summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 45810fb)
raw | patch | inline | side by side (parent: 45810fb)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Mon, 2 Dec 2019 14:16:12 +0000 (17:16 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Mon, 2 Dec 2019 14:16:12 +0000 (17:16 +0300) |
src/editor/f_main.pas | patch | blob | history | |
src/shared/wadreader.pas | [new file with mode: 0644] | patch | blob |
diff --git a/src/editor/f_main.pas b/src/editor/f_main.pas
index 7282c785c430a7a5342aa2f6e52a2821e14413d1..ca14ebe46ef777a30433bdacd9c2f93eaf09b5fb 100644 (file)
--- a/src/editor/f_main.pas
+++ b/src/editor/f_main.pas
f_options, e_graphics, e_log, GL, Math,
f_mapoptions, g_basic, f_about, f_mapoptimization,
f_mapcheck, f_addresource_texture, g_textures,
- f_activationtype, f_keys,
+ f_activationtype, f_keys, wadreader,
MAPREADER, f_selectmap, f_savemap, WADEDITOR, MAPDEF,
g_map, f_saveminimap, f_addresource, CONFIG, f_packmap,
f_addresource_sound, f_maptest, f_choosetype,
procedure TMainForm.aRecentFileExecute(Sender: TObject);
var
- n, pw: Integer;
- s, fn: String;
- b: Boolean;
+ n: Integer;
+ fn, s: String;
begin
s := LowerCase((Sender as TMenuItem).Caption);
Delete(s, Pos('&', s), 1);
s := Trim(Copy(s, 1, 2));
n := StrToIntDef(s, 0) - 1;
-
- if (n < 0) or (n >= RecentFiles.Count) then
- Exit;
-
- s := RecentFiles[n];
- pw := Pos('.wad:\', LowerCase(s));
- b := False;
-
- if pw > 0 then
- begin // Map name included
- fn := Copy(s, 1, pw + 3);
- Delete(s, 1, pw + 5);
- if (FileExists(fn)) then
- begin
- OpenMap(fn, s);
- b := True;
- end;
+ if (n >= 0) and (n <= RecentFiles.Count) then
+ begin
+ fn := g_ExtractWadName(RecentFiles[n]);
+ if FileExists(fn) then
+ begin
+ s := g_ExtractFilePathName(RecentFiles[n]);
+ OpenMap(fn, s)
end
- else // Only wad name
- if (FileExists(s)) then
+ else if MessageBox(0, PChar(_lc[I_MSG_DEL_RECENT_PROMT]), PChar(_lc[I_MSG_DEL_RECENT]), MB_ICONQUESTION or MB_YESNO) = idYes then
begin
- OpenMap(s, '');
- b := True;
- end;
-
- if (not b) and (MessageBox(0, PChar(_lc[I_MSG_DEL_RECENT_PROMT]),
- PChar(_lc[I_MSG_DEL_RECENT]), MB_ICONQUESTION or MB_YESNO) = idYes) then
- begin
- RecentFiles.Delete(n);
- RefreshRecentMenu();
- end;
+ RecentFiles.Delete(n);
+ RefreshRecentMenu();
+ end
+ end
end;
procedure TMainForm.aEditorOptionsExecute(Sender: TObject);
diff --git a/src/shared/wadreader.pas b/src/shared/wadreader.pas
--- /dev/null
+++ b/src/shared/wadreader.pas
@@ -0,0 +1,136 @@
+(* Copyright (C) Doom 2D: Forever Developers
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License ONLY.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *)
+{$INCLUDE a_modes.inc}
+unit wadreader;
+
+interface
+
+// g_ExtractWadName C:\svr\shit.wad:\MAPS\MAP01 -> C:/svr/shit.wad
+function g_ExtractWadName (resourceStr: AnsiString): AnsiString;
+
+// g_ExtractWadNameNoPath C:\svr\shit.wad:\MAPS\MAP01 -> shit.wad
+function g_ExtractWadNameNoPath (resourceStr: AnsiString): AnsiString;
+
+// g_ExtractFilePath C:\svr\shit.wad:\MAPS\MAP01 -> :/MAPS
+function g_ExtractFilePath (resourceStr: AnsiString): AnsiString;
+
+// g_ExtractFileName C:\svr\shit.wad:\MAPS\MAP01 -> MAP01
+function g_ExtractFileName (resourceStr: AnsiString): AnsiString; // without path
+
+// g_ExtractFilePathName C:\svr\shit.wad:\MAPS\MAP01 -> MAPS/MAP01
+function g_ExtractFilePathName (resourceStr: AnsiString): AnsiString;
+
+implementation
+
+function normSlashes (s: AnsiString): AnsiString;
+var
+ f: Integer;
+begin
+ for f := 1 to length(s) do if s[f] = '\' then s[f] := '/';
+ result := s;
+end;
+
+function g_ExtractWadNameNoPath (resourceStr: AnsiString): AnsiString;
+var
+ f, c: Integer;
+begin
+ for f := length(resourceStr) downto 1 do
+ begin
+ if resourceStr[f] = ':' then
+ begin
+ result := normSlashes(Copy(resourceStr, 1, f-1));
+ c := length(result);
+ while (c > 0) and (result[c] <> '/') do Dec(c);
+ if c > 0 then result := Copy(result, c+1, length(result));
+ exit;
+ end;
+ end;
+ result := '';
+end;
+
+function g_ExtractWadName (resourceStr: AnsiString): AnsiString;
+var
+ f: Integer;
+begin
+ for f := length(resourceStr) downto 1 do
+ begin
+ if resourceStr[f] = ':' then
+ begin
+ result := normSlashes(Copy(resourceStr, 1, f-1));
+ exit;
+ end;
+ end;
+ result := '';
+end;
+
+function g_ExtractFilePath (resourceStr: AnsiString): AnsiString;
+var
+ f, lastSlash: Integer;
+begin
+ result := '';
+ lastSlash := -1;
+ for f := length(resourceStr) downto 1 do
+ begin
+ if (lastSlash < 0) and (resourceStr[f] = '\') or (resourceStr[f] = '/') then lastSlash := f;
+ if resourceStr[f] = ':' then
+ begin
+ if lastSlash > 0 then
+ begin
+ result := normSlashes(Copy(resourceStr, f, lastSlash-f));
+ while (length(result) > 0) and (result[1] = '/') do Delete(result, 1, 1);
+ end;
+ exit;
+ end;
+ end;
+ if lastSlash > 0 then result := normSlashes(Copy(resourceStr, 1, lastSlash-1));
+end;
+
+function g_ExtractFileName (resourceStr: AnsiString): AnsiString; // without path
+var
+ f, lastSlash: Integer;
+begin
+ result := '';
+ lastSlash := -1;
+ for f := length(resourceStr) downto 1 do
+ begin
+ if (lastSlash < 0) and (resourceStr[f] = '\') or (resourceStr[f] = '/') then lastSlash := f;
+ if resourceStr[f] = ':' then
+ begin
+ if lastSlash > 0 then result := Copy(resourceStr, lastSlash+1, length(resourceStr));
+ exit;
+ end;
+ end;
+ if lastSlash > 0 then result := Copy(resourceStr, lastSlash+1, length(resourceStr));
+end;
+
+function g_ExtractFilePathName (resourceStr: AnsiString): AnsiString;
+var
+ f: Integer;
+begin
+ result := '';
+ for f := length(resourceStr) downto 1 do
+ begin
+ if resourceStr[f] = ':' then
+ begin
+ result := normSlashes(Copy(resourceStr, f+1, length(resourceStr)));
+ while (length(result) > 0) and (result[1] = '/') do Delete(result, 1, 1);
+ exit;
+ end;
+ end;
+ result := normSlashes(resourceStr);
+ while (length(result) > 0) and (result[1] = '/') do Delete(result, 1, 1);
+end;
+
+end.