X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Feditor%2Ff_addresource.pas;h=103d9b031f3165cb39920cd042a8f4d56c5dcf3f;hb=3360cb5c3e96b591451afa67a0f8a281db79e8c5;hp=edca4ed817570b631ebabe9260132922159974da;hpb=b5f9c55a34f89cc238eedc5f0c2620a2d8ba6687;p=d2df-editor.git diff --git a/src/editor/f_addresource.pas b/src/editor/f_addresource.pas index edca4ed..103d9b0 100644 --- a/src/editor/f_addresource.pas +++ b/src/editor/f_addresource.pas @@ -45,17 +45,16 @@ var implementation uses - f_main, WADSTRUCT, g_language, utils; + f_main, WADSTRUCT, g_language, utils, sfs, g_options; {$R *.lfm} const - STANDART_WAD = 'Standart.wad'; + STANDART_WAD = 'standart.wad'; procedure TAddResourceForm.FormActivate(Sender: TObject); -var - SR: TSearchRec; - + var + SR: TSearchRec; begin cbWADList.Clear(); cbSectionsList.Clear(); @@ -65,14 +64,14 @@ begin FFullResourceName := ''; FResourceSelected := False; - ChDir(EditorDir); - if FindFirst(EditorDir+'wads/*.wad', faAnyFile, SR) = 0 then + if FindFirst(WadsDir + DirectorySeparator + '*.*', faAnyFile, SR) = 0 then repeat - cbWADList.Items.Add(SR.Name); + if (SR.name <> '.') and (SR.name <> '..') then + cbWADList.Items.Add(SR.Name); until FindNext(SR) <> 0; FindClose(SR); -// "Standart.wad" в начало списка: +// "standart.wad" в начало списка: if cbWADList.Items.IndexOf(STANDART_WAD) > 0 then begin cbWADList.Items.Delete(cbWADList.Items.IndexOf(STANDART_WAD)); @@ -81,15 +80,15 @@ begin // WAD карты: if OpenedMap <> '' then - cbWADList.Items.Add(_lc[I_WAD_SPECIAL_MAP]); + cbWADList.Items.Add(MsgWadSpecialMap); end; procedure TAddResourceForm.bOKClick(Sender: TObject); begin if FResourceName = '' then begin - MessageBox(0, PChar(_lc[I_MSG_CHOOSE_RES]), - PChar(_lc[I_MSG_ERROR]), MB_OK + MB_ICONERROR); + Application.MessageBox(PChar(MsgMsgChooseRes), + PChar(MsgMsgError), MB_OK + MB_ICONERROR); Exit; end; @@ -103,87 +102,67 @@ begin end; procedure TAddResourceForm.cbWADListChange(Sender: TObject); -var - WAD: TWADEditor_1; - SectionList: SArray; - i: Integer; - FileName, fn, sn, rn: String; - + var + wad: TSFSFileList; + i: Integer; + FileName, Section, sn, rn: String; begin - WAD := TWADEditor_1.Create(); - -// Внешний WAD: - if cbWADList.Text <> _lc[I_WAD_SPECIAL_MAP] then - FileName := EditorDir+'wads/'+cbWADList.Text - else // WAD карты: - begin - g_ProcessResourceStr(OpenedMap, fn, sn, rn); - FileName := fn; - end; - -// Читаем секции: - WAD.ReadFile(FileName); - SectionList := WAD.GetSectionList(); - WAD.Free(); + if cbWADList.Text <> MsgWadSpecialMap then + FileName := WadsDir + DirectorySeparator + cbWADList.Text (* Resource wad *) + else + g_ProcessResourceStr(OpenedMap, FileName, sn, rn); (* Map wad *) cbSectionsList.Clear(); lbResourcesList.Clear(); - if SectionList <> nil then - for i := 0 to High(SectionList) do - if SectionList[i] <> '' then - cbSectionsList.Items.Add(win2utf(SectionList[i])) - else - cbSectionsList.Items.Add('..'); -end; - -procedure TAddResourceForm.cbSectionsListChange(Sender: TObject); -var - ResourceList: SArray; - WAD: TWADEditor_1; - i: DWORD; - FileName, SectionName, fn, sn, rn: String; - -begin - WAD := TWADEditor_1.Create(); - -// Внешний WAD: - if cbWADList.Text <> _lc[I_WAD_SPECIAL_MAP] then - FileName := EditorDir+'wads/'+cbWADList.Text - else // WAD карты: + wad := SFSFileList(FileName); + if wad <> nil then + begin + for i := 0 to wad.Count - 1 do begin - g_ProcessResourceStr(OpenedMap, fn, sn, rn); - FileName := fn; + Section := win2utf(Copy(wad.Files[i].path, 1, Length(wad.Files[i].path) - 1)); + if cbSectionsList.Items.IndexOf(Section) = -1 then + cbSectionsList.Items.Add(Section) end; + wad.Destroy + end; -// Читаем WAD: - WAD.ReadFile(FileName); + (* Update resource list (see below) *) + cbSectionsListChange(Sender) +end; - if cbSectionsList.Text <> '..' then - SectionName := utf2win(cbSectionsList.Text) +procedure TAddResourceForm.cbSectionsListChange(Sender: TObject); + var + wad: TSFSFileList; + i: Integer; + FileName, Section, SectionName, sn, rn: String; +begin + if cbWADList.Text <> MsgWadSpecialMap then + FileName := WadsDir + DirectorySeparator + cbWADList.Text (* Resource wad *) else - SectionName := ''; - -// Читаем ресурсы выбранной секции: - ResourceList := WAD.GetResourcesList(SectionName); - - WAD.Free(); + g_ProcessResourceStr(OpenedMap, FileName, sn, rn); (* Map wad *) + SectionName := cbSectionsList.Text; lbResourcesList.Clear(); - if ResourceList <> nil then - for i := 0 to High(ResourceList) do - lbResourcesList.Items.Add(win2utf(ResourceList[i])); + wad := SFSFileList(FileName); + if wad <> nil then + begin + for i := 0 to wad.Count - 1 do + begin + Section := win2utf(Copy(wad.Files[i].path, 1, Length(wad.Files[i].path) - 1)); + if Section = SectionName then + lbResourcesList.Items.Add(win2utf(wad.Files[i].name)) + end; + wad.Destroy + end; end; procedure TAddResourceForm.lbResourcesListClick(Sender: TObject); -var - FileName, SectionName, fn: String; - + var + FileName, fn: String; begin - FResourceSelected := (lbResourcesList.SelCount > 0) or - (lbResourcesList.ItemIndex > -1); - + FResourceSelected := (lbResourcesList.SelCount > 0) or (lbResourcesList.ItemIndex > -1); if not FResourceSelected then begin FResourceName := ''; @@ -191,25 +170,18 @@ begin Exit; end; - if cbSectionsList.Text = '..' then - SectionName := '' - else - SectionName := utf2win(cbSectionsList.Text); - if cbWADList.Text[1] <> '<' then FileName := cbWADList.Text else FileName := ''; - FResourceName := FileName+':'+SectionName+'\'+utf2win(lbResourcesList.Items[lbResourcesList.ItemIndex]); + FResourceName := FileName + ':' + cbSectionsList.Text + '\' + lbResourcesList.Items[lbResourcesList.ItemIndex]; + g_ProcessResourceStr(OpenedMap, @fn, nil, nil); if FileName <> '' then - FFullResourceName := EditorDir+'wads/'+FResourceName + FFullResourceName := WadsDir + DirectorySeparator + FResourceName else - begin - g_ProcessResourceStr(OpenedMap, @fn, nil, nil); - FFullResourceName := fn+FResourceName; - end; + FFullResourceName := fn + FResourceName end; end.