3 {$INCLUDE ../shared/a_modes.inc}
13 Imaging, ImagingTypes, ImagingUtility,
15 fmod, fmodtypes, fmoderrors, fmodpresets,
18 WADEDITOR_dfwad in '../shared/WADEDITOR_dfwad.pas',
19 WADEDITOR_dfzip in '../shared/WADEDITOR_dfzip.pas',
20 e_log in '../engine/e_log.pas',
22 g_language, g_options,
30 THandlerObject = class
31 procedure ExceptionHandler (Sender: TObject; e: Exception);
35 LogFileName: AnsiString = '';
36 ParamFileIndex: Integer = 1;
38 procedure THandlerObject.ExceptionHandler (Sender: TObject; e: Exception);
40 e_WriteStackTrace(e.message);
41 MessageDlg('Unhandled exception: ' + e.message + ' (see Editor.log for more information)',
45 procedure InitLogs ();
47 e_InitLog(LogFileName, WM_NEWFILE);
49 {$IF DECLARED(UseHeapTrace)}
50 (* http://wiki.freepascal.org/heaptrc *)
51 GlobalSkipIfNoLeaks := True;
52 //SetHeapTraceOutput('EditorLeaks.log');
53 //HaltOnError := False;
56 e_WriteLog('Used file pathes:', MSG_NOTIFY);
57 e_WriteLog(' GameExeFile = ' + GameExeFile, MSG_NOTIFY);
58 e_WriteLog(' CfgFileName = ' + CfgFileName, MSG_NOTIFY);
59 e_WriteLog(' LogFileName = ' + LogFileName, MSG_NOTIFY);
60 e_WriteLog(' MapsDir = ' + MapsDir, MSG_NOTIFY);
61 e_WriteLog(' WadsDir = ' + WadsDir, MSG_NOTIFY);
62 e_WriteLog(' LangDir = ' + LangDir, MSG_NOTIFY);
63 e_WriteLog(' GameWad = ' + GameWad, MSG_NOTIFY);
64 e_WriteLog(' EditorWad = ' + EditorWad, MSG_NOTIFY);
67 procedure CheckParamOptions ();
73 while (i <= ParamCount) and (Length(ParamStr(i)) > 0) and (ParamStr(i)[1] = '-') do
76 if p = '--log-file' then
78 if i + 1 <= ParamCount then
81 LogFileName := ParamStr(i);
84 else if p = '--config' then
86 if i + 1 <= ParamCount then
89 CfgFileName := ParamStr(i);
92 else if p = '--game-wad' then
94 if i + 1 <= ParamCount then
97 GameWad := ParamStr(i);
100 else if p = '--editor-wad' then
102 if i + 1 <= ParamCount then
105 EditorWad := ParamStr(i);
108 else if p = '--wads-dir' then
110 if i + 1 <= ParamCount then
113 WadsDir := ParamStr(i);
116 else if p = '--lang-dir' then
118 if i + 1 <= ParamCount then
121 LangDir := ParamStr(i);
129 procedure CheckParamFiles ();
134 if i <= ParamCount then
135 StartMap := ParamStr(i);
139 function NSStringToAnsiString (s: NSString): AnsiString;
144 for i := 0 to s.length-1 do
145 result := result + AnsiChar(s.characterAtIndex(i));
148 function GetBundlePath (): AnsiString;
151 pathCFStr: CFStringRef;
152 pathStr: ShortString;
154 pathRef := CFBundleCopyBundleURL(CFBundleGetMainBundle());
155 pathCFStr := CFURLCopyFileSystemPath(pathRef, kCFURLPOSIXPathStyle);
156 CFStringGetPascalString(pathCFStr, @pathStr, 255, CFStringGetSystemEncoding());
158 CFRelease(pathCFStr);
163 procedure InitPathes ();
166 EditorDir: AnsiString;
168 BundlePath, DFPath, DocPath: AnsiString; ns: NSString;
169 ApplicationSupportDirs, DocumentDirs: NSArray;
174 EditorDir := ExtractFilePath(Application.ExeName);
176 GameExeFile := 'Doom2DF.exe';
178 GameExeFile := 'Doom2DF';
180 CfgFileName := EditorDir + DirectorySeparator + 'Editor.cfg';
181 LogFileName := EditorDir + DirectorySeparator + 'Editor.log';
182 MapsDir := EditorDir + DirectorySeparator + 'maps';
183 WadsDir := EditorDir + DirectorySeparator + 'wads';
184 LangDir := EditorDir + DirectorySeparator + 'data' + DirectorySeparator + 'lang';
185 GameWad := EditorDir + DirectorySeparator + 'data' + DirectorySeparator + 'game.wad';
186 EditorWad := EditorDir + DirectorySeparator + 'data' + DirectorySeparator + 'editor.wad';
188 BundlePath := GetBundlePath();
189 ApplicationSupportDirs := NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory,
190 NSUserDomainMask, true);
191 count := ApplicationSupportDirs.count;
192 ns := ApplicationSupportDirs.objectAtIndex(count - 1);
193 DFPath := NSStringToAnsiString(ns) + DirectorySeparator + 'Doom2D Forever';
194 DocumentDirs := NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true);
195 count := DocumentDirs.count;
196 ns := DocumentDirs.objectAtIndex(count - 1);
197 DocPath := NSStringToAnsiString(ns) + DirectorySeparator + 'Doom2D Forever';
198 GameExeFile := 'Doom2D Forever.app';
199 CfgFileName := DFPath + DirectorySeparator + 'Editor.cfg';
200 LogFileName := DFPath + DirectorySeparator + 'Editor.log';
201 MapsDir := DocPath + DirectorySeparator + 'Maps';
202 WadsDir := BundlePath + DirectorySeparator + 'Contents' + DirectorySeparator + 'Resources' +
203 DirectorySeparator + 'wads';
204 LangDIr := BundlePath + DirectorySeparator + 'Contents' + DirectorySeparator + 'Resources' +
205 DirectorySeparator + 'data' + DirectorySeparator + 'lang';
206 GameWad := BundlePath + DirectorySeparator + 'Contents' + DirectorySeparator + 'Resources' +
207 DirectorySeparator + 'data' + DirectorySeparator + 'game.wad';
208 EditorWad := BundlePath + DirectorySeparator + 'Contents' + DirectorySeparator + 'Resources' +
209 DirectorySeparator + 'data' + DirectorySeparator + 'editor.wad';
211 ForceDirectories(MapsDir);
212 ForceDirectories(WadsDir);
217 // Disable icons in menu on OSX by default
218 Application.ShowMenuGlyphs := sbgNever;
221 Application.ExceptionDialog := aedOkMessageBox;
222 Application.AddOnExceptionHandler(THandlerObject.ExceptionHandler, True);
223 Application.Initialize(); // LCL requires this to come strictly before any call to .CreateForm()
229 Application.CreateForm(TMainForm, MainForm);
230 g_Language_Set(gLanguage);