X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Feditor%2Ff_savemap.pas;h=a78e6009a44a3dd6d6c165eadb50f7a7c3299155;hb=952e5c9c629e44e260c55f2756d72a199d8d9052;hp=c9fff9e176ad1ad4af64556d727649e390d3111f;hpb=2789c629b21057292614b015b9a03595bab89c2f;p=d2df-editor.git diff --git a/src/editor/f_savemap.pas b/src/editor/f_savemap.pas index c9fff9e..a78e600 100644 --- a/src/editor/f_savemap.pas +++ b/src/editor/f_savemap.pas @@ -17,7 +17,7 @@ type 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); @@ -35,7 +35,7 @@ var implementation uses - MAPREADER, MAPSTRUCT, g_language, g_resources, sfs; + BinEditor, MAPREADER, WADEDITOR, WADSTRUCT, MAPSTRUCT, g_language; {$R *.lfm} @@ -69,9 +69,9 @@ begin for a := 0 to lbMapList.Count-1 do if eMapName.Text = lbMapList.Items[a] then begin - ok := Application.MessageBox(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; @@ -84,65 +84,81 @@ begin 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.