diff options
author | k-m_schindler <k-m_schindler@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2009-03-07 01:06:07 +0000 |
---|---|---|
committer | k-m_schindler <k-m_schindler@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2009-03-07 01:06:07 +0000 |
commit | 458111738476004a914af6fd3e117eb84a35ab6a (patch) | |
tree | f77d289e66e92fee83e2419c9978b40fb9c2b69b /src | |
parent | 9be9439fce30028c619a401523793ec101dccaed (diff) | |
download | usdx-458111738476004a914af6fd3e117eb84a35ab6a.tar.gz usdx-458111738476004a914af6fd3e117eb84a35ab6a.tar.xz usdx-458111738476004a914af6fd3e117eb84a35ab6a.zip |
unclutter UMain.pas. Create UPath.pas. Tests on all platformssvn statussvn status
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1625 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'src')
-rw-r--r-- | src/base/TextGL.pas | 9 | ||||
-rw-r--r-- | src/base/UCatCovers.pas | 3 | ||||
-rw-r--r-- | src/base/UGraphic.pas | 10 | ||||
-rw-r--r-- | src/base/UIni.pas | 3 | ||||
-rw-r--r-- | src/base/ULanguage.pas | 5 | ||||
-rw-r--r-- | src/base/ULog.pas | 3 | ||||
-rw-r--r-- | src/base/UMain.pas | 136 | ||||
-rw-r--r-- | src/base/UMusic.pas | 3 | ||||
-rw-r--r-- | src/base/UPath.pas | 188 | ||||
-rw-r--r-- | src/base/UPlaylist.pas | 3 | ||||
-rw-r--r-- | src/base/UPluginLoader.pas | 3 | ||||
-rw-r--r-- | src/base/USkins.pas | 5 | ||||
-rw-r--r-- | src/base/USongs.pas | 14 | ||||
-rw-r--r-- | src/menu/UDisplay.pas | 11 | ||||
-rw-r--r-- | src/screens/UScreenCredits.pas | 22 | ||||
-rw-r--r-- | src/screens/UScreenEditConvert.pas | 9 | ||||
-rw-r--r-- | src/screens/UScreenOptionsThemes.pas | 10 | ||||
-rw-r--r-- | src/screens/UScreenSingModi.pas | 14 | ||||
-rw-r--r-- | src/ultrastardx.dpr | 1 |
19 files changed, 267 insertions, 185 deletions
diff --git a/src/base/TextGL.pas b/src/base/TextGL.pas index bd505f51..c8de4e28 100644 --- a/src/base/TextGL.pas +++ b/src/base/TextGL.pas @@ -96,12 +96,13 @@ var implementation uses - UMain, - UCommon, + Classes, SysUtils, IniFiles, - Classes, - UGraphic; + UCommon, + UGraphic, + UMain, + UPath; var // Colours for the reflection diff --git a/src/base/UCatCovers.pas b/src/base/UCatCovers.pas index 4fc54199..6ef81b68 100644 --- a/src/base/UCatCovers.pas +++ b/src/base/UCatCovers.pas @@ -64,8 +64,9 @@ uses SysUtils, Classes, // UFiles, + ULog, UMain, - ULog; + UPath; constructor TCatCovers.Create; begin diff --git a/src/base/UGraphic.pas b/src/base/UGraphic.pas index c328d016..17175d02 100644 --- a/src/base/UGraphic.pas +++ b/src/base/UGraphic.pas @@ -280,11 +280,12 @@ function LoadingThreadFunction: integer; implementation uses + Classes, UMain, UIni, UDisplay, UCommandLine, - Classes; + UPath; procedure LoadFontTextures; begin @@ -294,11 +295,10 @@ end; procedure LoadTextures; - var - P: integer; - R, G, B: real; - Col: integer; + P: integer; + R, G, B: real; + Col: integer; begin Log.LogStatus('Loading Textures', 'LoadTextures'); diff --git a/src/base/UIni.pas b/src/base/UIni.pas index a1fa7ac9..78229f53 100644 --- a/src/base/UIni.pas +++ b/src/base/UIni.pas @@ -261,7 +261,8 @@ uses UPlatform, USkins, URecord, - UCommandLine; + UCommandLine, + UPath; (** * Returns the filename without its fileextension diff --git a/src/base/ULanguage.pas b/src/base/ULanguage.pas index 31840f5f..02cd7712 100644 --- a/src/base/ULanguage.pas +++ b/src/base/ULanguage.pas @@ -75,9 +75,10 @@ uses Classes, SysUtils, {$IFDEF win32} - windows, + Windows, {$ENDIF} - ULog; + ULog, + UPath; //---------- //Create - Construct Class then LoadList + Standard Language + Set Standard Implode Glues diff --git a/src/base/ULog.pas b/src/base/ULog.pas index 582120bc..a872729a 100644 --- a/src/base/ULog.pas +++ b/src/base/ULog.pas @@ -132,7 +132,8 @@ uses UMain, UTime, UCommon, - UCommandLine; + UCommandLine, + UPath; (* * Write to console if in debug mode (Thread-safe). diff --git a/src/base/UMain.pas b/src/base/UMain.pas index 7e935c70..bc1cc7cc 100644 --- a/src/base/UMain.pas +++ b/src/base/UMain.pas @@ -89,21 +89,6 @@ type end; 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; Done: boolean; // FIXME: ConversionFileName should not be global @@ -120,10 +105,6 @@ const MAX_SONG_SCORE = 10000; // max. achievable points per song MAX_SONG_LINE_BONUS = 1000; // max. achievable line bonus per song -function FindPath(out PathResult: string; const RequestedPath: string; NeedsWritePermission: boolean): boolean; -procedure InitializePaths; -procedure AddSongPath(const Path: string); - procedure Main; procedure MainLoop; procedure CheckEvents; @@ -173,6 +154,7 @@ uses UCommon, UGraphic, UGraphicClasses, + UPath, UPluginDefs, UPlatform, UThemes; @@ -1052,120 +1034,4 @@ begin end; -procedure AddSpecialPath(var PathList: TStringList; const Path: string); -var - I: 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 I := 0 to PathList.Count-1 do - begin - OldPathAbs := IncludeTrailingPathDelimiter(ExpandFileName(PathList[I])); - // 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[I] := 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/src/base/UMusic.pas b/src/base/UMusic.pas index eee271a8..727088c8 100644 --- a/src/base/UMusic.pas +++ b/src/base/UMusic.pas @@ -576,7 +576,8 @@ uses UMain, UCommandLine, URecord, - ULog; + ULog, + UPath; var DefaultVideoPlayback : IVideoPlayback; diff --git a/src/base/UPath.pas b/src/base/UPath.pas new file mode 100644 index 00000000..2316ac02 --- /dev/null +++ b/src/base/UPath.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: 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/src/base/UPlaylist.pas b/src/base/UPlaylist.pas index 11ed84de..419ce687 100644 --- a/src/base/UPlaylist.pas +++ b/src/base/UPlaylist.pas @@ -34,7 +34,8 @@ interface {$I switches.inc} uses - USong; + USong, + UPath; type TPlaylistItem = record diff --git a/src/base/UPluginLoader.pas b/src/base/UPluginLoader.pas index bb8a9aa5..8836cb78 100644 --- a/src/base/UPluginLoader.pas +++ b/src/base/UPluginLoader.pas @@ -41,7 +41,8 @@ interface uses UPluginDefs, - UCoreModule; + UCoreModule, + UPath; type TPluginListItem = record diff --git a/src/base/USkins.pas b/src/base/USkins.pas index 30d7cbcf..a4722d95 100644 --- a/src/base/USkins.pas +++ b/src/base/USkins.pas @@ -71,9 +71,10 @@ uses IniFiles, Classes, SysUtils, - UMain, + UIni, ULog, - UIni; + UMain, + UPath; constructor TSkin.Create; begin diff --git a/src/base/USongs.pas b/src/base/USongs.pas index 4d702163..79e1eb59 100644 --- a/src/base/USongs.pas +++ b/src/base/USongs.pas @@ -151,12 +151,14 @@ const implementation -uses StrUtils, - UGraphic, - UCovers, - UFiles, - UMain, - UIni; +uses + StrUtils, + UCovers, + UFiles, + UGraphic, + UIni, + UPath, + UMain; constructor TSongs.Create(); begin diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index f4cca4a5..3e653183 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -34,7 +34,7 @@ interface {$I switches.inc} uses - ucommon, + UCommon, SDL, UMenu, gl, @@ -86,15 +86,16 @@ var implementation uses - UImage, TextGL, + UCommandLine, + UGraphic, + UIni, + UImage, ULog, UMain, UTexture, - UIni, - UGraphic, UTime, - UCommandLine; + UPath; constructor TDisplay.Create; var diff --git a/src/screens/UScreenCredits.pas b/src/screens/UScreenCredits.pas index 6d410a97..6e5c5ba7 100644 --- a/src/screens/UScreenCredits.pas +++ b/src/screens/UScreenCredits.pas @@ -34,6 +34,7 @@ interface {$I switches.inc} uses + SysUtils, UMenu, SDL, SDL_Image, @@ -42,7 +43,6 @@ uses gl, UMusic, UFiles, - SysUtils, UThemes, UGraphicClasses; @@ -167,16 +167,16 @@ const implementation uses - ULog, - UGraphic, - UMain, - UIni, - USongs, - Textgl, - ULanguage, - UCommon, - Math; - + Math, + ULog, + UGraphic, + UMain, + UIni, + USongs, + Textgl, + ULanguage, + UCommon, + UPath; function TScreenCredits.ParseInput(PressedKey: Cardinal; CharCode: WideChar; PressedDown: Boolean): Boolean; begin diff --git a/src/screens/UScreenEditConvert.pas b/src/screens/UScreenEditConvert.pas index 56afdefd..8ef43770 100644 --- a/src/screens/UScreenEditConvert.pas +++ b/src/screens/UScreenEditConvert.pas @@ -119,14 +119,15 @@ type implementation uses - UGraphic, SysUtils, - UDrawTexture, TextGL, + gl, + UDrawTexture, UFiles, - UMain, + UGraphic, UIni, - gl, + UMain, + UPath, USkins; function TScreenEditConvert.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; diff --git a/src/screens/UScreenOptionsThemes.pas b/src/screens/UScreenOptionsThemes.pas index ec6fe014..4970de21 100644 --- a/src/screens/UScreenOptionsThemes.pas +++ b/src/screens/UScreenOptionsThemes.pas @@ -57,10 +57,12 @@ type implementation -uses UMain, - UGraphic, - USkins, - SysUtils; +uses + SysUtils, + UGraphic, + UMain, + UPath, + USkins; function TScreenOptionsThemes.ParseInput(PressedKey: Cardinal; CharCode: WideChar; PressedDown: Boolean): Boolean; begin diff --git a/src/screens/UScreenSingModi.pas b/src/screens/UScreenSingModi.pas index 75c7195e..9c48104e 100644 --- a/src/screens/UScreenSingModi.pas +++ b/src/screens/UScreenSingModi.pas @@ -119,7 +119,19 @@ procedure PlaySound (const Index: Cardinal); stdcall; //Plays a Custom Sou function ToSentences(Const Lines: TLines): TSentences; implementation -uses UGraphic, UDraw, UMain, Classes, URecord, ULanguage, math, UDLLManager, USkins, UGraphicClasses; + +uses + Classes, + Math, + UDLLManager, + UDraw, + UGraphic, + UGraphicClasses, + ULanguage, + UMain, + UPath, + URecord, + USkins; // Method for input parsing. If False is returned, GetNextWindow // should be checked to know the next window to load; diff --git a/src/ultrastardx.dpr b/src/ultrastardx.dpr index e13bbc13..f4e06b0c 100644 --- a/src/ultrastardx.dpr +++ b/src/ultrastardx.dpr @@ -198,6 +198,7 @@ uses URingBuffer in 'base\URingBuffer.pas', USingScores in 'base\USingScores.pas', USingNotes in 'base\USingNotes.pas', + UPath in 'base\UPath.pas', //------------------------------ //Includes - Plugin Support |