36 #include <sys/types.h>
39 #include <boost/regex.hpp>
76 stream.
readdata( colormixbuf,
sizeof ( *colormixbuf ));
78 for (
int i= 0; i < 8; i++ ) {
95 #ifdef use_truecolor2pal
96 stream.
readdata( &truecolor2pal_table,
sizeof ( truecolor2pal_table ));
97 stream.
readdata( &bi2asc_color_translation_table,
sizeof ( bi2asc_color_translation_table ));
103 (*xlatpictgraytable)[255] = 255;
116 static boost::regex exevar(
"\\$\\(?EXEPATH\\)?", boost::regex::icase);
117 path = boost::regex_replace( path, exevar, ConfigurationFileLocator::Instance().getExecutableLocation(), boost::regex_constants::format_literal );
119 static boost::regex appdata(
"\\$\\(?APPDATA\\)?", boost::regex::icase);
120 path = boost::regex_replace( path, appdata, ConfigurationFileLocator::Instance().getSpecialPath( CSIDL_APPDATA ), boost::regex_constants::format_literal );
122 static boost::regex commonappdata(
"\\$\\(?COMMON_APPDATA\\)?", boost::regex::icase);
123 path = boost::regex_replace( path, commonappdata, ConfigurationFileLocator::Instance().getSpecialPath( CSIDL_COMMON_APPDATA ), boost::regex_constants::format_literal );
125 static boost::regex myDocs(
"\\$\\(?MY_DOCUMENTS\\)?", boost::regex::icase);
126 path = boost::regex_replace( path, myDocs, ConfigurationFileLocator::Instance().getSpecialPath( CSIDL_PERSONAL ), boost::regex_constants::format_literal );
161 fprintf(stderr,
"could neither access nor create directory %s\n", tmp );
177 static boost::regex dir(
"(.*)[\\\\/:][^\\\\/:]+");
179 if( boost::regex_match( filename, what, dir)) {
180 directory.assign( what[1].first, what[1].second );
198 char buffer[_MAX_PATH];
199 if( _getcwd( buffer, _MAX_PATH ) )
200 if ( exePath ==
"." || exePath ==
".\\" )
218 TCHAR szPath[MAX_PATH];
220 if ( SUCCEEDED(SHGetFolderPath( NULL, type, NULL, SHGFP_TYPE_CURRENT, szPath ))) {
234 vector<ASCString> dirs;
238 if ( RegOpenKeyEx ( HKEY_LOCAL_MACHINE,
239 "SOFTWARE\\Advanced Strategic Command\\",
242 &key ) == ERROR_SUCCESS) {
245 const int size = 2000;
248 if ( RegQueryValueEx ( key,
"InstallDir2", NULL, &type, (BYTE*)buf, &size2 ) == ERROR_SUCCESS ) {
249 if ( type == REG_SZ ) {
252 dirs.push_back( dir );
270 dirs.push_back(
"$(MY_DOCUMENTS)\\" );
271 dirs.push_back(
"$(APPDATA)\\" );
272 dirs.push_back(
"$(COMMON_APPDATA)\\" );
273 dirs.push_back(
"$(EXEPATH)\\" );
284 dirs.push_back( dir );
296 if ( cmdline.length() ) {
298 displayLogMessage( 7,
"ConfigurationFileLocatorCore::getConfigFileName() returns cmdline: " + cmdline +
"\n" );
305 displayLogMessage( 7,
"ConfigurationFileLocatorCore::getConfigFileName() returns env dir: " + res +
"\n" );
312 if (
exist( completeName )) {
314 displayLogMessage( 7,
"ConfigurationFileLocatorCore::getConfigFileName() returns exepath: " + completeName +
"\n" );
320 if ( list.size() >= 1 ) {
322 for ( vector<ASCString>::iterator i = list.begin(); i != list.end(); ++i ) {
325 displayLogMessage( 7,
"ConfigurationFileLocatorCore::getConfigFileName() returns default dir: " + p +
"\n" );
330 displayLogMessage( 7,
"ConfigurationFileLocatorCore::getConfigFileName() returns list0: " + res +
"\n" );
354 for ( vector<ASCString>::iterator i = dirs.begin(); i != dirs.end(); ++i )
363 ASCString configFileName = ConfigurationFileLocator::Instance().getConfigFileName();
364 if ( !configFileName.empty() )
365 return configFileName ;
367 return "-none- ; default values used";
380 if (
exist ( filename )) {
398 ConfigurationFileLocator::Instance().writeDefaultPathsToOptions();
400 if ( !filename.empty() ) {
403 displayLogMessage ( 6,
"A config file has been successfully written to " + filename +
" ");
421 if ( configFileName.empty() )
422 configFileName = ConfigurationFileLocator::Instance().getConfigFileName();
447 ASCString msg =
"Unable to access " + filename +
"\n";
448 msg +=
"Make sure the file main.ascdat is in one of the search paths specified in your config file !\n";
450 ASCString configFileName = ConfigurationFileLocator::Instance().getConfigFileName();
451 if (
exist( configFileName ))
452 msg +=
"The configuration file that is used is: " + configFileName +
"\n";
454 if ( !configFileName.empty() ) {
457 msg +=
"A configuration file has been written to " + configFileName +
"\n";
460 msg +=
"These paths are being searched for data files:\n ";
469 fatalError (
"checkFileLoadability threw an unspecified exception\n" );
478 ConfigurationFileLocator::Instance().setCommandLineParam( configFileName );
498 fatalError (
"a fatal IO error occured while mounting the container file %s\n"
499 "It is probably damaged, try getting a new one.\n", err.
getFileName().c_str() );
502 fatalError (
"a fatal error occured while decompressing a container file.\n"
503 "If you have several *.ascdat files in your ASC directory, try removing all but main.ascdat.\n"
504 "If the error still occurs then, get a new data package from www.asc-hq.org\n" );
507 fatalError (
"a fatal error occured while mounting the container files \n");
510 fatalError (
"loading of game failed during pre graphic initializing" );
513 if ( ! (skipChecks & 1 ))
519 ASCString msg =
"A newer version of the data file '";
520 msg += filename +
"' is required. \nYou can get a new data package at http://www.asc-hq.org\n";
521 msg +=
"The old file is " + location;
void addSearchPath(const ASCString &path)
miscellaneous functions which are used by ASC and all its tools
const int technology_version
const ASCString & getFileName() const
ASCString getSearchPath(int i)
ASCString getConfigFileName()
void setDefaultDirectories()
int readdata(void *buf, int size, bool excpt=true)
Reads data from the stream.
void writeDefaultPathsToOptions()
void addSearchPath(const ASCString &path)
void load(const ASCString &filename)
ASCString getSpecialPath(int type)
void warningMessage(const ASCString &str)
ppixelxlattable xlatpictgraytable
Global platform dependant definitions. This file just branches to the platform specific files in thei...
void versionError(const ASCString &filename, const ASCString &location)
void setExecutableLocation(const ASCString &path)
int readgameoptions(const ASCString &filename)
ASCString getConfigFileName()
virtual Uint8 readUint8(void)
Reads a 8 bit unsigned Integer.
The ASCString class provides an abstract way to manipulate strings.
char * extractPath(char *buf, const char *filename)
ConfigurationFileLocatorCore()
void checkFileLoadability(const ASCString &filename)
void setChanged(bool flag=true)
bool makeDirectory(const ASCString &path)
bool directoryExist(const ASCString &path)
bool isPathRelative(const ASCString &path)
bool writegameoptions(ASCString configFileName)
void displayLogMessage(int msgVerbosity, const char *message,...)
const char * asc_EnvironmentName
The interface for the various streams that ASC offers, like file and memory streams.
char * constructFileName(char *buf, int directoryLevel, const char *path, const char *filename)
const ASCString & getMessage(void) const
int createDirectory(const char *name)
The IO for many basic classes and structurs of ACS.
void generategrayxlattable(ppixelxlattable tab, Uint8 offset, Uint8 size, dacpalette256 *pal)
A translation table ( to be used by xlatpict ) is generated to translate any color of palette pal to ...
ASCString getConfigForPrinting()
static CGameOptions * Instance()
returns the only Instance
ASCString getDirectory(ASCString filename)
const char * asc_configurationfile
tpixelxlattable * ppixelxlattable
void opencontainer(const char *wildcard)
void appendbackslash(char *string)
basegfx.h is the interface for the legacy graphic routines (of which some are platform dependent)...
void setCommandLineParam(const ASCString &path)
ASCString getSearchPath(int i)
bool exist(const ASCString &s)
does a file s exist (wildcards allowed)
void initFileIO(const ASCString &configFileName, int skipChecks)
The color palette and various color translation tables.
vector< ASCString > getDefaultDirectory()
ASCString getExecutableLocation()
void fatalError(const ASCString &string)
struct txlattables::@19::@21 a
void save(const ASCString &filename)
ASCString resolvePath(ASCString path)