Example #1
0
void User::initPipe()
{
	if (m_pPipeClient)
		return;

	m_pPipeClient = new UserIPCPipeClient(getUserName(), getAppDataPath(), true);
	m_pPipeClient->onDisconnectEvent += delegate(&onPipeDisconnect);

	size_t x=0;

	do
	{
		try
		{
			m_pPipeClient->start();
			break;
		}
		catch (gcException &)
		{
			if (x > 5)
			{
				logOut();
				throw;
			}
			else
			{
				gcSleep(100);
				x++;
			}
		}
	}
	while (true);
}
Example #2
0
QString Runtime::getDataPath()
{
    static QString dataPath = getAppDataPath();
    return dataPath;
}
Example #3
0
QString PathUtils::getAppDataFilePath(const QString& filename) {
    return QDir(getAppDataPath()).absoluteFilePath(filename);
}
Example #4
0
std::string Config::setup()
{
	versionDifferent = false;

	bool configFileFound = false;
	bool configFileValid = false;
	bool firstTime = false;
	bool setupDone = false;
	string strSetupResult = "";
	
	// get currentDir path
	currentDir = getCurrentDir(); // current directory
	cout << "currentDir = " << currentDir << endl;
	
	// get ENV's appdata path PLUS 'BeepComp'
	appDataPath = getAppDataPath();
	
	bool appDataCreateResult;
	
	//
	// create the parent folder in appdata
	//
	appDataCreateResult = CreateDirectory(appDataPath.c_str(), NULL);
	cout << "Create %APPDATA%\\BeepComp folder:  " << appDataPath << endl;

	// success-fail check
	if(appDataCreateResult)
		cout << "success!\n";
	else
	{
		cout << "fail.\n";
		if(GetLastError()==ERROR_ALREADY_EXISTS) cout << "The folder already exists.\n";
	}	
	
	// now check for the config file's existance
	cout << "check if beepcomp.config exists...\n";
	configFilePath = appDataPath + "\\" + "beepcomp.config";
	cout << "configFilePath = " << configFilePath << endl;
	
	// if config file found ... get Path information from that
	configFileFound = configFileExists(configFilePath);
	
	// if config file found -> the program has already run once after installation	
	// we will check for the validity of config file...
	
	// if config file was found, let's try to get path data from it 
	if(configFileFound)
	{
		cout << "Config file exists, reading contents and check data validity...\n";
		configFileValid = readConfigFile();
		
		// read config file ... you get boolean result for data validity
		if(configFileValid)
		{
			cout << "Config file's data is good!.\n";
			cout << "Path information is now:\n";
			cout << "userDocPath: " << userDocPath << endl;
			cout << "userdataParentPath: " << userdataParentPath << endl;
			cout << "userdataPath: " << userdataPath << endl;
			setupDone = true; // congrats, all done here
		}
		else
			cout << "Config file's data is NOT good...\n";
	}
	// config file NOT found. first time here
	else
	{
		cout << "Config file NOT found. first time here...\n";
		firstTime = true;
	}
	
	if(versionDifferent)
		cout << "Installed version is different - we should overwrite userdata.\n";
	
	// if config file is found and also its data is valid... 
	// we have read all the valid path information - we will exit without setup
	if(setupDone)
	{
		strSetupResult = "SETUP SKIPPED - Config file found and is valid";
		return strSetupResult;
	}

	////////////////////////////////////////////////////////////////////////////////////////
	
	// File not found - means program is being run for the first time after installation
	// - will do initial setup!
	
	setupDone = false;
	if(firstTime)
	{
		cout << "Config file does not exist. Must be fresh after installation!\n";
		strSetupResult = "Initial setup - ";
	}
	else
	{
		cout << "Config file corrupt - need to rebuild! (or possibly dest folders erased?)\n";
		strSetupResult = "Rebuild corrupt config file (or reconstructing dest folders) - ";
	}

	// get the userDoc path from env var
	userDocPath = getUserDocPathFromSystem();
	cout << "User's 'Documents' path = " << userDocPath << endl;
	
	// if this EVER fails... safeguard: set it to USERPROFILE folder...
	if(userDocPath.empty())
	{
		userDocPath = string(getenv("USERPROFILE"));
		cout << "User's Documents path corrected to USERPROFILE folder:\n";
		cout << userDocPath << endl;
	}
	
	bool result;
	
	//
	// create the parent folder in userdata
	//
	userdataParentPath = userDocPath + "\\" + "BeepComp";
	result = CreateDirectory(userdataParentPath.c_str(), NULL);
	cout << "Create parent folder:  " << userdataParentPath << endl;

	// success-fail check
	if(result)
		cout << "success!\n";
	else
	{
		cout << "fail.\n";
		if(GetLastError()==ERROR_ALREADY_EXISTS) cout << "The folder already exists.\n";
	}	
	
	//
	// create the userdata folder in the parent folder
	//
	userdataPath = userdataParentPath + "\\" + "userdata";
	result = CreateDirectory(userdataPath.c_str(), NULL);
	cout << "Create userdata folder:  " << userdataPath << endl;

	// success-fail check
	if(result)
		cout << "success!\n";
	else
	{
		cout << "fail.\n";
		if(GetLastError()==ERROR_ALREADY_EXISTS) cout << "The folder already exists.\n";
	}
	
	// now get ready to copy all the txt files to destination...
	cout << "Okay, first time here. Let's set up your userdata folder...\n";
	
	// get ready to copy all the txt files from userdata source
	userdataPathOrigin = currentDir + "\\" + "userdata";
	vector<string> dataFiles = getFileNamesInFolder(userdataPathOrigin);
	
	int nFiles = dataFiles.size();
	
	cout << "Listing files to copy...\n";
	for(int i=0; i<nFiles; i++)
		cout << dataFiles[i] << endl;
	
	// now copy all these files to to the newly created userdata directory!
	for(int i=0; i<nFiles; i++)
	{
		string source = userdataPathOrigin + "\\" + dataFiles[i];
		string destination = userdataPath + "\\" + dataFiles[i];
		cout << "Copying...\n";
		cout << "From: " << source << endl;
		cout << "To:   " << destination << endl;
		
		int copyResult;
		copyResult = CopyFile(source.c_str(), destination.c_str(), FALSE); // will force overwrite
		
		if(copyResult==0)
			cout << "...failed\n";
		else
			cout << "...success!\n";
	}
	
	// write all path information to config file...
	
	result = writeConfigFile();
	if(!result)
	{
		cout << "Unable to write: " << configFilePath << endl;
		strSetupResult += "error writing config file";
	}
	else
	{
		cout << "beepcomp.config file created!\n";
		strSetupResult += "SUCCESS";
	}
	
	return strSetupResult;
}