move redir handling
This commit is contained in:
@@ -19,6 +19,7 @@ unsigned long randseed = time(NULL);
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
int power_of_two(int input)
|
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. */
|
* if n == 0, the whole string is erased. */
|
||||||
str.erase(str.begin()+n, str.end());
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -189,6 +189,8 @@ float calc_stddev(const float *start, const float *end);
|
|||||||
void TrimLeft(CString &str, const char *s = "\r\n\t ");
|
void TrimLeft(CString &str, const char *s = "\r\n\t ");
|
||||||
void TrimRight(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
|
#ifndef WIN32
|
||||||
#include <unistd.h> /* correct place with correct definitions */
|
#include <unistd.h> /* correct place with correct definitions */
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
#include "IniFile.h"
|
#include "IniFile.h"
|
||||||
#include "RageTimer.h"
|
#include "RageTimer.h"
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
ThemeManager* THEME = NULL; // global object accessable from anywhere in the program
|
ThemeManager* THEME = NULL; // global object accessable from anywhere in the program
|
||||||
@@ -131,14 +130,14 @@ try_element_again:
|
|||||||
|
|
||||||
// look for a redirect
|
// look for a redirect
|
||||||
GetDirListing( sCurrentThemeDir + sAssetCategory+"\\"+sFileName + "*.redir", asPossibleElementFilePaths, false, true );
|
GetDirListing( sCurrentThemeDir + sAssetCategory+"\\"+sFileName + "*.redir", asPossibleElementFilePaths, false, true );
|
||||||
if( !asPossibleElementFilePaths.empty() )
|
/* if( !asPossibleElementFilePaths.empty() )
|
||||||
{
|
{
|
||||||
ifstream file(asPossibleElementFilePaths[0]);
|
ifstream file(asPossibleElementFilePaths[0]);
|
||||||
CString sLine;
|
CString sLine;
|
||||||
getline(file, sLine);
|
getline(file, sLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
// Search both the current theme and the default theme dirs for this element
|
// Search both the current theme and the default theme dirs for this element
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
@@ -197,27 +196,20 @@ try_element_again:
|
|||||||
asPossibleElementFilePaths[0].MakeLower();
|
asPossibleElementFilePaths[0].MakeLower();
|
||||||
if( asPossibleElementFilePaths[0].GetLength() > 5 && asPossibleElementFilePaths[0].Right(5) == "redir" ) // this is a redirect file
|
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;
|
if( sNewFilePath == "" || !DoesFileExist(sNewFilePath) )
|
||||||
splitrelpath( sRedirFilePath, sDir, sFName, sExt );
|
|
||||||
|
|
||||||
CString sNewFileName;
|
|
||||||
{
|
{
|
||||||
ifstream file(sRedirFilePath);
|
CString message = ssprintf(
|
||||||
getline(file, sNewFileName );
|
"The redirect '%s' points to the file '%s', which does not exist."
|
||||||
// CString sNewFilePath = sDir+"\\"+sNewFileName; // This is what it used to be, FONT redirs were getting extra slashes
|
"Verify that this redirect is correct.",
|
||||||
// at the start of their file names, so I took out this extra slash - Andy.
|
asPossibleElementFilePaths[0].GetString(), sNewFilePath.GetString());
|
||||||
}
|
|
||||||
|
|
||||||
CString sNewFilePath = sDir+sNewFileName;
|
|
||||||
if( sNewFileName == "" || !DoesFileExist(sNewFilePath) )
|
|
||||||
{
|
|
||||||
#ifdef _DEBUG
|
#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;
|
goto try_element_again;
|
||||||
#endif
|
#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
|
else
|
||||||
return sNewFilePath;
|
return sNewFilePath;
|
||||||
|
|||||||
Reference in New Issue
Block a user