move redir handling

This commit is contained in:
Glenn Maynard
2003-01-01 22:02:41 +00:00
parent 83062aee55
commit d848550137
3 changed files with 34 additions and 18 deletions
+22
View File
@@ -19,6 +19,7 @@ unsigned long randseed = time(NULL);
#include <math.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fstream>
int power_of_two(int input)
{
@@ -746,3 +747,24 @@ void TrimRight(CString &str, const char *s)
* if n == 0, the whole string is erased. */
str.erase(str.begin()+n, str.end());
}
/* path is a .redir pathname. Read it and return the real one. */
CString DerefRedir(const CString &path)
{
CString sDir, sFName, sExt;
splitrelpath( path, sDir, sFName, sExt );
if(sExt != "redir") return path;
CString sNewFileName;
{
ifstream file(path);
getline(file, sNewFileName);
}
/* Empty is invalid. */
if(sNewFileName == "")
return "";
return sDir+sNewFileName;
}
+2
View File
@@ -189,6 +189,8 @@ float calc_stddev(const float *start, const float *end);
void TrimLeft(CString &str, const char *s = "\r\n\t ");
void TrimRight(CString &str, const char *s = "\r\n\t ");
CString DerefRedir(const CString &path);
#ifndef WIN32
#include <unistd.h> /* correct place with correct definitions */
#endif
+10 -18
View File
@@ -20,7 +20,6 @@
#include "IniFile.h"
#include "RageTimer.h"
#include <fstream>
using namespace std;
ThemeManager* THEME = NULL; // global object accessable from anywhere in the program
@@ -131,14 +130,14 @@ try_element_again:
// look for a redirect
GetDirListing( sCurrentThemeDir + sAssetCategory+"\\"+sFileName + "*.redir", asPossibleElementFilePaths, false, true );
if( !asPossibleElementFilePaths.empty() )
/* if( !asPossibleElementFilePaths.empty() )
{
ifstream file(asPossibleElementFilePaths[0]);
CString sLine;
getline(file, sLine);
}
*/
///////////////////////////////////////
// Search both the current theme and the default theme dirs for this element
///////////////////////////////////////
@@ -197,27 +196,20 @@ try_element_again:
asPossibleElementFilePaths[0].MakeLower();
if( asPossibleElementFilePaths[0].GetLength() > 5 && asPossibleElementFilePaths[0].Right(5) == "redir" ) // this is a redirect file
{
CString sRedirFilePath = asPossibleElementFilePaths[0];
CString sNewFilePath = DerefRedir(asPossibleElementFilePaths[0]);
CString sDir, sFName, sExt;
splitrelpath( sRedirFilePath, sDir, sFName, sExt );
CString sNewFileName;
if( sNewFilePath == "" || !DoesFileExist(sNewFilePath) )
{
ifstream file(sRedirFilePath);
getline(file, sNewFileName );
// CString sNewFilePath = sDir+"\\"+sNewFileName; // This is what it used to be, FONT redirs were getting extra slashes
// at the start of their file names, so I took out this extra slash - Andy.
}
CString message = ssprintf(
"The redirect '%s' points to the file '%s', which does not exist."
"Verify that this redirect is correct.",
asPossibleElementFilePaths[0].GetString(), sNewFilePath.GetString());
CString sNewFilePath = sDir+sNewFileName;
if( sNewFileName == "" || !DoesFileExist(sNewFilePath) )
{
#ifdef _DEBUG
if( IDRETRY == MessageBox(NULL,"ThemeManager",ssprintf("The redirect '%s' points to the file '%s', which does not exist. Verify that this redirect is correct.", sRedirFilePath.GetString(), sNewFilePath.GetString()), MB_RETRYCANCEL ) )
if( MessageBox(NULL, "ThemeManager", message.GetString(), MB_RETRYCANCEL ) == IDRETRY)
goto try_element_again;
#endif
RageException::Throw( "The redirect '%s' points to the file '%s', which does not exist. Verify that this redirect is correct.", sRedirFilePath.GetString(), sNewFilePath.GetString() );
RageException::Throw( "%s", message.GetString() );
}
else
return sNewFilePath;