X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Feditor%2Ff_packmap.pas;h=00e3dc0372b3984515df0b1068ee1fb9d6de1763;hb=ecf69fd49c810dc4fe78092ec1f0204cbb719e01;hp=428d9d355a0735a0805f02038ab128ddea81a41b;hpb=6fb9c23afad22a71679525dc44ea32675d73609f;p=d2df-editor.git diff --git a/src/editor/f_packmap.pas b/src/editor/f_packmap.pas index 428d9d3..00e3dc0 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; + f_main, math, g_language, g_resources, e_log; {$R *.lfm} @@ -70,71 +70,44 @@ begin eWAD.Text := SaveDialog.FileName; end; -function ProcessResource(wad_to: TWADEditor_1; - section_to, filename, section, resource: String): Boolean; -var - wad2: TWADEditor_1; - data: Pointer; - reslen: Integer; - //s: string; - +function ProcessResource(wad_to, section_to, filename, section, resource: String): Boolean; + var + data: Pointer; + res, len: Integer; + us, un: String; begin - Result := False; - + Result := True; if filename = '' then - g_ProcessResourceStr(OpenedMap, @filename, nil, nil) + g_GetResourceSection(OpenedMap, filename, us, un) else - filename := EditorDir+'wads/'+filename; - -// Читаем ресурс из WAD-файла карты или какого-то другого: - wad2 := TWADEditor_1.Create(); - - if not wad2.ReadFile(filename) then - begin - MessageBox(0, PChar(Format(_lc[I_MSG_WAD_ERROR], - [ExtractFileName(filename)])), - PChar(_lc[I_MSG_ERROR]), MB_OK + MB_ICONERROR); - wad2.Free(); - Exit; - end; + filename := EditorDir + 'wads/' + filename; + e_WriteLog('ProcessResource: "' + wad_to + '" "' + section_to + '" "' + filename + '" "' + section + '" "' + resource + '"', MSG_NOTIFY); - if not wad2.GetResource(utf2win(section), utf2win(resource), data, reslen) then - begin - MessageBox(0, PChar(Format(_lc[I_MSG_RES_ERROR], - [filename, section, resource])), - PChar(_lc[I_MSG_ERROR]), MB_OK + MB_ICONERROR); - wad2.Free(); - Exit; - end; - - wad2.Free(); + if resource = '' then Exit; - {if wad_to.HaveResource(utf2win(section_to), utf2win(resource)) then - begin - for a := 2 to 256 do + g_ReadResource(filename, section, resource, data, len); + if data <> nil then 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 + (* Write resource only if it does not exists *) + g_ExistsResource(wad_to, section_to, resource, res); + if res <> 0 then + begin + g_AddResource(wad_to, section_to, resource, data, len, res); + ASSERT(res = 0) + end; + FreeMem(data); + end + else 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; + //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 end; procedure TPackMapForm.bPackClick(Sender: TObject); var - WAD: TWADEditor_1; + WadFile: String; mr: TMapReader_1; mw: TMapWriter_1; data: Pointer; @@ -159,12 +132,8 @@ begin if data = nil then Exit; - WAD := TWADEditor_1.Create(); - -// Не перезаписывать WAD, а дополнить: - if cbAdd.Checked then - if WAD.ReadFile(eWAD.Text) then - WAD.CreateImage(); + if not cbAdd.Checked then + g_DeleteFile(eWAD.Text, '.bak0'); // Читаем карту из памяти: mr := TMapReader_1.Create(); @@ -182,7 +151,7 @@ begin if IsSpecialTexture(res) then Continue; - g_ProcessResourceStr(res, @filename, @section, @resource); + g_GetResourceSection(res, filename, section, resource); // Не записывать стандартные текстуры: if (not cbNonStandart.Checked) or @@ -190,10 +159,9 @@ begin (AnsiLowerCase(filename) <> SHRSHADE_WAD) ) then begin // Копируем ресурс текстуры: - if not ProcessResource(WAD, tsection, filename, section, resource) then + if not f_packmap.ProcessResource(eWAD.Text, tsection, filename, section, resource) then begin mr.Free(); - WAD.Free(); Exit; end; @@ -211,7 +179,7 @@ begin if cbSky.Checked then begin res := win2utf(header.SkyName); - g_ProcessResourceStr(res, @filename, @section, @resource); + g_GetResourceSection(res, filename, section, resource); // Не записывать стандартное небо: if (not cbNonStandart.Checked) or @@ -219,10 +187,9 @@ begin (AnsiLowerCase(filename) <> SHRSHADE_WAD) ) then begin // Копируем ресурс неба: - if not ProcessResource(WAD, ssection, filename, section, resource) then + if not f_packmap.ProcessResource(eWAD.Text, ssection, filename, section, resource) then begin mr.Free(); - WAD.Free(); Exit; end; @@ -237,7 +204,7 @@ begin if cbMusic.Checked then begin res := win2utf(header.MusicName); - g_ProcessResourceStr(res, @filename, @section, @resource); + g_GetResourceSection(res, filename, section, resource); // Не записывать стандартную музыку: if (not cbNonStandart.Checked) or @@ -245,10 +212,9 @@ begin (AnsiLowerCase(filename) <> SHRSHADE_WAD) ) then begin // Копируем ресурс музыки: - if not ProcessResource(WAD, msection, filename, section, resource) then + if not f_packmap.ProcessResource(eWAD.Text, msection, filename, section, resource) then begin mr.Free(); - WAD.Free(); Exit; end; @@ -298,7 +264,7 @@ begin if res = '' then Break; - g_ProcessResourceStr(res, @filename, @section, @resource); + g_GetResourceSection(res, @filename, @section, @resource); // Не записывать стандартные дополнительные текстуры: if (not cbNonStandart.Checked) or @@ -306,7 +272,7 @@ begin (AnsiLowerCase(filename) <> SHRSHADE_WAD) ) then begin // Копируем ресурс дополнительной текстуры: - if ProcessResource(WAD, tsection, filename, section, resource) then + if f_packmap.ProcessResource(eWAD.Text, tsection, filename, section, resource) then begin Нужно проверять есть такая текстура textures и есть ли она вообще? @@ -338,18 +304,13 @@ begin // Сохраняем карту из памяти под новым именем в WAD-файл: len := mw.SaveMap(data); - WAD.AddResource(data, len, eResource.Text, ''); - WAD.SaveTo(eWAD.Text); - + g_AddResource(eWAD.Text, '', eResource.Text, data, len, a); mw.Free(); mr.Free(); - WAD.Free(); - - MessageDlg(Format(_lc[I_MSG_PACKED], - [eResource.Text, ExtractFileName(eWAD.Text)]), - mtInformation, [mbOK], 0); - Close(); + + ASSERT(a = 0); (* saved *) + MessageDlg(Format(_lc[I_MSG_PACKED], [eResource.Text, ExtractFileName(eWAD.Text)]), mtInformation, [mbOK], 0); end; procedure TPackMapForm.FormCreate(Sender: TObject);