From: DeaDDooMER Date: Wed, 16 Jan 2019 14:45:07 +0000 (+0300) Subject: Added new optios(thanks GranMinigun!), added .dfz extension(now default) and fixed... X-Git-Url: https://deadsoftware.ru/gitweb?p=d2df-editor.git;a=commitdiff_plain;h=ecf69fd49c810dc4fe78092ec1f0204cbb719e01;hp=a140ef8433c5e5cdf3d2ec4a6343c5380535e200 Added new optios(thanks GranMinigun!), added .dfz extension(now default) and fixed zip-related bugfixes --- diff --git a/src/editor/f_main.lfm b/src/editor/f_main.lfm index 344fefb..4eae45a 100644 --- a/src/editor/f_main.lfm +++ b/src/editor/f_main.lfm @@ -747,8 +747,8 @@ object MainForm: TMainForm end end object OpenDialog: TOpenDialog - DefaultExt = '.wad' - Filter = 'Карты Doom 2D: Forever (*.wad)|*.wad|Старые карты Doom 2D: Forever (*.ini)|*.ini|Все файлы (*.*)|*.*' + DefaultExt = '.dfz' + Filter = 'Карты Doom 2D: Forever (*.dfz, *.wad)|*.dfz;*.wad|Старые карты Doom 2D: Forever 0.30 (*.ini)|*.ini|Все файлы (*.*)|*.*' Options = [ofHideReadOnly, ofNoChangeDir, ofPathMustExist, ofFileMustExist, ofEnableSizing, ofDontAddToRecent] left = 32 top = 64 @@ -1721,8 +1721,8 @@ object MainForm: TMainForm } end object SaveDialog: TSaveDialog - DefaultExt = '.wad' - Filter = 'Карты Doom 2D: Forever (*.wad)|*.wad|Все файлы (*.*)|*.*' + DefaultExt = '.dfz' + Filter = 'Карты Doom 2D: Forever (*.dfz)|*.dfz|Карты Doom 2D: Forever (*.wad)|Все файлы (*.*)|*.*' Options = [ofHideReadOnly, ofNoChangeDir, ofPathMustExist, ofNoReadOnlyReturn, ofEnableSizing, ofDontAddToRecent] left = 64 top = 64 diff --git a/src/editor/f_main.pas b/src/editor/f_main.pas index 5624e6a..95d468d 100644 --- a/src/editor/f_main.pas +++ b/src/editor/f_main.pas @@ -2737,6 +2737,9 @@ begin s := config.ReadStr('Editor', 'Language', ''); gLanguage := s; + Compress := config.ReadBool('Editor', 'Compress', True); + Backup := config.ReadBool('Editor', 'Backup', True); + RecentCount := config.ReadInt('Editor', 'RecentCount', 5); if RecentCount > 10 then RecentCount := 10; diff --git a/src/editor/f_options.lfm b/src/editor/f_options.lfm index b100ee3..3e6cc23 100644 --- a/src/editor/f_options.lfm +++ b/src/editor/f_options.lfm @@ -1,12 +1,12 @@ object OptionsForm: TOptionsForm Left = 202 - Height = 262 + Height = 285 Top = 174 Width = 435 BorderIcons = [biSystemMenu] BorderStyle = bsSingle Caption = 'Настройки редактора' - ClientHeight = 262 + ClientHeight = 285 ClientWidth = 435 Color = clBtnFace Font.Color = clWindowText @@ -14,14 +14,14 @@ object OptionsForm: TOptionsForm Font.Name = 'MS Sans Serif' OnActivate = FormActivate Position = poScreenCenter - LCLVersion = '1.6.4.0' + LCLVersion = '1.8.4.0' object GroupBox1: TGroupBox Left = 8 - Height = 225 + Height = 248 Top = 0 Width = 425 - ClientHeight = 207 - ClientWidth = 421 + ClientHeight = 246 + ClientWidth = 423 TabOrder = 0 object sDotColor: TShape Left = 344 @@ -31,25 +31,25 @@ object OptionsForm: TOptionsForm end object LabelGrid: TLabel Left = 6 - Height = 13 + Height = 14 Top = 74 - Width = 61 + Width = 73 Caption = 'Шаги сетки:' ParentColor = False end object LabelGridCol: TLabel Left = 190 - Height = 13 + Height = 14 Top = 2 - Width = 60 + Width = 69 Caption = 'Цвет сетки:' ParentColor = False end object LabelBack: TLabel Left = 190 - Height = 13 + Height = 14 Top = 43 - Width = 57 + Width = 66 Caption = 'Цвет фона:' ParentColor = False end @@ -62,9 +62,9 @@ object OptionsForm: TOptionsForm end object LabelPreview: TLabel Left = 190 - Height = 13 + Height = 14 Top = 72 - Width = 216 + Width = 252 Caption = 'Цвет фона поля предпросмотра текстуры:' ParentColor = False WordWrap = True @@ -78,49 +78,49 @@ object OptionsForm: TOptionsForm end object LabelMinimap: TLabel Left = 190 - Height = 13 + Height = 14 Top = 129 - Width = 112 + Width = 129 Caption = 'Масштаб мини-карты:' ParentColor = False end object LabelRecent: TLabel Left = 190 - Height = 13 + Height = 14 Top = 162 - Width = 199 + Width = 233 Caption = 'Запоминать последних открытых карт:' ParentColor = False WordWrap = True end object LabelLanguage: TLabel Left = 6 - Height = 13 + Height = 14 Top = 162 - Width = 31 + Width = 34 Caption = 'Язык:' ParentColor = False end object LabelGridSize: TLabel Left = 6 - Height = 13 + Height = 14 Top = 122 - Width = 105 + Width = 121 Caption = 'Размер точек сетки:' ParentColor = False WordWrap = True end object cbShowDots: TCheckBox Left = 6 - Height = 17 + Height = 21 Top = 2 - Width = 112 + Width = 130 Caption = 'Показывать сетку' TabOrder = 0 end object UpDown1: TUpDown Left = 143 - Height = 21 + Height = 26 Top = 74 Width = 12 Associate = eDotStepOne @@ -132,7 +132,7 @@ object OptionsForm: TOptionsForm end object eDotStepOne: TEdit Left = 86 - Height = 21 + Height = 26 Top = 74 Width = 57 TabOrder = 3 @@ -167,10 +167,10 @@ object OptionsForm: TOptionsForm end object cbScale: TComboBox Left = 344 - Height = 21 + Height = 27 Top = 129 Width = 70 - ItemHeight = 13 + ItemHeight = 0 ItemIndex = 0 Items.Strings = ( '1x' @@ -182,23 +182,23 @@ object OptionsForm: TOptionsForm end object cbShowTexture: TCheckBox Left = 6 - Height = 17 + Height = 21 Top = 18 - Width = 167 + Width = 196 Caption = 'Показывать текстуру панели' TabOrder = 1 end object cbShowSize: TCheckBox Left = 6 - Height = 17 + Height = 21 Top = 34 - Width = 169 + Width = 194 Caption = 'Показывать размеры панели' TabOrder = 2 end object eRecent: TEdit Left = 344 - Height = 21 + Height = 26 Top = 180 Width = 57 TabOrder = 15 @@ -206,7 +206,7 @@ object OptionsForm: TOptionsForm end object UpDown3: TUpDown Left = 401 - Height = 21 + Height = 26 Top = 180 Width = 12 Associate = eRecent @@ -218,7 +218,7 @@ object OptionsForm: TOptionsForm end object eDotStepTwo: TEdit Left = 86 - Height = 21 + Height = 26 Top = 98 Width = 57 TabOrder = 5 @@ -226,7 +226,7 @@ object OptionsForm: TOptionsForm end object UpDown2: TUpDown Left = 143 - Height = 21 + Height = 26 Top = 98 Width = 12 Associate = eDotStepTwo @@ -238,9 +238,9 @@ object OptionsForm: TOptionsForm end object rbRussian: TRadioButton Left = 86 - Height = 17 + Height = 21 Top = 162 - Width = 60 + Width = 71 Caption = 'Русский' Checked = True TabOrder = 8 @@ -248,18 +248,18 @@ object OptionsForm: TOptionsForm end object rbEnglish: TRadioButton Left = 86 - Height = 17 + Height = 21 Top = 186 - Width = 52 + Width = 64 Caption = 'English' TabOrder = 9 end object cbDotSize: TComboBox Left = 82 - Height = 21 + Height = 27 Top = 136 Width = 73 - ItemHeight = 13 + ItemHeight = 0 ItemIndex = 0 Items.Strings = ( '1' @@ -270,19 +270,35 @@ object OptionsForm: TOptionsForm end object cbCheckerboard: TCheckBox Left = 190 - Height = 17 + Height = 21 Top = 94 - Width = 145 + Width = 166 Caption = 'Использовать шахматку' Checked = True State = cbChecked TabOrder = 12 end + object cbCompress: TCheckBox + Left = 190 + Height = 21 + Top = 208 + Width = 212 + Caption = 'Сжимать архив при сохранении' + TabOrder = 17 + end + object cbBackup: TCheckBox + Left = 190 + Height = 21 + Top = 224 + Width = 222 + Caption = 'Резервная копия при сохранении' + TabOrder = 18 + end end object bOK: TButton Left = 262 Height = 25 - Top = 232 + Top = 256 Width = 75 Caption = 'ОК' Default = True @@ -292,7 +308,7 @@ object OptionsForm: TOptionsForm object bCancel: TButton Left = 358 Height = 25 - Top = 232 + Top = 256 Width = 75 Cancel = True Caption = 'Отмена' @@ -323,7 +339,7 @@ object OptionsForm: TOptionsForm 'ColorS=F0FBFF' 'ColorT=A4A0A0' ) - left = 200 - top = 232 + left = 96 + top = 216 end end diff --git a/src/editor/f_options.pas b/src/editor/f_options.pas index 1f297ec..8a77b18 100644 --- a/src/editor/f_options.pas +++ b/src/editor/f_options.pas @@ -10,10 +10,15 @@ uses ExtCtrls, ComCtrls, Registry; type + + { TOptionsForm } + TOptionsForm = class (TForm) bOK: TButton; bCancel: TButton; cbCheckerboard: TCheckBox; + cbCompress: TCheckBox; + cbBackup: TCheckBox; ColorDialog: TColorDialog; GroupBox1: TGroupBox; // Общие настройки: @@ -72,7 +77,7 @@ procedure RegisterFileType(ext: String; FileName: String); implementation uses - f_main, StdConvs, CONFIG, g_language; + f_main, StdConvs, CONFIG, g_language, g_resources; {$R *.lfm} @@ -117,6 +122,8 @@ begin sBackColor.Brush.Color := BackColor; sPreviewColor.Brush.Color := PreviewColor; cbCheckerboard.Checked := UseCheckerboard; + cbCompress.Checked := Compress; + cbBackup.Checked := Backup; if Scale = 2 then cbScale.ItemIndex := 1 else @@ -187,6 +194,8 @@ begin BackColor := sBackColor.Brush.Color; PreviewColor := sPreviewColor.Brush.Color; UseCheckerboard := cbCheckerboard.Checked; + Compress := cbCompress.Checked; + Backup := cbBackup.Checked; if cbScale.ItemIndex = 1 then Scale := 2 @@ -214,6 +223,8 @@ begin config.WriteInt('Editor', 'Scale', cbScale.ItemIndex); config.WriteInt('Editor', 'RecentCount', re); config.WriteStr('Editor', 'Language', gLanguage); + config.WriteBool('Editor', 'Compress', Compress); + config.WriteBool('Editor', 'Backup', Backup); if RecentCount <> re then begin diff --git a/src/editor/f_packmap.lfm b/src/editor/f_packmap.lfm index 2a275eb..f5babda 100644 --- a/src/editor/f_packmap.lfm +++ b/src/editor/f_packmap.lfm @@ -177,7 +177,7 @@ object PackMapForm: TPackMapForm TabOrder = 1 end object SaveDialog: TSaveDialog - DefaultExt = '.wad' + DefaultExt = '.dfz' Filter = 'Карты Doom2D: Forever (*.wad)|*.wad|All files (*.*)|*.*' Options = [ofHideReadOnly, ofPathMustExist, ofEnableSizing, ofDontAddToRecent] left = 8 diff --git a/src/editor/f_packmap.pas b/src/editor/f_packmap.pas index cdbe105..00e3dc0 100644 --- a/src/editor/f_packmap.pas +++ b/src/editor/f_packmap.pas @@ -133,15 +133,7 @@ begin Exit; if not cbAdd.Checked then - begin - (* Overwrite wad *) - if FileExists(eWAD.Text) then - begin - if FileExists(eWAD.Text + '.bak0') then - ASSERT(DeleteFile(eWAD.Text + '.bak0')); - ASSERT(RenameFile(eWAD.Text, eWAD.Text + '.bak0')) - end - end; + g_DeleteFile(eWAD.Text, '.bak0'); // Читаем карту из памяти: mr := TMapReader_1.Create(); diff --git a/src/editor/g_language.pas b/src/editor/g_language.pas index 99a1855..75d8787 100644 --- a/src/editor/g_language.pas +++ b/src/editor/g_language.pas @@ -543,6 +543,8 @@ Type I_LAB_ES_MINIMAP, I_LAB_ES_RECENT, I_LAB_ES_LANGUAGE, + I_LAB_ES_COMPRESS, + I_LAB_ES_BACKUP, I_LAB_PACK_SAVE_TO, I_LAB_PACK_MAP_NAME, @@ -1678,6 +1680,10 @@ Const 'Запоминать последних открытых карт:'), ('LAB ES LANGUAGE', 'Language:', 'Язык:'), + ('LAB ES COMPRESS', 'Compress archive when save', + 'Сжимать архив при сохранении'), + ('LAB ES BACKUP', 'Make backup before save', + 'Резервная копия при сохранении'), ('LAB PACK SAVE TO', 'Save to:', 'Сохранить в:'), @@ -1796,10 +1802,10 @@ Const ('WAD SPECIAL TEXS', '', '<СПЕЦТЕКСТУРЫ>'), - ('FILE FILTER ALL', 'Doom 2D: Forever Maps (*.wad)|*.wad|Old Doom 2D: Forever 0.30 Maps (*.ini)|*.ini|All Files (*.*)|*.*', - 'Карты Doom 2D: Forever (*.wad)|*.wad|Старые карты Doom 2D: Forever 0.30 (*.ini)|*.ini|Все файлы (*.*)|*.*'), - ('FILE FILTER WAD', 'Doom 2D: Forever Maps (*.wad)|*.wad|All Files (*.*)|*.*', - 'Карты Doom 2D: Forever (*.wad)|*.wad|Все файлы (*.*)|*.*'), + ('FILE FILTER ALL', 'Doom 2D: Forever Maps (*.dfz, *.wad)|*.dfz;*.wad|Doom 2D: Forever 0.30 Maps (*.ini)|*.ini|Все файлы (*.*)|*.*', + 'Карты Doom 2D: Forever (*.dfz, *.wad)|*.dfz;*.wad|Старые карты Doom 2D: Forever 0.30 (*.ini)|*.ini|Все файлы (*.*)|*.*'), + ('FILE FILTER WAD', 'Doom 2D: Forever Maps (*.dfz)|*.dfz|Doom 2D: Forever Maps (*.wad)|*.wad|Все файлы (*.*)|*.*', + 'Карты Doom 2D: Forever (*.dfz)|*.dfz|Карты Doom 2D: Forever (*.wad)|*.wad|Все файлы (*.*)|*.*'), ('EDITOR TITLE', 'Doom 2D: Forever Map Editor', 'Редактор карт Doom 2D: Forever'), @@ -2330,6 +2336,8 @@ begin cbShowTexture.Caption := _lc[I_CTRL_ES_TEXTURE]; cbShowSize.Caption := _lc[I_CTRL_ES_PANEL_SIZE]; cbCheckerboard.Caption := _lc[I_CTRL_ES_CHECKERBOARD]; + cbCompress.Caption := _lc[I_LAB_ES_COMPRESS]; + cbBackup.Caption := _lc[I_LAB_ES_BACKUP]; LabelGrid.Caption := _lc[I_LAB_ES_GRID]; LabelGridCol.Caption := _lc[I_LAB_ES_GRID_COLOR]; LabelGridSize.Caption := _lc[I_LAB_ES_GRID_SIZE]; diff --git a/src/editor/g_resources.pas b/src/editor/g_resources.pas index 9605b1a..0e383c3 100644 --- a/src/editor/g_resources.pas +++ b/src/editor/g_resources.pas @@ -3,6 +3,13 @@ unit g_resources; interface (** + g_GetResourceSection + Parse path in form 'path/to/file.wad:some/section/resouce' to + wad = 'path/to/file.wa', section = 'some/section', name = 'resource' + + g_DeleteFile + Delete file if it exists. Make backup if enabled. + g_ReadResource Read whole file from wad (data <> nil) and (len > 0) when ok @@ -26,7 +33,13 @@ interface res = 0 when ok **) + (* Editor options *) + var + Compress: Boolean; + Backup: Boolean; + procedure g_GetResourceSection (path: String; out wad, section, name: String); + procedure g_DeleteFile(wad: String; backupPostfix: String = '.bak'); procedure g_ReadResource (wad, section, name: String; out data: PByte; out len: Integer); procedure g_ReadSubResource (wad, section0, name0, section1, name1: String; out data: PByte; out len: Integer); @@ -84,6 +97,26 @@ implementation wad := Copy(path, 1, i - 1); end; + procedure g_DeleteFile (wad: String; backupPostfix: String = '.bak'); + var newwad: String; + begin + if Backup then + begin + if FileExists(wad) then + begin + newwad := wad + backupPostfix; + if FileExists(newwad) then + ASSERT(DeleteFile(newwad)); + ASSERT(RenameFile(wad, newwad)) + end + end + else + begin + if FileExists(wad) then + ASSERT(DeleteFile(wad)) + end + end; + procedure g_AddResourceToDFWAD (wad, section, name: String; const data: PByte; len: Integer; out res: Integer); var f: TWADEditor_1; begin @@ -100,12 +133,7 @@ implementation f.CreateImage; f.RemoveResource(section, name); f.AddResource(data, len, name, section); - if FileExists(wad) then - begin - if FileExists(wad + '.bak') then - ASSERT(DeleteFile(wad + '.bak')); - ASSERT(RenameFile(wad, wad + '.bak')) - end; + g_DeleteFile(wad); f.SaveTo(wad); f.Free; res := 0 @@ -124,8 +152,8 @@ implementation var ds: TSFSMemoryChunkStream; begin SetLength(dir, n + 1); - ds := TSFSMemoryChunkStream.Create(data, len, false); - dir[n] := dfzip.ZipOne(ts, name, ds); + ds := TSFSMemoryChunkStream.Create(data, len, False); + dir[n] := dfzip.ZipOne(ts, name, ds, Compress); ds.Free; INC(n); end; @@ -146,7 +174,7 @@ implementation for i := 0 to list.Count - 1 do begin path := NoTrailing(list.Files[i].path); - if (path <> section) or (list.Files[i].name <> section) then + if (path <> section) or (list.Files[i].name <> name) then begin g_ReadResource(wad, path, list.Files[i].name, data0, len0); ASSERT(data0 <> nil); @@ -170,12 +198,7 @@ implementation dfzip.writeCentralDir(ts, dir); ts.Free; - if FileExists(wad) then - begin - if FileExists(wad + '.bak') then - ASSERT(DeleteFile(wad + '.bak')); - ASSERT(RenameFile(wad, wad + '.bak')) - end; + g_DeleteFile(wad); ASSERT(RenameFile(tmp, wad)); res := 0 end; @@ -189,7 +212,7 @@ implementation e_WriteLog('g_AddResource "' + wad + '" "' + section + '" "' + name + '"', MSG_NOTIFY); if ext = '.wad' then g_AddResourceToDFWAD(wad, section, name, data, len, res) - else if (ext = '.pk3') or (ext = '.zip') or (ext = '.dfzip') then + else g_AddResourceToZip(wad, section, name, data, len, res) end; @@ -208,6 +231,7 @@ implementation end; f.CreateImage; f.RemoveResource(section, name); + g_DeleteFile(wad); f.SaveTo(wad); f.Free; res := 0 (* ok *) @@ -226,8 +250,8 @@ implementation var ds: TSFSMemoryChunkStream; begin SetLength(dir, n + 1); - ds := TSFSMemoryChunkStream.Create(data, len, false); - dir[n] := dfzip.ZipOne(ts, name, ds); + ds := TSFSMemoryChunkStream.Create(data, len, False); + dir[n] := dfzip.ZipOne(ts, name, ds, Compress); ds.Free; INC(n); end; @@ -248,7 +272,7 @@ implementation for i := 0 to list.Count - 1 do begin path := NoTrailing(list.Files[i].path); - if (path <> section) or (list.Files[i].name <> section) then + if (path <> section) or (list.Files[i].name <> name) then begin g_ReadResource(wad, path, list.Files[i].name, data0, len0); ASSERT(data0 <> nil); @@ -266,12 +290,7 @@ implementation dfzip.writeCentralDir(ts, dir); ts.Free; - if FileExists(wad) then - begin - if FileExists(wad + '.bak') then - ASSERT(DeleteFile(wad + '.bak')); - ASSERT(RenameFile(wad, wad + '.bak')) - end; + g_DeleteFile(wad); ASSERT(RenameFile(tmp, wad)); res := 0 end; @@ -284,7 +303,7 @@ implementation ext := LowerCase(SysUtils.ExtractFileExt(wad)); if ext = '.wad' then g_DeleteResourceFromDFWAD(wad, section, name, res) - else if (ext = '.dfz') or (ext = '.pk3') or (ext = '.zip') or (ext = '.dfzip') then + else g_DeleteResourceFromZip(wad, section, name, res) end; diff --git a/src/sfs/sfsZipFS.pas b/src/sfs/sfsZipFS.pas index 2cc9eff..e5e9968 100644 --- a/src/sfs/sfsZipFS.pas +++ b/src/sfs/sfsZipFS.pas @@ -417,6 +417,7 @@ begin result := StrEquCI1251(prefix, 'zip') or StrEquCI1251(prefix, 'pk3') or + StrEquCI1251(prefix, 'dfz') or StrEquCI1251(prefix, 'dfwad') or StrEquCI1251(prefix, 'dfzip'); end;