Example #1
0
void Init() {
#ifdef WIN32
DBName += getenv("LOCALAPPDATA");
DBName += "\\.abfplayer.db";
#else
DBName += getenv("HOME");
DBName += "/.abfplayer.db";
#endif
if (!DBExists()) CreateDatabase();
Initialized = true;
}
Example #2
0
///////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////
Environment::Environment(Options& opt):
    options(opt),
    log(cout),
    winSys(opt)
{
#   if defined(__UNIX__)

	// If running tests, first create the results directory.
	// Refuse to overwrite one that already exists.
	if (opt.mode == Options::run) {
		if (opt.overwrite) {
			// remove existing db dir
			// XXX using system() probably isn't ideal
			char cmd[1000];
			snprintf(cmd, 999, "rm -rf %s", opt.db1Name.c_str());
			system(cmd);
		}
		if (mkdir(opt.db1Name.c_str(), 0755)) {
			if (errno == EEXIST)
				throw DBExists();
			else
				throw DBCantOpen(opt.db1Name);
		}
	// If comparing previous runs, make a token attempt to verify
	// that the two databases exist.
	} else {
		struct stat s;
		if (stat(opt.db1Name.c_str(), &s) || !S_ISDIR(s.st_mode))
			throw DBCantOpen(opt.db1Name);
		if (stat(opt.db2Name.c_str(), &s) || !S_ISDIR(s.st_mode))
			throw DBCantOpen(opt.db2Name);
	}

#   elif defined(__MS__)
	// If running tests, first create the results directory.
	// Refuse to overwrite one that already exists.
	if (opt.mode == Options::run) {
		if (opt.overwrite) {
			char cmd[1000];
#if defined(_MSC_VER)
			_snprintf(cmd, 999, "rd /s /q %s", opt.db1Name.c_str());
#else
			snprintf(cmd, 999, "rd /s /q %s", opt.db1Name.c_str());
#endif
			system(cmd);
		}
		if (!CreateDirectory(opt.db1Name.c_str(),0)) {
			if (GetLastError() == ERROR_ALREADY_EXISTS)
				throw DBExists();
			else
				throw DBCantOpen(opt.db1Name);
		}
	// If comparing previous runs, make a token attempt to verify
	// that the two databases exist.
	} else {
		struct _stat s; 

		if (_stat(opt.db1Name.c_str(), &s) || !(s.st_mode & _S_IFDIR))
			throw DBCantOpen(opt.db1Name);
		if (_stat(opt.db2Name.c_str(), &s) || !(s.st_mode & _S_IFDIR))
			throw DBCantOpen(opt.db2Name);
	}

#   endif
} // Environment::Environment()