Rev 1 | Rev 3 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 2 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | unit ExtractorMain; |
1 | unit ExtractorMain; |
2 | 2 | ||
3 | {$DEFINE DEBUG_MODE} |
- | |
4 | - | ||
5 | {$DEFINE USE_DZIP_UNPACK} |
3 | {$DEFINE USE_DZIP_UNPACK} |
6 | 4 | ||
7 | // TODO: Implement ExtractionTarget switch |
5 | // todo: compilerswitch, der auch selectdirectory() anzeigt (ohne foldercreate) |
8 | 6 | ||
9 | interface |
7 | interface |
10 | 8 | ||
11 | uses |
9 | uses |
12 | Windows, SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls, ShellAPI, |
10 | Windows, SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls, ShellAPI, |
13 | ExtCtrls, ComCtrls, ZipMstr19, ZMMsgStr19, ZMMsg19, ZMDelZip19, |
11 | ExtCtrls, ComCtrls, ZipMstr19, ZMMsgStr19, ZMMsg19, ZMDelZip19, |
14 | ZMCompat19, SFXBehavior; |
12 | ZMCompat19, SFXBehavior, ShlObj; |
15 | 13 | ||
16 | type |
14 | type |
17 | TOverwriteDecision = (odUndefined, odOverwriteAll, odOverwriteNothing); |
15 | TOverwriteDecision = (odUndefined, odOverwriteAll, odOverwriteNothing); |
18 | 16 | ||
19 | TMainForm = class(TForm) |
17 | TMainForm = class(TForm) |
Line 148... | Line 146... | ||
148 | uz: TZipMaster19; |
146 | uz: TZipMaster19; |
149 | l: TStringList; |
147 | l: TStringList; |
150 | s: string; |
148 | s: string; |
151 | ec: Integer; |
149 | ec: Integer; |
152 | ar: TExecuteSFXAutoRunResult; |
150 | ar: TExecuteSFXAutoRunResult; |
- | 151 | GeneralBaseDir: string; |
|
153 | resourcestring |
152 | resourcestring |
154 | Lng_Aborted = 'Der laufende Prozess wurde abgebrochen. Das extrahierten Dateien sind somit unvollständig.'; |
153 | Lng_Aborted = 'Der laufende Prozess wurde abgebrochen. Das extrahierten Dateien sind somit unvollständig.'; |
155 | Lng_Zip_Error = 'ZIP-Master Fehler "%s" (%d)'; |
154 | Lng_Zip_Error = 'ZIP-Master Fehler "%s" (%d)'; |
156 | Lng_AutoRunFailed = 'SFX-AutoRun fehlgeschlagen. Die entpackten Inhalte werden nun angezeigt.'; |
155 | Lng_AutoRunFailed = 'SFX-AutoRun fehlgeschlagen. Die entpackten Inhalte werden nun angezeigt.'; |
157 | Lng_Unknown_Error = 'Unbekannter Fehler: Dateien sind nicht aufzufinden!'; |
156 | Lng_Unknown_Error = 'Unbekannter Fehler: Dateien sind nicht aufzufinden!'; |
- | 157 | Lng_SelectDir = 'Bitte wählen Sie ein Verzeichnis zum Extrahieren aus. Es wird maximal 1 Datei bzw. Ordner erstellt!'; |
|
158 | begin |
158 | begin |
159 | AZipfile := ExpandUNCFileName(AZipfile); |
159 | AZipfile := ExpandUNCFileName(AZipfile); |
160 | RenamingOldPrefix := ''; |
160 | RenamingOldPrefix := ''; |
161 | RenamingNewPrefix := ''; |
161 | RenamingNewPrefix := ''; |
162 | 162 | ||
Line 182... | Line 182... | ||
182 | uz.OnProgress := ArcProzess; |
182 | uz.OnProgress := ArcProzess; |
183 | uz.OnTick := ArcTick; |
183 | uz.OnTick := ArcTick; |
184 | uz.OnCheckTerminate := ArcCheckTerminate; |
184 | uz.OnCheckTerminate := ArcCheckTerminate; |
185 | uz.OnPasswordError := ArcPassword; |
185 | uz.OnPasswordError := ArcPassword; |
186 | uz.PasswordReqCount := MaxTries; |
186 | uz.PasswordReqCount := MaxTries; |
187 | // TODO: Mehr events? |
- | |
188 | uz.OnSkipped := SkipEvent; |
187 | uz.OnSkipped := SkipEvent; |
189 | uz.OnSetExtName := ArcExtFNChange; |
188 | uz.OnSetExtName := ArcExtFNChange; |
- | 189 | // TODO: Mehr events? |
|
- | 190 | ||
- | 191 | // Find out base dirtory |
|
- | 192 | ||
- | 193 | GeneralBaseDir := ''; |
|
- | 194 | case zb.ExtractionTarget of |
|
- | 195 | etExtractHere: |
|
- | 196 | begin |
|
- | 197 | GeneralBaseDir := ExtractFilePath(AZipfile); // Default |
|
- | 198 | end; |
|
- | 199 | etDesktop: |
|
- | 200 | begin |
|
- | 201 | GeneralBaseDir := GetSpecialFolderPath(CSIDL_DESKTOP); |
|
- | 202 | end; |
|
- | 203 | etAsk: |
|
- | 204 | begin |
|
- | 205 | if not AdvSelectDirectory(Lng_SelectDir, '', GeneralBaseDir, False, False, True) then |
|
- | 206 | begin |
|
- | 207 | Exit; |
|
- | 208 | end; |
|
- | 209 | end; |
|
- | 210 | end; |
|
- | 211 | GeneralBaseDir := IncludeTrailingPathDelimiter(GeneralBaseDir); |
|
- | 212 | ||
- | 213 | // Semantic scanning of ZIP to determinate the final extraction directory |
|
190 | 214 | ||
191 | l := TStringList.Create; |
215 | l := TStringList.Create; |
192 | try |
216 | try |
193 | // Count the root objects (files OR dirs) in the ZIP |
217 | // Count the root objects (files OR dirs) in the ZIP |
194 | 218 | ||
Line 200... | Line 224... | ||
200 | Exit; |
224 | Exit; |
201 | end |
225 | end |
202 | else if l.Count = 1 then |
226 | else if l.Count = 1 then |
203 | begin |
227 | begin |
204 | // 1 Object = Extract it right here! |
228 | // 1 Object = Extract it right here! |
205 | s := ExtractFilePath(AZipfile) + l.Strings[0]; |
229 | BaseDir := GeneralBaseDir; |
206 | BaseDir := ExtractFilePath(AZipfile); |
230 | s := BaseDir + l.Strings[0]; |
- | 231 | ||
207 | RenamingOldPrefix := StripBaseDir(S); |
232 | RenamingOldPrefix := l.Strings[0]; // = StripBaseDir(S); |
- | 233 | ||
208 | if zb.ConflictBehavior = cbAvoid then |
234 | if zb.ConflictBehavior = cbAvoid then |
209 | begin |
235 | begin |
210 | s := SearchNextFreeName(s); |
236 | s := SearchNextFreeName(s, LooksLikeDir(s)); |
211 | end; |
237 | end; |
212 | // TODO: helloworld.exe schlägt fehl! |
- | |
- | 238 | ||
213 | RenamingNewPrefix := StripBaseDir(S); // We need to change the name! |
239 | RenamingNewPrefix := StripBaseDir(s); |
214 | end |
240 | end |
215 | else |
241 | else |
216 | begin |
242 | begin |
217 | // 2+ Objects = Extract them in a separate folder |
243 | // 2+ Objects = Extract them in a separate folder |
218 | s := ChangeFileExt(AZipfile, ''); |
244 | s := GeneralBaseDir + ExtractFileNameWithoutExt(AZipfile) + PathDelim; |
219 | if zb.ConflictBehavior = cbAvoid then |
245 | if zb.ConflictBehavior = cbAvoid then |
220 | begin |
246 | begin |
221 | s := SearchNextFreeName(s); |
247 | s := SearchNextFreeName(s, true); |
222 | MkDir(s); |
248 | MkDir(s); |
223 | end |
249 | end |
224 | else |
250 | else |
225 | begin |
251 | begin |
226 | if not DirectoryExists(s) then MkDir(s); |
252 | if not DirectoryExists(s) then MkDir(s); |
227 | end; |
253 | end; |
228 | BaseDir := s; |
254 | BaseDir := s; |
229 | end; |
255 | end; |
230 | BaseDir := IncludeTrailingPathDelimiter(BaseDir); |
256 | BaseDir := IncludeTrailingPathDelimiter(BaseDir); |
231 | 257 | ||
232 | uz.ExtrBaseDir := BaseDir; // TODO: andere ordner erlauben |
258 | uz.ExtrBaseDir := BaseDir; |
233 | 259 | ||
234 | // Pre-Extract-Dialog |
260 | // Pre-Extract-Dialog |
235 | 261 | ||
236 | if zb.CommentPresentation = cpBeforeExtracting then |
262 | if zb.CommentPresentation = cpBeforeExtracting then |
237 | begin |
263 | begin |
Line 327... | Line 353... | ||
327 | 353 | ||
328 | procedure TMainForm.ArcExtFNChange(Sender: TObject; |
354 | procedure TMainForm.ArcExtFNChange(Sender: TObject; |
329 | var FileName: TZMString; const BaseDir: TZMString; |
355 | var FileName: TZMString; const BaseDir: TZMString; |
330 | var IsChanged: Boolean); |
356 | var IsChanged: Boolean); |
331 | begin |
357 | begin |
332 | if RenamingOldPrefix = RenamingOldPrefix then Exit; |
358 | if RenamingOldPrefix = RenamingNewPrefix then Exit; |
333 | - | ||
334 | FileName := RenamingNewPrefix + Copy(FileName, 1+Length(RenamingOldPrefix), Length(FileName)-Length(RenamingOldPrefix)); |
359 | FileName := RenamingNewPrefix + Copy(FileName, 1+Length(RenamingOldPrefix), Length(FileName)-Length(RenamingOldPrefix)); |
335 | IsChanged := true; |
360 | IsChanged := true; |
336 | end; |
361 | end; |
337 | 362 | ||
338 | procedure TMainForm.ArcTick(Sender: TObject); |
363 | procedure TMainForm.ArcTick(Sender: TObject); |
Line 449... | Line 474... | ||
449 | 474 | ||
450 | procedure TMainForm.FormCreate(Sender: TObject); |
475 | procedure TMainForm.FormCreate(Sender: TObject); |
451 | resourcestring |
476 | resourcestring |
452 | Lng_Extracting = 'Extrahiere Dateien. Bitte warten...'; |
477 | Lng_Extracting = 'Extrahiere Dateien. Bitte warten...'; |
453 | begin |
478 | begin |
454 | {$IFDEF DEBUG_MODE} |
- | |
455 | Caption := Caption + ' (Debug)'; |
- | |
456 | {$ENDIF} |
- | |
457 | WaitLabel.Caption := Lng_Extracting; |
479 | WaitLabel.Caption := Lng_Extracting; |
458 | WaitLabel.Left := progressBar.Width div 2 - WaitLabel.Width div 2; |
480 | WaitLabel.Left := progressBar.Width div 2 - WaitLabel.Width div 2; |
459 | CurrentFileLabel.Caption := ''; |
481 | CurrentFileLabel.Caption := ''; |
460 | end; |
482 | end; |
461 | 483 | ||
Line 498... | Line 520... | ||
498 | end; |
520 | end; |
499 | end; |
521 | end; |
500 | {$ENDIF} |
522 | {$ENDIF} |
501 | 523 | ||
502 | procedure TMainForm.AutoTimerTimer(Sender: TObject); |
524 | procedure TMainForm.AutoTimerTimer(Sender: TObject); |
- | 525 | resourcestring |
|
- | 526 | Lng_NakedSFX = 'Das selbstentpackende Archiv (SFX) beschädigt oder ungültig. Wenn Sie diese Datei aus dem Internet bezogen haben, laden Sie sie bitte erneut herunter.'; |
|
- | 527 | Lng_FileNotFound = 'Die durch Parameter angegebene Datei "%s" kann nicht gefunden werden!'; |
|
- | 528 | Lng_TooManyArguments = 'Zu viele Argumente!'; |
|
503 | begin |
529 | begin |
504 | AutoTimer.Enabled := false; |
530 | AutoTimer.Enabled := false; |
505 | 531 | ||
506 | {$IFNDEF USE_DZIP_UNPACK} |
532 | {$IFNDEF USE_DZIP_UNPACK} |
507 | ExtractDllFromResource(GetTempDirectory); |
533 | ExtractDllFromResource(GetTempDirectory); |
508 | {$ENDIF} |
534 | {$ENDIF} |
509 | 535 | ||
510 | try |
536 | try |
- | 537 | if IsExtractable(ParamStr(0)) then |
|
- | 538 | begin |
|
- | 539 | ExtractZipHere(ParamStr(0)); |
|
- | 540 | end |
|
- | 541 | else |
|
- | 542 | begin |
|
- | 543 | // Der Extractor ist "nackt" oder das SFX beschädigt |
|
- | 544 | ||
511 | {$IFDEF DEBUG_MODE} |
545 | if ParamCount = 0 then |
- | 546 | begin |
|
- | 547 | MessageDlg(Lng_NakedSFX, mtError, [mbOk], 0); |
|
- | 548 | end |
|
- | 549 | else if ParamCount = 1 then |
|
- | 550 | begin |
|
- | 551 | // In diesem Zustand erlauben wir, fremde SFX zu entpacken (auch für Debugging-Zwecke) |
|
512 | if FileExists(ParamStr(1)) then |
552 | if FileExists(ParamStr(1)) then |
513 | begin |
553 | begin |
514 | ExtractZipHere(ParamStr(1)); |
554 | ExtractZipHere(ParamStr(1)); |
515 | end |
555 | end |
516 | else |
556 | else |
517 | begin |
557 | begin |
- | 558 | MessageDlg(Lng_FileNotFound, mtError, [mbOk], 0); |
|
518 | {$ENDIF} |
559 | end; |
519 | 560 | end |
|
520 | ExtractZipHere(ParamStr(0)); |
561 | else if ParamCount = 2 then |
521 | 562 | begin |
|
- | 563 | // Future: Mehr als nur 1 Parameter erlauben? |
|
- | 564 | MessageDlg(Lng_TooManyArguments, mtError, [mbOk], 0); |
|
522 | {$IFDEF DEBUG_MODE} |
565 | end; |
523 | end; |
566 | end; |
524 | {$ENDIF} |
- | |
525 | finally |
567 | finally |
526 | AbortUnzip := true; // Damit es zu keiner Abfrage kommt |
568 | AbortUnzip := true; // Damit es zu keiner Abfrage in OnCloseQuery kommt |
527 | Close; |
569 | Close; |
528 | end; |
570 | end; |
529 | end; |
571 | end; |
530 | 572 | ||
531 | function TMainForm.StripBaseDir(const s: string): string; |
573 | function TMainForm.StripBaseDir(const s: string): string; |