From 9daf02c3d62e1e81e01e4823f9996db5815a1f4f Mon Sep 17 00:00:00 2001 From: tobigun Date: Thu, 23 Jul 2009 15:18:19 +0000 Subject: UPath renamed to UPathUtils git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@1873 b956fd51-792f-4845-bead-9b4dfca2ff2c --- unicode/src/base/TextGL.pas | 2 +- unicode/src/base/UCatCovers.pas | 2 +- unicode/src/base/UDLLManager.pas | 2 +- unicode/src/base/UGraphic.pas | 2 +- unicode/src/base/UIni.pas | 2 +- unicode/src/base/ULanguage.pas | 2 +- unicode/src/base/ULog.pas | 2 +- unicode/src/base/UMain.pas | 2 +- unicode/src/base/UMusic.pas | 2 +- unicode/src/base/UNote.pas | 2 +- unicode/src/base/UPath.pas | 188 --------------------------- unicode/src/base/UPathUtils.pas | 188 +++++++++++++++++++++++++++ unicode/src/base/UPlaylist.pas | 2 +- unicode/src/base/USkins.pas | 2 +- unicode/src/base/USong.pas | 2 +- unicode/src/base/USongs.pas | 2 +- unicode/src/menu/UDisplay.pas | 2 +- unicode/src/screens/UScreenCredits.pas | 2 +- unicode/src/screens/UScreenEditConvert.pas | 2 +- unicode/src/screens/UScreenOptionsThemes.pas | 2 +- unicode/src/screens/UScreenSingModi.pas | 2 +- unicode/src/ultrastardx.dpr | 2 +- 22 files changed, 208 insertions(+), 208 deletions(-) delete mode 100644 unicode/src/base/UPath.pas create mode 100644 unicode/src/base/UPathUtils.pas (limited to 'unicode/src') diff --git a/unicode/src/base/TextGL.pas b/unicode/src/base/TextGL.pas index 667a224f..65d716c2 100644 --- a/unicode/src/base/TextGL.pas +++ b/unicode/src/base/TextGL.pas @@ -73,7 +73,7 @@ uses IniFiles, UCommon, UMain, - UPath; + UPathUtils; function FindFontFile(FontIni: TCustomIniFile; Font: string): string; var diff --git a/unicode/src/base/UCatCovers.pas b/unicode/src/base/UCatCovers.pas index 6ef81b68..86f675c5 100644 --- a/unicode/src/base/UCatCovers.pas +++ b/unicode/src/base/UCatCovers.pas @@ -66,7 +66,7 @@ uses // UFiles, ULog, UMain, - UPath; + UPathUtils; constructor TCatCovers.Create; begin diff --git a/unicode/src/base/UDLLManager.pas b/unicode/src/base/UDLLManager.pas index 3faa15bf..dd05d733 100644 --- a/unicode/src/base/UDLLManager.pas +++ b/unicode/src/base/UDLLManager.pas @@ -92,7 +92,7 @@ uses {$ELSE} dynlibs, {$ENDIF} - UPath, + UPathUtils, ULog, SysUtils; diff --git a/unicode/src/base/UGraphic.pas b/unicode/src/base/UGraphic.pas index 818e49aa..7c5b18fd 100644 --- a/unicode/src/base/UGraphic.pas +++ b/unicode/src/base/UGraphic.pas @@ -281,7 +281,7 @@ uses UIni, UDisplay, UCommandLine, - UPath; + UPathUtils; procedure LoadFontTextures; begin diff --git a/unicode/src/base/UIni.pas b/unicode/src/base/UIni.pas index 03654db7..bf068f11 100644 --- a/unicode/src/base/UIni.pas +++ b/unicode/src/base/UIni.pas @@ -264,7 +264,7 @@ uses USkins, URecord, UCommandLine, - UPath, + UPathUtils, UUnicodeUtils; (** diff --git a/unicode/src/base/ULanguage.pas b/unicode/src/base/ULanguage.pas index f79f4165..9571358e 100644 --- a/unicode/src/base/ULanguage.pas +++ b/unicode/src/base/ULanguage.pas @@ -79,7 +79,7 @@ uses Classes, SysUtils, ULog, - UPath; + UPathUtils; {** * LoadList, set default language, set standard implode glues diff --git a/unicode/src/base/ULog.pas b/unicode/src/base/ULog.pas index a872729a..6f7aa644 100644 --- a/unicode/src/base/ULog.pas +++ b/unicode/src/base/ULog.pas @@ -133,7 +133,7 @@ uses UTime, UCommon, UCommandLine, - UPath; + UPathUtils; (* * Write to console if in debug mode (Thread-safe). diff --git a/unicode/src/base/UMain.pas b/unicode/src/base/UMain.pas index 0c3410d1..5b07c9ae 100644 --- a/unicode/src/base/UMain.pas +++ b/unicode/src/base/UMain.pas @@ -80,7 +80,7 @@ uses UJoystick, ULanguage, ULog, - UPath, + UPathUtils, UPlaylist, UMusic, UBeatTimer, diff --git a/unicode/src/base/UMusic.pas b/unicode/src/base/UMusic.pas index 5fc9805f..b959ea05 100644 --- a/unicode/src/base/UMusic.pas +++ b/unicode/src/base/UMusic.pas @@ -533,7 +533,7 @@ uses UCommandLine, URecord, ULog, - UPath; + UPathUtils; var DefaultVideoPlayback : IVideoPlayback; diff --git a/unicode/src/base/UNote.pas b/unicode/src/base/UNote.pas index 6da4cf07..93d8d607 100644 --- a/unicode/src/base/UNote.pas +++ b/unicode/src/base/UNote.pas @@ -129,7 +129,7 @@ uses UCommon, UGraphic, UGraphicClasses, - UPath, + UPathUtils, UPlatform, UThemes; diff --git a/unicode/src/base/UPath.pas b/unicode/src/base/UPath.pas deleted file mode 100644 index 2316ac02..00000000 --- a/unicode/src/base/UPath.pas +++ /dev/null @@ -1,188 +0,0 @@ -{* UltraStar Deluxe - Karaoke Game - * - * UltraStar Deluxe is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * 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; either version 2 - * of the License, or (at your option) any later version. - * - * 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; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * $URL: https://ultrastardx.svn.sourceforge.net/svnroot/ultrastardx/trunk/src/base/UPath.pas $ - * $Id: UPath.pas 1624 2009-03-06 23:45:10Z k-m_schindler $ - *} - -unit UPath; - -interface - -{$IFDEF FPC} - {$MODE Delphi} -{$ENDIF} - -{$I switches.inc} - -uses - SysUtils, - Classes; - -var - // Absolute Paths - GamePath: string; - SoundPath: string; - SongPaths: TStringList; - LogPath: string; - ThemePath: string; - SkinsPath: string; - ScreenshotsPath: string; - CoverPaths: TStringList; - LanguagesPath: string; - PluginPath: string; - VisualsPath: string; - FontPath: string; - ResourcesPath: string; - PlayListPath: string; - -function FindPath(out PathResult: string; const RequestedPath: string; NeedsWritePermission: boolean): boolean; -procedure InitializePaths; -procedure AddSongPath(const Path: string); - -implementation - -uses - StrUtils, - UPlatform, - UCommandLine, - ULog; - -procedure AddSpecialPath(var PathList: TStringList; const Path: string); -var - Index: integer; - PathAbs, OldPathAbs: string; -begin - if (PathList = nil) then - PathList := TStringList.Create; - - if (Path = '') or not ForceDirectories(Path) then - Exit; - - PathAbs := IncludeTrailingPathDelimiter(ExpandFileName(Path)); - - // check if path or a part of the path was already added - for Index := 0 to PathList.Count-1 do - begin - OldPathAbs := IncludeTrailingPathDelimiter(ExpandFileName(PathList[Index])); - // check if the new directory is a sub-directory of a previously added one. - // This is also true, if both paths point to the same directories. - if (AnsiStartsText(OldPathAbs, PathAbs)) then - begin - // ignore the new path - Exit; - end; - - // check if a previously added directory is a sub-directory of the new one. - if (AnsiStartsText(PathAbs, OldPathAbs)) then - begin - // replace the old with the new one. - PathList[Index] := PathAbs; - Exit; - end; - end; - - PathList.Add(PathAbs); -end; - -procedure AddSongPath(const Path: string); -begin - AddSpecialPath(SongPaths, Path); -end; - -procedure AddCoverPath(const Path: string); -begin - AddSpecialPath(CoverPaths, Path); -end; - -(** - * Initialize a path variable - * After setting paths, make sure that paths exist - *) -function FindPath(out PathResult: string; - const RequestedPath: string; - NeedsWritePermission: boolean) - : boolean; -begin - Result := false; - - if (RequestedPath = '') then - Exit; - - // Make sure the directory exists - if (not ForceDirectories(RequestedPath)) then - begin - PathResult := ''; - Exit; - end; - - PathResult := IncludeTrailingPathDelimiter(RequestedPath); - - if (NeedsWritePermission) and - (FileIsReadOnly(RequestedPath)) then - begin - Exit; - end; - - Result := true; -end; - -(** - * Function sets all absolute paths e.g. song path and makes sure the directorys exist - *) -procedure InitializePaths; -begin - // Log directory (must be writable) - if (not FindPath(LogPath, Platform.GetLogPath, true)) then - begin - Log.FileOutputEnabled := false; - Log.LogWarn('Log directory "'+ Platform.GetLogPath +'" not available', 'InitializePaths'); - end; - - FindPath(SoundPath, Platform.GetGameSharedPath + 'sounds', false); - FindPath(ThemePath, Platform.GetGameSharedPath + 'themes', false); - FindPath(SkinsPath, Platform.GetGameSharedPath + 'themes', false); - FindPath(LanguagesPath, Platform.GetGameSharedPath + 'languages', false); - FindPath(PluginPath, Platform.GetGameSharedPath + 'plugins', false); - FindPath(VisualsPath, Platform.GetGameSharedPath + 'visuals', false); - FindPath(FontPath, Platform.GetGameSharedPath + 'fonts', false); - FindPath(ResourcesPath, Platform.GetGameSharedPath + 'resources', false); - - // Playlists are not shared as we need one directory to write too - FindPath(PlaylistPath, Platform.GetGameUserPath + 'playlists', true); - - // Screenshot directory (must be writable) - if (not FindPath(ScreenshotsPath, Platform.GetGameUserPath + 'screenshots', true)) then - begin - Log.LogWarn('Screenshot directory "'+ Platform.GetGameUserPath +'" not available', 'InitializePaths'); - end; - - // Add song paths - AddSongPath(Params.SongPath); - AddSongPath(Platform.GetGameSharedPath + 'songs'); - AddSongPath(Platform.GetGameUserPath + 'songs'); - - // Add category cover paths - AddCoverPath(Platform.GetGameSharedPath + 'covers'); - AddCoverPath(Platform.GetGameUserPath + 'covers'); -end; - -end. diff --git a/unicode/src/base/UPathUtils.pas b/unicode/src/base/UPathUtils.pas new file mode 100644 index 00000000..4c4d3bc0 --- /dev/null +++ b/unicode/src/base/UPathUtils.pas @@ -0,0 +1,188 @@ +{* UltraStar Deluxe - Karaoke Game + * + * UltraStar Deluxe is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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; either version 2 + * of the License, or (at your option) any later version. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + *} + +unit UPathUtils; + +interface + +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + +{$I switches.inc} + +uses + SysUtils, + Classes; + +var + // Absolute Paths + GamePath: string; + SoundPath: string; + SongPaths: TStringList; + LogPath: string; + ThemePath: string; + SkinsPath: string; + ScreenshotsPath: string; + CoverPaths: TStringList; + LanguagesPath: string; + PluginPath: string; + VisualsPath: string; + FontPath: string; + ResourcesPath: string; + PlayListPath: string; + +function FindPath(out PathResult: string; const RequestedPath: string; NeedsWritePermission: boolean): boolean; +procedure InitializePaths; +procedure AddSongPath(const Path: string); + +implementation + +uses + StrUtils, + UPlatform, + UCommandLine, + ULog; + +procedure AddSpecialPath(var PathList: TStringList; const Path: string); +var + Index: integer; + PathAbs, OldPathAbs: string; +begin + if (PathList = nil) then + PathList := TStringList.Create; + + if (Path = '') or not ForceDirectories(Path) then + Exit; + + PathAbs := IncludeTrailingPathDelimiter(ExpandFileName(Path)); + + // check if path or a part of the path was already added + for Index := 0 to PathList.Count-1 do + begin + OldPathAbs := IncludeTrailingPathDelimiter(ExpandFileName(PathList[Index])); + // check if the new directory is a sub-directory of a previously added one. + // This is also true, if both paths point to the same directories. + if (AnsiStartsText(OldPathAbs, PathAbs)) then + begin + // ignore the new path + Exit; + end; + + // check if a previously added directory is a sub-directory of the new one. + if (AnsiStartsText(PathAbs, OldPathAbs)) then + begin + // replace the old with the new one. + PathList[Index] := PathAbs; + Exit; + end; + end; + + PathList.Add(PathAbs); +end; + +procedure AddSongPath(const Path: string); +begin + AddSpecialPath(SongPaths, Path); +end; + +procedure AddCoverPath(const Path: string); +begin + AddSpecialPath(CoverPaths, Path); +end; + +(** + * Initialize a path variable + * After setting paths, make sure that paths exist + *) +function FindPath(out PathResult: string; + const RequestedPath: string; + NeedsWritePermission: boolean) + : boolean; +begin + Result := false; + + if (RequestedPath = '') then + Exit; + + // Make sure the directory exists + if (not ForceDirectories(RequestedPath)) then + begin + PathResult := ''; + Exit; + end; + + PathResult := IncludeTrailingPathDelimiter(RequestedPath); + + if (NeedsWritePermission) and + (FileIsReadOnly(RequestedPath)) then + begin + Exit; + end; + + Result := true; +end; + +(** + * Function sets all absolute paths e.g. song path and makes sure the directorys exist + *) +procedure InitializePaths; +begin + // Log directory (must be writable) + if (not FindPath(LogPath, Platform.GetLogPath, true)) then + begin + Log.FileOutputEnabled := false; + Log.LogWarn('Log directory "'+ Platform.GetLogPath +'" not available', 'InitializePaths'); + end; + + FindPath(SoundPath, Platform.GetGameSharedPath + 'sounds', false); + FindPath(ThemePath, Platform.GetGameSharedPath + 'themes', false); + FindPath(SkinsPath, Platform.GetGameSharedPath + 'themes', false); + FindPath(LanguagesPath, Platform.GetGameSharedPath + 'languages', false); + FindPath(PluginPath, Platform.GetGameSharedPath + 'plugins', false); + FindPath(VisualsPath, Platform.GetGameSharedPath + 'visuals', false); + FindPath(FontPath, Platform.GetGameSharedPath + 'fonts', false); + FindPath(ResourcesPath, Platform.GetGameSharedPath + 'resources', false); + + // Playlists are not shared as we need one directory to write too + FindPath(PlaylistPath, Platform.GetGameUserPath + 'playlists', true); + + // Screenshot directory (must be writable) + if (not FindPath(ScreenshotsPath, Platform.GetGameUserPath + 'screenshots', true)) then + begin + Log.LogWarn('Screenshot directory "'+ Platform.GetGameUserPath +'" not available', 'InitializePaths'); + end; + + // Add song paths + AddSongPath(Params.SongPath); + AddSongPath(Platform.GetGameSharedPath + 'songs'); + AddSongPath(Platform.GetGameUserPath + 'songs'); + + // Add category cover paths + AddCoverPath(Platform.GetGameSharedPath + 'covers'); + AddCoverPath(Platform.GetGameUserPath + 'covers'); +end; + +end. diff --git a/unicode/src/base/UPlaylist.pas b/unicode/src/base/UPlaylist.pas index 744f4ce8..cc983a9e 100644 --- a/unicode/src/base/UPlaylist.pas +++ b/unicode/src/base/UPlaylist.pas @@ -35,7 +35,7 @@ interface uses USong, - UPath; + UPathUtils; type TPlaylistItem = record diff --git a/unicode/src/base/USkins.pas b/unicode/src/base/USkins.pas index a4722d95..a19b7546 100644 --- a/unicode/src/base/USkins.pas +++ b/unicode/src/base/USkins.pas @@ -74,7 +74,7 @@ uses UIni, ULog, UMain, - UPath; + UPathUtils; constructor TSkin.Create; begin diff --git a/unicode/src/base/USong.pas b/unicode/src/base/USong.pas index eedc6258..86349359 100644 --- a/unicode/src/base/USong.pas +++ b/unicode/src/base/USong.pas @@ -154,7 +154,7 @@ uses StrUtils, TextGL, UIni, - UPath, + UPathUtils, UMusic, //needed for Lines UNote; //needed for Player diff --git a/unicode/src/base/USongs.pas b/unicode/src/base/USongs.pas index 7a996262..2b2bcf49 100644 --- a/unicode/src/base/USongs.pas +++ b/unicode/src/base/USongs.pas @@ -163,7 +163,7 @@ uses UGraphic, UMain, UIni, - UPath, + UPathUtils, UNote, UUnicodeUtils; diff --git a/unicode/src/menu/UDisplay.pas b/unicode/src/menu/UDisplay.pas index f2eb2ced..a4d16500 100644 --- a/unicode/src/menu/UDisplay.pas +++ b/unicode/src/menu/UDisplay.pas @@ -123,7 +123,7 @@ uses UMain, UTexture, UTime, - UPath; + UPathUtils; constructor TDisplay.Create; var diff --git a/unicode/src/screens/UScreenCredits.pas b/unicode/src/screens/UScreenCredits.pas index cff83d70..af1eea53 100644 --- a/unicode/src/screens/UScreenCredits.pas +++ b/unicode/src/screens/UScreenCredits.pas @@ -176,7 +176,7 @@ uses Textgl, ULanguage, UCommon, - UPath; + UPathUtils; function TScreenCredits.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin diff --git a/unicode/src/screens/UScreenEditConvert.pas b/unicode/src/screens/UScreenEditConvert.pas index 8c7f5fa7..5dfa3b43 100644 --- a/unicode/src/screens/UScreenEditConvert.pas +++ b/unicode/src/screens/UScreenEditConvert.pas @@ -141,7 +141,7 @@ uses UGraphic, UIni, UMain, - UPath, + UPathUtils, USkins, UTextEncoding, UUnicodeUtils; diff --git a/unicode/src/screens/UScreenOptionsThemes.pas b/unicode/src/screens/UScreenOptionsThemes.pas index 9025582c..163d8af9 100644 --- a/unicode/src/screens/UScreenOptionsThemes.pas +++ b/unicode/src/screens/UScreenOptionsThemes.pas @@ -61,7 +61,7 @@ uses SysUtils, UGraphic, UMain, - UPath, + UPathUtils, UUnicodeUtils, USkins; diff --git a/unicode/src/screens/UScreenSingModi.pas b/unicode/src/screens/UScreenSingModi.pas index 3ae5b7dc..d361943e 100644 --- a/unicode/src/screens/UScreenSingModi.pas +++ b/unicode/src/screens/UScreenSingModi.pas @@ -108,7 +108,7 @@ uses UGraphicClasses, ULanguage, UNote, - UPath, + UPathUtils, URecord, USkins; diff --git a/unicode/src/ultrastardx.dpr b/unicode/src/ultrastardx.dpr index f6376365..ea701a37 100644 --- a/unicode/src/ultrastardx.dpr +++ b/unicode/src/ultrastardx.dpr @@ -201,7 +201,7 @@ uses URingBuffer in 'base\URingBuffer.pas', USingScores in 'base\USingScores.pas', USingNotes in 'base\USingNotes.pas', - UPath in 'base\UPath.pas', + UPathUtils in 'base\UPathUtils.pas', UNote in 'base\UNote.pas', UBeatTimer in 'base\UBeatTimer.pas', -- cgit v1.2.3