示例#1
0
void save_options(struct app_runtime_t *app, Options *options, char *config_file_path)
{
    if ((!config_file_path) || (!strcmp(config_file_path, ""))) {
        return; 
    }

    int rc = -1;
    int buf_size = 8*1024*1024;
    char *buffer = (char*) malloc(buf_size);
    memset(buffer, 0, buf_size);

    CSimpleIniA ini;
    ini.SetUnicode();

    int is_write = formatOptions(options, buffer, buf_size);
    if (is_write != OPTIONS_WRITE) {
        goto SAVE_QUIT;
    }

    rc = ini.LoadData(buffer, strlen(buffer));
    if (rc < 0) {
        s_logger.log_e(&s_logger, "APP: Load Options Error.");
    }

    rc = ini.SaveFile(config_file_path);
    if (rc < 0) {
        s_logger.log_e(&s_logger, "APP: Save Options Error.");
    }

SAVE_QUIT:
    if (buffer != NULL) {
        free(buffer);
        buffer = NULL;
    }
}
void ScriptSettings::Save() const {
	CSimpleIniA ini;
	ini.SetUnicode();
	ini.LoadFile(SETTINGSFILE);
	ini.SetValue("OPTIONS", "Enable", EnableManual ? " 1" : " 0");
	ini.SetLongValue("OPTIONS", "ShiftMode", ShiftMode);
	ini.SaveFile(SETTINGSFILE);
}
示例#3
0
文件: test.cpp 项目: rusonglee/cstudy
int main(void)
{
	CSimpleIniA ini;
	const char* filename="test.ini";
	ini.SetUnicode();
	ini.LoadFile(filename);
	ini.SetValue("node1","foo","foonew");
	const char* inivalue=ini.GetValue("node1","foo",NULL);
	printf("%s\n",inivalue);
	printf("end!\n");
	bool b=false;
	ini.SaveFile(filename,b);
	ini.Reset();
	return 0;
}
	void save(const char* filename) {
		CSimpleIniA ini;
		ini.SetUnicode();

		ini.SetDoubleValue("Controls", "Mouse Sensitivity", _mouseSensitivity);
		ini.SetLongValue("Graphics", "Width", _displayWidth);
		ini.SetLongValue("Graphics", "Height", _displayHeight);
		ini.SetBoolValue("Graphics", "Fullscreen", _fullscreen);
		ini.SetBoolValue("Graphics", "Borderless", _borderless);
		ini.SetDoubleValue("Graphics", "Field of View", _fieldOfView);
		ini.SetBoolValue("Debug", "Show Console", _showConsole);
		ini.SetBoolValue("Debug", "Logging", _logging);
		ini.SetBoolValue("Debug", "Show Mouse Cursor", _showMouseCursor);
		ini.SetBoolValue("Debug", "Center Mouse Cursor", _centerMouseCursor);
		ini.SetBoolValue("Debug", "Show FPS", _showFPS);
		ini.SetBoolValue("Debug", "Show Cursor Coords", _showCursorCoordinates);
		ini.SetBoolValue("Debug", "Debug Context", _debugContext);
		ini.SetValue("Debug", "Starting Scene", _startingScene->c_str());
		SI_Error rc = ini.SaveFile(filename);
		if (rc < 0)
			fputs("Couldn't save settings", stderr);
	}
示例#5
0
bool SettingsManager::saveSettings()
{
	
	CSimpleIniA ini;
	ini.SetUnicode();
	ini.LoadFile("CONFIG.ini");

	if(ini.IsEmpty())
		{return false;}

	ini.SetValue("HIGHSCORE", "NAME", m_settings->HIGHSCORE_NAME.c_str());
	ini.SetLongValue("HIGHSCORE", "SCORE", m_settings->HIGHSCORE_SCORE);
	ini.SetValue("HIGHSCORE2", "NAME", m_settings->HIGHSCORE2_NAME.c_str());
	ini.SetLongValue("HIGHSCORE2", "SCORE", m_settings->HIGHSCORE2_SCORE);
	ini.SetValue("HIGHSCORE3", "NAME", m_settings->HIGHSCORE3_NAME.c_str());
	ini.SetLongValue("HIGHSCORE3", "SCORE", m_settings->HIGHSCORE3_SCORE);

	//Save the file
	if(ini.SaveFile("CONFIG.ini") < 0)
		{return false;}
	return true;
}
示例#6
0
inline bool Filecache::sync() {
    _guard g(m);
    ini.SaveFile(filename.c_str());
    return true;
}
示例#7
0
// Main
int main(int argc, char **argv)
{
	// Check the number of command line arguments
	if(argc < 2)
	{
		cout << "Try " << argv[0] << " -h or --help" << endl;
		return 1;
	}

	try
	{
		TCLAP::CmdLine cmd("Push notifications to your phone easily.", ' ', "0.3");

		// Values
		TCLAP::ValueArg<int> idArg("i","id","ID of the device.",false,0,"number");
		cmd.add(idArg);

		// Switches
		TCLAP::SwitchArg tokenSwitch("t", "token", "Request your token.", cmd, false);
		TCLAP::SwitchArg listSwitch("l", "list", "List all your devices.", cmd, false);
		TCLAP::SwitchArg pipeSwitch("p", "pipe", "Input via pipe.", cmd, false);
		TCLAP::SwitchArg verifySwitch("v","verify","Checks if token is still valid.", cmd, false);


		// add unlabeled argument
		TCLAP::UnlabeledValueArg<string> noLabelMessage("message", "The notification you want to send.", false, "message", "message");
		cmd.add(noLabelMessage);


    	// Parse the argv array.
    	cmd.parse(argc, argv);


		// Variables
		string message;
		int id;
		CSimpleIniA iniReader;
		iniReader.SetUnicode();


		// Request token
		if(tokenSwitch.getValue())
		{
			string username, password, token;

			// Read username
			cout << "Username: "******"Password: "******"pusher", "username", username.c_str());
			iniReader.SetValue("pusher", "appToken", token.c_str());

			// Check if file is writable
			if(iniReader.SaveFile(CONFIG_FILE) < 0)
			{
				cout << "Try running pusher as root or save the following in "
					<< CONFIG_FILE << "\n" << endl;

				// Data
				string strData;
				iniReader.Save(strData);
				cout << strData << endl;

				return 1;
			}


			cout << "Success!" << endl;
			return 0;
		}



		// Check if reading of config is possible
		if(iniReader.LoadFile(CONFIG_FILE) < 0)
		{
			throw PusherError("You need to login first.");
		}

		string username = iniReader.GetValue("pusher", "username", "");
		string appToken = iniReader.GetValue("pusher", "appToken", "");

		if(username.empty() || appToken.empty())
		{
			throw PusherError("You need to login first.");
		}



		// Loading values
		PushHandler pusherInstance(username, appToken);



		// Verify token
		if(verifySwitch.getValue())
		{
			if(pusherInstance.verifyToken())
			{
				cout << "appToken is valid" << endl;
				return 0;
			}
			else
			{
				cout << "appToken is invalid" << endl;
				return 1;
			}
		}



		// List devices
		if(listSwitch.getValue())
		{
			vector<PushHandler::Device> devices;
			devices = pusherInstance.getDevices();

			unsigned int titleLength = 5;
			unsigned int modelLength = 5;
			unsigned int idLength = 2;

			for(unsigned int i = 0; i < devices.size(); i++)
			{
				if(devices[i].title.length() > titleLength) { titleLength = devices[i].title.length(); }
				if(devices[i].model.length() > modelLength) { modelLength = devices[i].model.length(); }
				if(devices[i].id.length() > idLength) { idLength = devices[i].id.length(); }
			}

			cout
				<< "ID\033[" << (idLength - 2 + 2) << "C"
				<< "Title\033[" << (titleLength - 5 + 2) << "C"
				<< "Model" << endl;

			for(unsigned int x = 0; x < (titleLength + modelLength + idLength + 4); x++) { cout << "-"; }
			cout << endl;

			for(unsigned int i = 0; i < devices.size(); i++)
			{
				cout
					<< devices[i].id << "\033[" << (idLength - devices[i].id.length() + 2) << "C"
					<< devices[i].title << "\033[" << (titleLength - devices[i].title.length() + 2) << "C"
					<< devices[i].model << endl;
			}

			return 0;
		}



		// Device id
		if(idArg.getValue() != 0)
		{
			id = idArg.getValue();
		}
		else
		{
			return 1;
		}



		// Load message
		if(pipeSwitch.getValue())
		{
			string pipeBuffer;

			while(getline(cin, pipeBuffer))
			{
				message += "\n";
				message += pipeBuffer;
			}

			message.erase(0,1);
		}
		else
		{
			message = noLabelMessage.getValue();
		}

		// Send the message
		stringstream stringID;
		stringID << id;

		pusherInstance.sendToDevice(stringID.str(), message);
	}