lang: ru: fix translation Enable Monsters -> Включить монстров
[d2df-editor.git] / src / editor / Editor.lpr
blob14ed16b27c174f9e85c527797f15703fe74b990f
1 program Editor;
3 {$INCLUDE ../shared/a_modes.inc}
5 uses
6   SysUtils, Interfaces,
7   Forms, Dialogs,
8   GL, GLExt,
9 {$IFDEF DARWIN}
10   MacOSAll, CocoaAll,
11 {$ENDIF}
13   Imaging, ImagingTypes, ImagingUtility,
14 {$IFNDEF NOSOUND}
15   fmod, fmodtypes, fmoderrors, fmodpresets,
16 {$ENDIF}
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,
23   f_main;
25 {$IFDEF WINDOWS}
26   {$R *.res}
27 {$ENDIF}
29 type
30   THandlerObject = class
31     procedure ExceptionHandler (Sender: TObject; e: Exception);
32   end;
34 var
35   LogFileName: AnsiString = '';
36   ParamFileIndex: Integer = 1;
38 procedure THandlerObject.ExceptionHandler (Sender: TObject; e: Exception);
39 begin
40   e_WriteStackTrace(e.message);
41   MessageDlg('Unhandled exception: ' + e.message + ' (see Editor.log for more information)',
42     mtError, [mbOK], 0);
43 end;
45 procedure InitLogs ();
46 begin
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;
54 {$ENDIF}
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);
65 end;
67 procedure CheckParamOptions ();
68 var
69   i: Integer;
70   p: AnsiString;
71 begin
72   i := 1;
73   while (i <= ParamCount) and (Length(ParamStr(i)) > 0) and (ParamStr(i)[1] = '-') do
74   begin
75     p := ParamStr(i);
76     if p = '--log-file' then
77     begin
78       if i + 1 <= ParamCount then
79       begin
80         Inc(i);
81         LogFileName := ParamStr(i);
82       end;
83     end
84     else if p = '--config' then
85     begin
86       if i + 1 <= ParamCount then
87       begin
88         Inc(i);
89         CfgFileName := ParamStr(i);
90       end;
91     end
92     else if p = '--game-wad' then
93     begin
94       if i + 1 <= ParamCount then
95       begin
96         Inc(i);
97         GameWad := ParamStr(i);
98       end;
99     end
100     else if p = '--editor-wad' then
101     begin
102       if i + 1 <= ParamCount then
103       begin
104         Inc(i);
105         EditorWad := ParamStr(i);
106       end;
107     end
108     else if p = '--wads-dir' then
109     begin
110       if i + 1 <= ParamCount then
111       begin
112         Inc(i);
113         WadsDir := ParamStr(i);
114       end;
115     end
116     else if p = '--lang-dir' then
117     begin
118       if i + 1 <= ParamCount then
119       begin
120         Inc(i);
121         LangDir := ParamStr(i);
122       end;
123     end;
124     Inc(i);
125   end;
126   ParamFileIndex := i;
127 end;
129 procedure CheckParamFiles ();
131   i: Integer;
132 begin
133   i := ParamFileIndex;
134   if i <= ParamCount then
135     StartMap := ParamStr(i);
136 end;
138 {$IFDEF DARWIN}
139 function NSStringToAnsiString (s: NSString): AnsiString;
141   i: Integer;
142 begin
143   result := '';
144   for i := 0 to s.length-1 do
145     result := result + AnsiChar(s.characterAtIndex(i));
146 end;
148 function GetBundlePath (): AnsiString;
150   pathRef: CFURLRef;
151   pathCFStr: CFStringRef;
152   pathStr: ShortString;
153 begin
154   pathRef := CFBundleCopyBundleURL(CFBundleGetMainBundle());
155   pathCFStr := CFURLCopyFileSystemPath(pathRef, kCFURLPOSIXPathStyle);
156   CFStringGetPascalString(pathCFStr, @pathStr, 255, CFStringGetSystemEncoding());
157   CFRelease(pathRef);
158   CFRelease(pathCFStr);
159   Result := pathStr;
160 end;
161 {$ENDIF}
163 procedure InitPathes ();
165 {$IFNDEF DARWIN}
166   EditorDir: AnsiString;
167 {$ELSE}
168   BundlePath, DFPath, DocPath: AnsiString; ns: NSString;
169   ApplicationSupportDirs, DocumentDirs: NSArray;
170   count: Integer;
171 {$ENDIF}
172 begin
173 {$IFNDEF DARWIN}
174   EditorDir := ExtractFilePath(Application.ExeName);
175   {$IFDEF WINDOWS}
176   GameExeFile := 'Doom2DF.exe';
177   {$ELSE}
178   GameExeFile := 'Doom2DF';
179   {$ENDIF}
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';
187 {$ELSE}
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';
210 {$ENDIF}
211   ForceDirectories(MapsDir);
212   ForceDirectories(WadsDir);
213 end;
215 begin
216 {$IFDEF DARWIN}
217   // Disable icons in menu on OSX by default
218   Application.ShowMenuGlyphs := sbgNever;
219 {$ENDIF}
221   Application.ExceptionDialog := aedOkMessageBox;
222   Application.AddOnExceptionHandler(THandlerObject.ExceptionHandler, True);
223   Application.Initialize();  // LCL requires this to come strictly before any call to .CreateForm()
225   InitPathes;
226   CheckParamOptions;
227   InitLogs;
229   Application.CreateForm(TMainForm, MainForm);
230   g_Language_Set(gLanguage);
232   CheckParamFiles;
233   Application.Run();
234 end.