mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-12 19:06:09 -10:00
153 lines
3.3 KiB
C++
153 lines
3.3 KiB
C++
#include "stdafx.h"
|
|
#include "launcher_settings.h"
|
|
#include "misc.h"
|
|
|
|
#include "iniparser/iniparser.h"
|
|
#include "iniparser/dictionary.h"
|
|
|
|
|
|
char LauncherSettings::m_exe_filepath[MAX_PATH] = "";
|
|
char LauncherSettings::m_exe_pathonly[MAX_PATH] = "";
|
|
char LauncherSettings::m_exe_nameonly[MAX_PATH] = "";
|
|
bool LauncherSettings::m_is_exe_path_valid = false;
|
|
|
|
char LauncherSettings::m_reg_path[MAX_PATH] = "";
|
|
int LauncherSettings::m_exe_type = EXE_TYPE_NONE;
|
|
|
|
char LauncherSettings::m_active_mod[MAX_PATH] = "";
|
|
|
|
bool LauncherSettings::m_showed_pilot_warning = false;
|
|
|
|
bool LauncherSettings::m_is_openal_build = false;
|
|
|
|
|
|
bool LauncherSettings::load()
|
|
{
|
|
dictionary *ini = iniparser_load(const_cast<char*>(INI_MAIN));
|
|
if (ini == NULL)
|
|
return false;
|
|
|
|
iniparser_dump(ini, stderr);
|
|
|
|
// read ini variables
|
|
char *exe_filepath = iniparser_getstr(ini, "launcher:exe_filepath");
|
|
char *active_mod = iniparser_getstr(ini, "launcher:active_mod");
|
|
bool showed_pilot_warning = (iniparser_getboolean(ini, "launcher:showed_pilot_warning", 0) != 0);
|
|
|
|
if (exe_filepath == NULL || active_mod == NULL)
|
|
return false;
|
|
|
|
// atomically assign all ini variables
|
|
set_exe_filepath(exe_filepath);
|
|
set_active_mod(active_mod);
|
|
m_showed_pilot_warning = showed_pilot_warning;
|
|
|
|
iniparser_freedict(ini);
|
|
return true;
|
|
}
|
|
|
|
bool LauncherSettings::save()
|
|
{
|
|
FILE *fp = ini_open_for_write(const_cast<char*>(INI_MAIN), false, "DO NOT EDIT THIS FILE");
|
|
if (fp == NULL)
|
|
return false;
|
|
|
|
ini_write_type(fp, "[launcher]");
|
|
ini_write_data(fp, "exe_filepath", m_exe_filepath);
|
|
ini_write_data(fp, "active_mod", m_active_mod);
|
|
ini_write_data(fp, "showed_pilot_warning", m_showed_pilot_warning);
|
|
|
|
ini_close(fp);
|
|
return true;
|
|
}
|
|
|
|
char *LauncherSettings::get_exe_pathonly()
|
|
{
|
|
return m_exe_pathonly;
|
|
}
|
|
|
|
char *LauncherSettings::get_exe_nameonly()
|
|
{
|
|
return m_exe_nameonly;
|
|
}
|
|
|
|
char *LauncherSettings::get_exe_filepath()
|
|
{
|
|
return m_exe_filepath;
|
|
}
|
|
|
|
bool LauncherSettings::is_exe_path_valid()
|
|
{
|
|
return m_is_exe_path_valid;
|
|
}
|
|
|
|
void LauncherSettings::set_exe_filepath(const char *path)
|
|
{
|
|
if (path == NULL || *path == '\0')
|
|
return;
|
|
|
|
strcpy(m_exe_filepath, path);
|
|
strcpy(m_exe_pathonly, path);
|
|
|
|
char *final_slash = strrchr(m_exe_pathonly, '\\');
|
|
|
|
if (final_slash != NULL)
|
|
{
|
|
strcpy(m_exe_nameonly, final_slash+1);
|
|
*final_slash = '\0';
|
|
m_is_exe_path_valid = true;
|
|
}
|
|
else
|
|
{
|
|
*m_exe_pathonly = '\0';
|
|
strcpy(m_exe_nameonly, path);
|
|
m_is_exe_path_valid = false;
|
|
}
|
|
}
|
|
|
|
char *LauncherSettings::get_reg_path()
|
|
{
|
|
return m_reg_path;
|
|
}
|
|
|
|
int LauncherSettings::get_exe_type()
|
|
{
|
|
return m_exe_type;
|
|
}
|
|
|
|
void LauncherSettings::set_reg_path(const char *reg_path, int exe_type)
|
|
{
|
|
strcpy(m_reg_path, reg_path);
|
|
m_exe_type = exe_type;
|
|
}
|
|
|
|
char *LauncherSettings::get_active_mod()
|
|
{
|
|
return m_active_mod;
|
|
}
|
|
|
|
void LauncherSettings::set_active_mod(const char *active_mod)
|
|
{
|
|
strcpy(m_active_mod, active_mod);
|
|
}
|
|
|
|
bool LauncherSettings::get_showed_pilot_warning()
|
|
{
|
|
return m_showed_pilot_warning;
|
|
}
|
|
|
|
void LauncherSettings::set_showed_pilot_warning(bool showed_pilot_warning)
|
|
{
|
|
m_showed_pilot_warning = showed_pilot_warning;
|
|
}
|
|
|
|
bool LauncherSettings::is_openal_build()
|
|
{
|
|
return m_is_openal_build;
|
|
}
|
|
|
|
void LauncherSettings::set_openal_build(bool flag)
|
|
{
|
|
m_is_openal_build = flag;
|
|
}
|