File: CommonFuncs.pas

package info (click to toggle)
mysql-query-browser 1.2.5beta-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 63,792 kB
  • ctags: 46,485
  • sloc: pascal: 249,299; ansic: 80,111; cpp: 72,467; sh: 25,271; objc: 20,015; yacc: 10,755; java: 9,917; xml: 4,580; php: 2,806; python: 1,566; sql: 1,563; makefile: 1,452; perl: 3
file content (164 lines) | stat: -rw-r--r-- 5,397 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
unit CommonFuncs;

interface

uses
  gnugettext, SysUtils, Options, AuxFuncs, Windows, Forms, About,
  TntSystem;

{$include Consts.ini}

procedure CheckCommonCommandlineParameter;
procedure ShowAboutDialog(Caption: WideString;
  Version: WideString; Credits: WideString);
function ShowSplashScreen(Caption: WideString): TAboutForm;

implementation

uses
  Classes, Unicode;

// -----------------------------------------------------------------------------

procedure CheckCommonCommandlineParameter;

var
  i: integer;
  S: WideString;
  HexString: string;
  Utf8String: string;
  
begin
  for i := 1 to WideParamCount do
  begin
    //-------------------------------------------------------------
    //General cmdline parameters

    S := WideParamStr(I);

    //Connection
    if (S = '-c') and (I+1 <= WideParamCount) then
      MYXCommonOptions.ConnectionToUse := WideParamStr(I + 1)
    else
      if (Copy(S, 1, 2) = '-c') then
        MYXCommonOptions.ConnectionToUse := Copy(S, 3, MaxInt)
      else
        //Username
        if ((S = '-u')) and (I+1 <= WideParamCount) then
          MYXCommonOptions.ConnectionUsername := WideParamStr(I + 1)
        else
          if (Copy(S, 1, 2) = '-u') then
            MYXCommonOptions.ConnectionUsername := Copy(S, 3, MaxInt)
          else
            //Password
            if (S = '-p') and (I+1 <= WideParamCount) then
              MYXCommonOptions.ConnectionPassword := WideParamStr(I + 1)
            else
              if (Copy(S, 1, 2) = '-p') then
                MYXCommonOptions.ConnectionPassword := Copy(S, 3, MaxInt)
              else
                //Host
                if (S = '-h') and (I+1 <= WideParamCount) then
                  MYXCommonOptions.ConnectionHost := WideParamStr(I + 1)
                else
                  if (Copy(S, 1, 2) = '-h') then
                    MYXCommonOptions.ConnectionHost := Copy(S, 3, MaxInt)
                  else
                    //Port
                    if (S = '-P') and (I+1 <= WideParamCount) then
                    begin
                      S := WideParamStr(I + 1);
                      MYXCommonOptions.ConnectionPort := StrToIntDef(S, 3306);
                    end
                    else
                      if (Copy(S, 1, 2) = '-P') then
                      begin
                        S := Copy(S, 3, MaxInt);
                        MYXCommonOptions.ConnectionPort := StrToIntDef(S, 3306);
                      end
                      else
                        //Schema
                        if (S = '-D') and (I+1 <= WideParamCount) then
                          MYXCommonOptions.ConnectionSchema := WideParamStr(I + 1)
                        else
                          if (Copy(S, 1, 2) = '-D') then
                            MYXCommonOptions.ConnectionSchema := Copy(S, 3, MaxInt)
                          else
                            // Password hexadecimal
                            if StrLCompW(PWideChar(S), '-x', 2) = 0 then
                            begin
                              if (Length(S) = 2) and (I < WideParamCount) then
                                HexString := WideParamStr(I + 1)
                              else
                                HexString := Copy(S, 3, MaxInt);
                              SetLength(Utf8String, Length(HexString) div 2);
                              HexToBin(PChar(HexString), PChar(Utf8String), Length(Utf8String));
                              MYXCommonOptions.ConnectionPassword := Utf8Decode(Utf8String);
                            end;
  end;

  //If only username was specified, automaticly set
  //other connection values
  if (MYXCommonOptions.ConnectionUsername <> '') then
  begin
    if (MYXCommonOptions.ConnectionHost = '') then
      MYXCommonOptions.ConnectionHost := 'localhost';

    if MYXCommonOptions.ConnectionPort = 0 then
      MYXCommonOptions.ConnectionPort := 3306;
  end;
end;

// -----------------------------------------------------------------------------

procedure ShowAboutDialog(Caption: WideString;
  Version: WideString; Credits: WideString);

var
  AboutForm: TAboutForm;

begin
  AboutForm := TAboutForm.Create(nil);
  try
    AboutForm.Caption := _('About ') + Caption;
    AboutForm.VersionLbl.Caption := _('version') + ' ' + Version;
    AboutForm.TextLbl.Caption := Credits;
    AboutForm.ShowModal;
  finally
    AboutForm.Free;
  end;
end;

// -----------------------------------------------------------------------------

function ShowSplashScreen(Caption: WideString): TAboutForm;

var
  AboutForm: TAboutForm;

begin
  Result := nil;

  AboutForm := TAboutForm.Create(nil);
  try
    AboutForm.Caption := _('About ') + Caption;
    AboutForm.VersionLbl.Caption := _('version') + ' ' +
      product_version+' '+product_build_level;
    AboutForm.TextLbl.Caption := '';
    AboutForm.BorderStyle := bsNone;
    AboutForm.Width := AboutForm.AboutImg.Width;
    AboutForm.Height := AboutForm.AboutImg.Height;
    AboutForm.FormStyle := fsStayOnTop;
    AboutForm.Show;
    AboutForm.Refresh;

    Result := AboutForm;
  except
    AboutForm.Free;
  end;
end;

// -----------------------------------------------------------------------------

end.