X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Feditor%2Ff_packmap.pas;h=9aaccfe1d593419ea12f5f52e913a496024e9648;hb=ba79a3849a16e4f11382fd712708dfecdb5ad3f6;hp=ac1d07d3d2f216a815d4483442e9876c5c380f75;hpb=4a5ba4792f76361e97b9fdddf42fcec270e06e51;p=d2df-editor.git diff --git a/src/editor/f_packmap.pas b/src/editor/f_packmap.pas index ac1d07d..9aaccfe 100644 --- a/src/editor/f_packmap.pas +++ b/src/editor/f_packmap.pas @@ -53,7 +53,7 @@ implementation uses BinEditor, WADEDITOR, g_map, MAPREADER, MAPWRITER, MAPSTRUCT, - f_main, math, g_language, g_resources; + f_main, math, g_language, g_options, e_log; {$R *.lfm} @@ -64,41 +64,67 @@ const procedure TPackMapForm.bSelectWADClick(Sender: TObject); begin - SaveDialog.Filter := _lc[I_FILE_FILTER_WAD]; + SaveDialog.Filter := MsgFileFilterWad; if SaveDialog.Execute() then eWAD.Text := SaveDialog.FileName; end; function ProcessResource(wad_to: TWADEditor_1; section_to, filename, section, resource: String): Boolean; - var - data: Pointer; - reslen: Integer; +var + wad2: TWADEditor_1; + data: Pointer; + reslen: Integer; + //s: string; + begin + Result := False; + if filename = '' then g_ProcessResourceStr(OpenedMap, @filename, nil, nil) else - filename := EditorDir + 'wads/' + filename; + filename := WadsDir + DirectorySeparator + filename; + +// Читаем ресурс из WAD-файла карты или какого-то другого: + wad2 := TWADEditor_1.Create(); - g_ReadResource(filename, section, resource, data, reslen); - if data <> nil then + if not wad2.ReadFile(filename) then begin - (* Write resource only if it does not exists *) - if not wad_to.HaveResource(utf2win(section_to), utf2win(resource)) then - begin - if not wad_to.HaveSection(utf2win(section_to)) then - wad_to.AddSection(utf2win(section_to)); - wad_to.AddResource(data, reslen, utf2win(resource), utf2win(section_to)) - end; - FreeMem(data); - Result := True - end - else + Application.MessageBox(PChar(Format(MsgMsgWadError, [ExtractFileName(filename)])), PChar(MsgMsgError), MB_OK + MB_ICONERROR); + wad2.Free(); + Exit; + end; + + if not wad2.GetResource(utf2win(section), utf2win(resource), data, reslen) then + begin + Application.MessageBox(PChar(Format(MsgMsgResError, [filename, section, resource])), PChar(MsgMsgError), MB_OK + MB_ICONERROR); + wad2.Free(); + Exit; + end; + + wad2.Free(); + + {if wad_to.HaveResource(utf2win(section_to), utf2win(resource)) then + begin + for a := 2 to 256 do + begin + s := IntToStr(a); + if not wad_to.HaveResource(utf2win(section_to), utf2win(resource+s)) then Break; + end; + resource := resource+s; + end;} + +// Если такого ресурса нет в WAD-файле-назначении, то копируем: + if not wad_to.HaveResource(utf2win(section_to), utf2win(resource)) then begin - //MessageBox(0, PChar(Format(_lc[I_MSG_WAD_ERROR], [ExtractFileName(filename)])), PChar(_lc[I_MSG_ERROR]), MB_OK + MB_ICONERROR); - MessageBox(0, PChar(Format(_lc[I_MSG_RES_ERROR], [filename, section, resource])), PChar(_lc[I_MSG_ERROR]), MB_OK + MB_ICONERROR); - Result := False - end + if not wad_to.HaveSection(utf2win(section_to)) then + wad_to.AddSection(utf2win(section_to)); + wad_to.AddResource(data, reslen, utf2win(resource), utf2win(section_to)); + end; + + FreeMem(data); + + Result := True; end; procedure TPackMapForm.bPackClick(Sender: TObject); @@ -124,7 +150,7 @@ begin msection := eMSection.Text; // Сохраняем карту в память: - data := SaveMap(''); + data := SaveMap('', ''); if data = nil then Exit; @@ -314,16 +340,13 @@ begin mr.Free(); WAD.Free(); - MessageDlg(Format(_lc[I_MSG_PACKED], - [eResource.Text, ExtractFileName(eWAD.Text)]), - mtInformation, [mbOK], 0); - + MessageDlg(Format(MsgMsgPacked, [eResource.Text, ExtractFileName(eWAD.Text)]), mtInformation, [mbOK], 0); Close(); end; procedure TPackMapForm.FormCreate(Sender: TObject); begin - SaveDialog.InitialDir := EditorDir; + SaveDialog.InitialDir := MapsDir; end; end.