|
@@ -5,7 +5,7 @@ program DMDirc;
|
5
|
5
|
{$R icon.rc}
|
6
|
6
|
{$R version.rc}
|
7
|
7
|
|
8
|
|
-uses Windows, SysUtils, classes;
|
|
8
|
+uses Windows, SysUtils, classes, StrUtils;
|
9
|
9
|
|
10
|
10
|
// Run an application and wait for it to finish.
|
11
|
11
|
function ExecAndWait(sProgramToRun: String): Longword;
|
|
@@ -41,10 +41,18 @@ begin
|
41
|
41
|
dwFlags := STARTF_USESHOWWINDOW;
|
42
|
42
|
wShowWindow := SW_SHOWNORMAL;
|
43
|
43
|
end;
|
44
|
|
-
|
|
44
|
+
|
45
|
45
|
CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
|
46
|
46
|
end;
|
47
|
47
|
|
|
48
|
+procedure RunProgram(sProgramToRun: String; wait: boolean);
|
|
49
|
+begin
|
|
50
|
+ if wait then ExecAndWait(sProgramToRun)
|
|
51
|
+ else Launch(sProgramToRun);
|
|
52
|
+end;
|
|
53
|
+
|
|
54
|
+const
|
|
55
|
+ launcherVersion: String = '1';
|
48
|
56
|
var
|
49
|
57
|
errorMessage: String;
|
50
|
58
|
javaCommand: String = 'javaw.exe';
|
|
@@ -53,13 +61,15 @@ var
|
53
|
61
|
i: integer;
|
54
|
62
|
hK32: THandle;
|
55
|
63
|
jarName: String;
|
|
64
|
+ launcherUpdate: boolean = false;
|
56
|
65
|
begin
|
57
|
66
|
jarName := ExtractFileDir(paramstr(0))+'\DMDirc.jar';
|
58
|
67
|
|
59
|
68
|
directory := GetEnvironmentVariable('APPDATA')+'\DMDirc';
|
60
|
69
|
if ParamCount > 0 then begin
|
61
|
70
|
for i := 1 to ParamCount do begin
|
62
|
|
- cliParams := cliParams+' '+paramstr(i);
|
|
71
|
+ if AnsiContainsStr(cliParams, ' ') then cliParams := cliParams+' "'+paramstr(i)+'"'
|
|
72
|
+ else cliParams := cliParams+' '+paramstr(i);
|
63
|
73
|
if (paramstr(i) = '-d') or (paramstr(i) = '--directory') then begin
|
64
|
74
|
if ParamCount > i then begin
|
65
|
75
|
directory := paramstr(i+1);
|
|
@@ -69,7 +79,8 @@ begin
|
69
|
79
|
end;
|
70
|
80
|
|
71
|
81
|
// Update if needed.
|
72
|
|
- if FileExists(directory+'\.DMDirc.jar') then begin
|
|
82
|
+ launcherUpdate := FileExists(directory+'\.DMDirc.exe') and FileExists(directory+'\.DMDircUpdater.exe');
|
|
83
|
+ if FileExists(directory+'\.DMDirc.jar') or launcherUpdate then begin
|
73
|
84
|
// Vista Sucks.
|
74
|
85
|
hK32 := GetModuleHandle('kernel32');
|
75
|
86
|
if GetProcAddress(hK32, 'GetLocaleInfoEx') <> nil then begin
|
|
@@ -86,32 +97,18 @@ begin
|
86
|
97
|
errorMessage := errorMessage+#13#10+'Please click ''Allow'' on the UAC prompt to complete the update, or click no';
|
87
|
98
|
errorMessage := errorMessage+#13#10+'here to continue without updating.';
|
88
|
99
|
if MessageBox(0, PChar(errorMessage), 'Windows Vista', MB_YESNO) = IDYES then begin
|
89
|
|
- ExecAndWait('DMDircUpdater.exe '+directory+'\.DMDirc.jar');
|
|
100
|
+ RunProgram('"'+ExtractFileDir(paramstr(0))+'\DMDircUpdater.exe" --UpdateSourceDir "'+directory+'"', not launcherUpdate);
|
90
|
101
|
end;
|
91
|
102
|
end
|
92
|
|
- else ExecAndWait('DMDircUpdater.exe '+directory+'\.DMDirc.jar');
|
|
103
|
+ else RunProgram('"'+ExtractFileDir(paramstr(0))+'\DMDircUpdater.exe" --UpdateSourceDir "'+directory+'"', not launcherUpdate);
|
93
|
104
|
end
|
94
|
|
- else ExecAndWait('DMDircUpdater.exe '+directory+'\.DMDirc.jar');
|
|
105
|
+ else RunProgram('"'+ExtractFileDir(paramstr(0))+'\DMDircUpdater.exe" --UpdateSourceDir "'+directory+'"', not launcherUpdate);
|
95
|
106
|
end;
|
96
|
107
|
|
97
|
|
- // Check JVM
|
98
|
|
- if (ExecAndWait(javaCommand+' -version') <> 0) then begin
|
99
|
|
- errorMessage := 'No JVM is currently installed.';
|
100
|
|
- errorMessage := errorMessage+#13#10;
|
101
|
|
- errorMessage := errorMessage+#13#10+'DMDirc requires a 1.6.0 compatible JVM, you can get one from:';
|
102
|
|
- errorMessage := errorMessage+#13#10+'http://jdl.sun.com/webapps/getjava/BrowserRedirect';
|
103
|
|
- errorMessage := errorMessage+#13#10;
|
104
|
|
- errorMessage := errorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance,';
|
105
|
|
- errorMessage := errorMessage+#13#10+'please feel free to contact us.';
|
106
|
|
-
|
107
|
|
- MessageBox(0, PChar(errorMessage), 'Sorry, DMDirc is unable to continue', MB_OK + MB_ICONSTOP);
|
108
|
|
- end
|
109
|
|
- // Else try and run client. (This only asks for help output to check that client
|
110
|
|
- // runs on this OS, otherwise later segfaults or so would cause the error to
|
111
|
|
- // appear
|
112
|
|
- else if FileExists(jarName) then begin
|
113
|
|
- if (ExecAndWait(javaCommand+' -jar "'+jarName+'" --help') <> 0) then begin
|
114
|
|
- errorMessage := 'The currently installed version of java is not compatible with DMDirc.';
|
|
108
|
+ if not launcherUpdate then begin
|
|
109
|
+ // Check JVM
|
|
110
|
+ if (ExecAndWait(javaCommand+' -version') <> 0) then begin
|
|
111
|
+ errorMessage := 'No JVM is currently installed.';
|
115
|
112
|
errorMessage := errorMessage+#13#10;
|
116
|
113
|
errorMessage := errorMessage+#13#10+'DMDirc requires a 1.6.0 compatible JVM, you can get one from:';
|
117
|
114
|
errorMessage := errorMessage+#13#10+'http://jdl.sun.com/webapps/getjava/BrowserRedirect';
|
|
@@ -121,12 +118,28 @@ begin
|
121
|
118
|
|
122
|
119
|
MessageBox(0, PChar(errorMessage), 'Sorry, DMDirc is unable to continue', MB_OK + MB_ICONSTOP);
|
123
|
120
|
end
|
|
121
|
+ // Else try and run client. (This only asks for help output to check that client
|
|
122
|
+ // runs on this OS, otherwise later segfaults or so would cause the error to
|
|
123
|
+ // appear
|
|
124
|
+ else if FileExists(jarName) then begin
|
|
125
|
+ if (ExecAndWait(javaCommand+' -jar "'+jarName+'" --help') <> 0) then begin
|
|
126
|
+ errorMessage := 'The currently installed version of java is not compatible with DMDirc.';
|
|
127
|
+ errorMessage := errorMessage+#13#10;
|
|
128
|
+ errorMessage := errorMessage+#13#10+'DMDirc requires a 1.6.0 compatible JVM, you can get one from:';
|
|
129
|
+ errorMessage := errorMessage+#13#10+'http://jdl.sun.com/webapps/getjava/BrowserRedirect';
|
|
130
|
+ errorMessage := errorMessage+#13#10;
|
|
131
|
+ errorMessage := errorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance,';
|
|
132
|
+ errorMessage := errorMessage+#13#10+'please feel free to contact us.';
|
|
133
|
+
|
|
134
|
+ MessageBox(0, PChar(errorMessage), 'Sorry, DMDirc is unable to continue', MB_OK + MB_ICONSTOP);
|
|
135
|
+ end
|
|
136
|
+ else begin
|
|
137
|
+ Launch(javaCommand+' -ea -jar "'+jarName+'"'+' -l windows-'+launcherVersion+' '+cliParams)
|
|
138
|
+ end;
|
|
139
|
+ end
|
124
|
140
|
else begin
|
125
|
|
- Launch(javaCommand+' -ea -jar "'+jarName+'"'+cliParams)
|
|
141
|
+ errorMessage := 'Your DMDirc installation has been broken. DMDirc.jar no longer exists.';
|
|
142
|
+ MessageBox(0, PChar(errorMessage), 'Sorry, DMDirc is unable to continue', MB_OK + MB_ICONSTOP);
|
126
|
143
|
end;
|
127
|
|
- end
|
128
|
|
- else begin
|
129
|
|
- errorMessage := 'Your DMDirc installation has been broken. DMDirc.jar no longer exists.';
|
130
|
|
- MessageBox(0, PChar(errorMessage), 'Sorry, DMDirc is unable to continue', MB_OK + MB_ICONSTOP);
|
131
|
144
|
end;
|
132
|
145
|
end.
|