DEADSOFTWARE

fix file opening from command line
[d2df-editor.git] / src / editor / Editor.lpr
1 program Editor;
3 {$INCLUDE ../shared/a_modes.inc}
5 uses
6 Forms, Interfaces, Dialogs,
7 GL, GLExt, SysUtils,
8 e_graphics in '../engine/e_graphics.pas',
9 e_log in '../engine/e_log.pas',
10 e_textures in '../engine/e_textures.pas',
11 MAPSTRUCT in '../shared/MAPSTRUCT.pas',
12 MAPREADER in '../shared/MAPREADER.pas',
13 MAPWRITER in '../shared/MAPWRITER.pas',
14 MAPDEF in '../shared/MAPDEF.pas',
15 WADEDITOR in '../shared/WADEDITOR.pas',
16 WADSTRUCT in '../shared/WADSTRUCT.pas',
17 CONFIG in '../shared/CONFIG.pas',
18 xstreams in '../shared/xstreams.pas',
19 dfzip in '../shared/dfzip.pas',
20 sfs in '../sfs/sfs.pas',
21 sfsPlainFS in '../sfs/sfsPlainFS.pas',
22 sfsZipFS in '../sfs/sfsZipFS.pas',
24 f_about in 'f_about.pas' {AboutForm},
25 f_options in 'f_options.pas' {OptionsForm},
26 f_main in 'f_main.pas' {MainForm},
27 g_map in 'g_map.pas',
28 f_mapoptions in 'f_mapoptions.pas' {MapOptionsForm},
29 f_activationtype in 'f_activationtype.pas' {ActivationTypeForm},
30 f_addresource in 'f_addresource.pas' {AddResourceForm},
31 f_keys in 'f_keys.pas' {KeysForm},
32 f_mapcheck in 'f_mapcheck.pas' {MapCheckForm},
33 f_mapoptimization in 'f_mapoptimization.pas' {MapOptimizationForm},
34 g_basic in 'g_basic.pas',
35 g_textures in 'g_textures.pas',
36 f_addresource_texture in 'f_addresource_texture.pas' {AddTextureForm},
37 f_savemap in 'f_savemap.pas' {SaveMapForm},
38 f_selectmap in 'f_selectmap.pas' {SelectMapForm},
39 f_addresource_sky in 'f_addresource_sky.pas' {AddSkyForm},
40 f_addresource_sound in 'f_addresource_sound.pas' {AddSoundForm},
41 spectrum in 'spectrum.pas',
42 f_saveminimap in 'f_saveminimap.pas' {SaveMiniMapForm},
43 f_packmap in 'f_packmap.pas' {PackMapForm},
44 f_maptest in 'f_maptest.pas' {MapTestForm},
45 f_choosetype in 'f_choosetype.pas' {ChooseTypeForm},
46 {$IFNDEF NOSOUND}
47 fmod,
48 fmoderrors,
49 fmodpresets,
50 fmodtypes,
51 {$ENDIF}
52 ImagingTypes,
53 Imaging,
54 ImagingUtility,
55 g_options in 'g_options.pas',
56 g_language in 'g_language.pas',
57 f_selectlang in 'f_selectlang.pas' {SelectLanguageForm};
59 {$IFDEF WINDOWS}
60 {$R *.res}
61 {$ENDIF}
63 type
64 THandlerObject = class (TObject)
65 procedure ExceptionHandler (Sender: TObject; e: Exception);
66 end;
68 var
69 LogFileName: AnsiString = '';
70 ParamFileIndex: Integer = 1;
72 procedure THandlerObject.ExceptionHandler (Sender: TObject; e: Exception);
73 begin
74 e_WriteStackTrace(e.message);
75 MessageDlg('Unhandled exception: ' + e.message + ' (see Editor.log for more information)', mtError, [mbOK], 0);
76 end;
78 procedure CheckParamOptions;
79 var i: Integer; p: AnsiString;
80 begin
81 i := 1;
82 while (i <= ParamCount) and (Length(ParamStr(i)) > 0) and (ParamStr(i)[1] = '-') do
83 begin
84 p := ParamStr(i);
85 if p = '--log-file' then
86 begin
87 if i + 1 <= ParamCount then
88 begin
89 Inc(i);
90 LogFileName := ParamStr(i);
91 end;
92 end
93 else if p = '--config' then
94 begin
95 if i + 1 <= ParamCount then
96 begin
97 Inc(i);
98 CfgFileName := ParamStr(i);
99 end;
100 end
101 else if p = '--game-wad' then
102 begin
103 if i + 1 <= ParamCount then
104 begin
105 Inc(i);
106 GameWad := ParamStr(i);
107 end;
108 end
109 else if p = '--editor-wad' then
110 begin
111 if i + 1 <= ParamCount then
112 begin
113 Inc(i);
114 EditorWad := ParamStr(i);
115 end;
116 end;
117 Inc(i);
118 end;
119 ParamFileIndex := i;
120 end;
122 procedure CheckParamFiles;
123 var i: Integer;
124 begin
125 i := ParamFileIndex;
126 if i <= ParamCount then
127 StartMap := ParamStr(i);
128 end;
130 procedure InitLogs;
131 begin
132 if LogFileName = '' then
133 LogFileName := 'Editor.log';
135 if LogFileName <> '' then
136 e_InitLog(LogFileName, WM_NEWFILE);
138 {$IF DECLARED(UseHeapTrace)}
139 (* http://wiki.freepascal.org/heaptrc *)
140 GlobalSkipIfNoLeaks := True;
141 //SetHeapTraceOutput('EditorLeaks.log');
142 //HaltOnError := False;
143 {$ENDIF}
144 end;
146 begin
147 Application.ExceptionDialog := aedOkMessageBox;
148 Application.AddOnExceptionHandler(THandlerObject.ExceptionHandler, True);
149 Application.Initialize();
151 EditorDir := ExtractFilePath(Application.ExeName);
152 CfgFileName := EditorDir + DirectorySeparator + 'Editor.cfg';
153 GameWad := EditorDir + DirectorySeparator + 'data' + DirectorySeparator + 'game.wad';
154 EditorWad := EditorDir + DirectorySeparator + 'data' + DirectorySeparator + 'editor.wad';
156 CheckParamOptions;
157 InitLogs;
159 Application.CreateForm(TMainForm, MainForm);
160 Application.CreateForm(TOptionsForm, OptionsForm);
161 Application.CreateForm(TAboutForm, AboutForm);
162 Application.CreateForm(TMapOptionsForm, MapOptionsForm);
163 Application.CreateForm(TActivationTypeForm, ActivationTypeForm);
164 Application.CreateForm(TAddResourceForm, AddResourceForm);
165 Application.CreateForm(TKeysForm, KeysForm);
166 Application.CreateForm(TMapCheckForm, MapCheckForm);
167 Application.CreateForm(TMapOptimizationForm, MapOptimizationForm);
168 Application.CreateForm(TAddTextureForm, AddTextureForm);
169 Application.CreateForm(TSaveMapForm, SaveMapForm);
170 Application.CreateForm(TSelectMapForm, SelectMapForm);
171 Application.CreateForm(TAddSkyForm, AddSkyForm);
172 Application.CreateForm(TAddSoundForm, AddSoundForm);
173 Application.CreateForm(TSaveMiniMapForm, SaveMiniMapForm);
174 Application.CreateForm(TPackMapForm, PackMapForm);
175 Application.CreateForm(TMapTestForm, MapTestForm);
176 Application.CreateForm(TChooseTypeForm, ChooseTypeForm);
177 Application.CreateForm(TSelectLanguageForm, SelectLanguageForm);
179 CheckParamFiles;
181 Application.Run();
182 end.