index 6d9b947f2427633045c4e37a057b7b30a1f62add..a78e6009a44a3dd6d6c165eadb50f7a7c3299155 100644 (file)
--- a/src/editor/f_savemap.pas
+++ b/src/editor/f_savemap.pas
Panel2: TPanel;
eMapName: TEdit;
- procedure GetMaps(FileName: String; placeName: Boolean);
+ procedure GetMaps(FileName: String; placeName: Boolean; ArchiveFormat: String);
procedure FormActivate(Sender: TObject);
procedure eMapNameChange(Sender: TObject);
procedure lbMapListClick(Sender: TObject);
implementation
uses
- MAPREADER, MAPSTRUCT, g_language, g_resources, sfs;
+ BinEditor, MAPREADER, WADEDITOR, WADSTRUCT, MAPSTRUCT, g_language;
{$R *.lfm}
for a := 0 to lbMapList.Count-1 do
if eMapName.Text = lbMapList.Items[a] then
begin
- ok := MessageBox(0, PChar(Format(_lc[I_MSG_MAP_EXISTS],
+ ok := Application.MessageBox(PChar(Format(MsgMsgMapExists,
[eMapName.Text])),
- PChar(_lc[I_MSG_SAVE_MAP]),
+ PChar(MsgMsgSaveMap),
MB_ICONQUESTION or MB_YESNO or MB_DEFBUTTON1) = mrYes;
if not ok then
Exit;
SaveMapForm.ModalResult := mrCancel;
end;
-procedure TSaveMapForm.GetMaps(FileName: String; placeName: Boolean);
- var
- nm: String;
- data: Pbyte;
- list: TSFSFileList;
- i, j, len, max_num: Integer;
- sign: Array [0..2] of Char;
+procedure TSaveMapForm.GetMaps(FileName: String; placeName: Boolean; ArchiveFormat: String);
+var
+ WAD: TWADEditor;
+ a, max_num, j: Integer;
+ ResList: SArray;
+ Data: Pointer;
+ Len: Integer;
+ Sign: Array [0..2] of Char;
+ nm: String;
+
begin
lbMapList.Items.Clear();
max_num := 1;
- list := SFSFileList(FileName);
- if list <> nil then
+ if ArchiveFormat = '' then
+ begin
+ // format not specified -> try open automatically and append to it (or create new default)
+ WAD := gWADEditorFactory.OpenFile(FileName);
+ if WAD = nil then
+ WAD := gWADEditorFactory.CreateDefaultEditor();
+ end
+ else
begin
- for i := 0 to list.Count - 1 do
+ // format specified -> appned using exactly this format (overwrite if not compatible)
+ WAD := gWADEditorFactory.CreateEditor(ArchiveFormat);
+ if WAD.ReadFile(FileName) = False then
+ WAD.FreeWAD();
+ end;
+
+ ResList := WAD.GetResourcesList('');
+
+ if ResList <> nil then
+ for a := 0 to High(ResList) do
begin
- g_ReadResource(FileName, win2utf(list.Files[i].path), win2utf(list.Files[i].name), data, len);
+ if not WAD.GetResource('', ResList[a], Data, Len) then
+ Continue;
+
+ CopyMemory(@Sign[0], Data, 3);
+ FreeMem(Data);
- if len >= 3 then
+ if Sign = MAP_SIGNATURE then
begin
- sign[0] := chr(data[0]);
- sign[1] := chr(data[1]);
- sign[2] := chr(data[2]);
- if sign = MAP_SIGNATURE then
+ nm := win2utf(ResList[a]);
+ lbMapList.Items.Add(nm);
+
+ if placeName then
begin
- nm := win2utf(list.Files[i].name);
- lbMapList.Items.Add(nm);
- if placeName then
+ nm := UpperCase(nm);
+ if (nm[1] = 'M') and
+ (nm[2] = 'A') and
+ (nm[3] = 'P') then
begin
- nm := UpperCase(nm);
- if (nm[1] = 'M') and (nm[2] = 'A') and (nm[3] = 'P') then
- begin
- nm := Trim(Copy(nm, 4, Length(nm)-3));
- j := StrToIntDef(nm, 0);
- if j >= max_num then
- max_num := j + 1;
- end
- end
- end
+ nm := Trim(Copy(nm, 4, Length(nm)-3));
+ j := StrToIntDef(nm, 0);
+ if j >= max_num then
+ max_num := j + 1;
+ end;
+ end;
end;
- if len > 0 then FreeMem(data)
+ Sign := '';
end;
- list.Destroy;
- end;
-
+ WAD.Free();
if placeName then
- begin
- nm := IntToStr(max_num);
- if Length(nm) < 2 then
- nm := '0' + nm;
- eMapName.Text := 'MAP' + nm
- end
+ begin
+ nm := IntToStr(max_num);
+ if Length(nm) < 2 then
+ nm := '0' + nm;
+ nm := 'MAP' + nm;
+ eMapName.Text := nm;
+ end
else
- begin
- eMapName.Text := ''
- end
+ eMapName.Text := '';
end;
end.