-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathImageWriterPro.dpr
More file actions
135 lines (123 loc) · 4.84 KB
/
ImageWriterPro.dpr
File metadata and controls
135 lines (123 loc) · 4.84 KB
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
{******************************************************************************}
{ }
{ ImageWriter Pro - Main Program File }
{ }
{ Copyright (c) 2024-2025 Anton Zelenov <tixset@gmail.com> }
{ GitHub: https://github.com/tixset/ImageWriter }
{ Based on dd for Windows by John Newbigin (http://chrysocome.net/dd) }
{ }
{ This program is free software: you can redistribute it and/or modify }
{ it under the terms of the GNU General Public License as published by }
{ the Free Software Foundation, either version 3 of the License, or }
{ (at your option) any later version. }
{ }
{ Description: }
{ Main entry point for ImageWriter Pro application. }
{ Enhanced version with network share support and worker process mode. }
{ }
{******************************************************************************}
program ImageWriterPro;
{$APPTYPE GUI}
{$DEFINE IMAGEWRITER_PRO}
// Include application resources (icon, manifest, zlib1.dll, version info)
{$R resources\resources_pro.res}
uses
Windows,
SysUtils,
Forms,
Dialogs,
MainForm in 'src\mainform.pas' {MainForm},
ExtractZLib in 'src\ExtractZLib.pas',
ElevationHelper in 'src\ElevationHelper.pas',
IPCPipe in 'src\IPCPipe.pas',
WorkerMode in 'src\WorkerMode.pas',
WorkerCommands in 'src\WorkerCommands.pas',
BinFile in 'src\BinFile.pas',
DeviceManager in 'src\managers\DeviceManager.pas',
HashUtils in 'src\managers\HashUtils.pas',
FileOperations in 'src\managers\FileOperations.pas',
LogUtils in 'src\managers\LogUtils.pas',
ProgressManager in 'src\managers\ProgressManager.pas',
PartitionAnalyzer in 'src\managers\PartitionAnalyzer.pas',
UIHelper in 'src\managers\UIHelper.pas',
DeviceInfoHelper in 'src\managers\DeviceInfoHelper.pas',
ValidationHelper in 'src\managers\ValidationHelper.pas',
SettingsManager in 'src\managers\SettingsManager.pas',
OperationUIHelper in 'src\managers\OperationUIHelper.pas',
ArchiveHandler in 'src\managers\ArchiveHandler.pas',
ArchivePartitionReader in 'src\managers\ArchivePartitionReader.pas',
DeviceBenchmark in 'src\managers\DeviceBenchmark.pas',
BenchmarkForm in 'src\BenchmarkForm.pas' {BenchmarkForm};
type
TExceptionLogger = class
procedure LogException(Sender: TObject; E: Exception);
end;
var
GMutex: THandle;
ExceptionLogger: TExceptionLogger;
procedure TExceptionLogger.LogException(Sender: TObject; E: Exception);
var
LogMsg: string;
LogFile: TextFile;
LogFileName: string;
begin
// Suppress default error dialog - log exception to file instead
LogMsg := '[' + FormatDateTime('yyyy-mm-dd hh:nn:ss', Now) + '] EXCEPTION: ' +
E.ClassName + ': ' + E.Message;
try
LogFileName := ExtractFilePath(ParamStr(0)) + 'log\ImageWriterPro_errors.log';
if not DirectoryExists(ExtractFilePath(LogFileName)) then
CreateDir(ExtractFilePath(LogFileName));
AssignFile(LogFile, LogFileName);
if FileExists(LogFileName) then
Append(LogFile)
else
Rewrite(LogFile);
WriteLn(LogFile, LogMsg);
CloseFile(LogFile);
except
// Silent fail
end;
// Also log via form if available
if Assigned(AppMainForm) then
begin
try
with TMainForm(AppMainForm) do
MemoLog.Lines.Add('[ERROR] ' + E.ClassName + ': ' + E.Message);
except
// Ignore
end;
end;
end;
begin
// Check if running in worker mode
if (ParamCount > 0) and (ParamStr(1) = '--worker') then
begin
// Worker mode: execute disk operations with elevated privileges
ExitCode := ExecuteWorkerMode;
Exit;
end;
// Normal GUI mode - check for single instance
GMutex := CreateMutex(nil, True, 'Global\ImageWriterPro_GUI_Mutex');
if GetLastError = ERROR_ALREADY_EXISTS then
begin
MessageBox(0, 'ImageWriter Pro is already running.', 'ImageWriter Pro', MB_OK or MB_ICONINFORMATION);
if GMutex <> 0 then
CloseHandle(GMutex);
Exit;
end;
try
Application.Initialize;
// Install global exception handler to log errors instead of showing MessageBox
ExceptionLogger := TExceptionLogger.Create;
Application.OnException := ExceptionLogger.LogException;
Application.CreateForm(TMainForm, AppMainForm);
Application.Run;
finally
if GMutex <> 0 then
begin
ReleaseMutex(GMutex);
CloseHandle(GMutex);
end;
end;
end.