summaryrefslogtreecommitdiffhomepage
path: root/Stars45/ModConfig.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Stars45/ModConfig.cpp')
-rw-r--r--Stars45/ModConfig.cpp478
1 files changed, 239 insertions, 239 deletions
diff --git a/Stars45/ModConfig.cpp b/Stars45/ModConfig.cpp
index dd2f96e..c082353 100644
--- a/Stars45/ModConfig.cpp
+++ b/Stars45/ModConfig.cpp
@@ -1,15 +1,15 @@
/* Project Starshatter 5.0
- Destroyer Studios LLC
- Copyright © 1997-2007. All Rights Reserved.
+ Destroyer Studios LLC
+ Copyright © 1997-2007. All Rights Reserved.
- SUBSYSTEM: Stars.exe
- FILE: ModConfig.cpp
- AUTHOR: John DiCamillo
+ SUBSYSTEM: Stars.exe
+ FILE: ModConfig.cpp
+ AUTHOR: John DiCamillo
- OVERVIEW
- ========
- Mod file deployment configuration and manager
+ OVERVIEW
+ ========
+ Mod file deployment configuration and manager
*/
@@ -31,23 +31,23 @@ static ModConfig* mod_config = 0;
ModConfig::ModConfig()
{
- mod_config = this;
+ mod_config = this;
- Load();
- FindMods();
- Deploy();
+ Load();
+ FindMods();
+ Deploy();
}
ModConfig::~ModConfig()
{
- if (mod_config == this)
- mod_config = 0;
+ if (mod_config == this)
+ mod_config = 0;
- Undeploy();
+ Undeploy();
- enabled.destroy();
- disabled.destroy();
- mods.destroy();
+ enabled.destroy();
+ disabled.destroy();
+ mods.destroy();
}
// +-------------------------------------------------------------------+
@@ -55,14 +55,14 @@ ModConfig::~ModConfig()
void
ModConfig::Initialize()
{
- mod_config = new(__FILE__,__LINE__) ModConfig;
+ mod_config = new(__FILE__,__LINE__) ModConfig;
}
void
ModConfig::Close()
{
- delete mod_config;
- mod_config = 0;
+ delete mod_config;
+ mod_config = 0;
}
// +-------------------------------------------------------------------+
@@ -70,7 +70,7 @@ ModConfig::Close()
ModConfig*
ModConfig::GetInstance()
{
- return mod_config;
+ return mod_config;
}
// +-------------------------------------------------------------------+
@@ -78,110 +78,110 @@ ModConfig::GetInstance()
void
ModConfig::Load()
{
- // read the config file:
- BYTE* block = 0;
- int blocklen = 0;
-
- char filename[64];
- strcpy(filename, "mod.cfg");
-
- FILE* f = ::fopen(filename, "rb");
-
- if (f) {
- ::fseek(f, 0, SEEK_END);
- blocklen = ftell(f);
- ::fseek(f, 0, SEEK_SET);
-
- block = new(__FILE__,__LINE__) BYTE[blocklen+1];
- block[blocklen] = 0;
-
- ::fread(block, blocklen, 1, f);
- ::fclose(f);
- }
-
- if (blocklen == 0)
- return;
-
- Parser parser(new(__FILE__,__LINE__) BlockReader((const char*) block, blocklen));
- Term* term = parser.ParseTerm();
-
- if (!term) {
- Print("ERROR: could not parse '%s'.\n", filename);
- return;
- }
- else {
- TermText* file_type = term->isText();
- if (!file_type || file_type->value() != "MOD_CONFIG") {
- Print("WARNING: invalid '%s' file. No mods deployed\n", filename);
- return;
- }
- }
-
- enabled.destroy();
-
- do {
- delete term;
-
- term = parser.ParseTerm();
-
- if (term) {
- TermDef* def = term->isDef();
- if (def) {
- Text name;
- GetDefText(name, def, filename);
- enabled.append(new(__FILE__,__LINE__) Text(name));
- }
- }
- }
- while (term);
-
- delete [] block;
+ // read the config file:
+ BYTE* block = 0;
+ int blocklen = 0;
+
+ char filename[64];
+ strcpy(filename, "mod.cfg");
+
+ FILE* f = ::fopen(filename, "rb");
+
+ if (f) {
+ ::fseek(f, 0, SEEK_END);
+ blocklen = ftell(f);
+ ::fseek(f, 0, SEEK_SET);
+
+ block = new(__FILE__,__LINE__) BYTE[blocklen+1];
+ block[blocklen] = 0;
+
+ ::fread(block, blocklen, 1, f);
+ ::fclose(f);
+ }
+
+ if (blocklen == 0)
+ return;
+
+ Parser parser(new(__FILE__,__LINE__) BlockReader((const char*) block, blocklen));
+ Term* term = parser.ParseTerm();
+
+ if (!term) {
+ Print("ERROR: could not parse '%s'.\n", filename);
+ return;
+ }
+ else {
+ TermText* file_type = term->isText();
+ if (!file_type || file_type->value() != "MOD_CONFIG") {
+ Print("WARNING: invalid '%s' file. No mods deployed\n", filename);
+ return;
+ }
+ }
+
+ enabled.destroy();
+
+ do {
+ delete term;
+
+ term = parser.ParseTerm();
+
+ if (term) {
+ TermDef* def = term->isDef();
+ if (def) {
+ Text name;
+ GetDefText(name, def, filename);
+ enabled.append(new(__FILE__,__LINE__) Text(name));
+ }
+ }
+ }
+ while (term);
+
+ delete [] block;
}
void
ModConfig::Save()
{
- FILE* f = fopen("mod.cfg", "w");
- if (f) {
- fprintf(f, "MOD_CONFIG\n\n");
-
- ListIter<Text> iter = enabled;
- while (++iter) {
- Text* name = iter.value();
- fprintf(f, "mod: \"%s\"\n", name->data());
- }
-
- fclose(f);
- }
+ FILE* f = fopen("mod.cfg", "w");
+ if (f) {
+ fprintf(f, "MOD_CONFIG\n\n");
+
+ ListIter<Text> iter = enabled;
+ while (++iter) {
+ Text* name = iter.value();
+ fprintf(f, "mod: \"%s\"\n", name->data());
+ }
+
+ fclose(f);
+ }
}
void
ModConfig::FindMods()
{
- disabled.destroy();
-
- DataLoader* loader = DataLoader::GetLoader();
-
- if (loader) {
- loader->UseFileSystem(true);
- loader->ListFiles("*.dat", disabled, true);
- loader->UseFileSystem(Starshatter::UseFileSystem());
-
- ListIter<Text> iter = disabled;
- while (++iter) {
- Text* name = iter.value();
- name->setSensitive(false);
-
- if (*name == "shatter.dat" ||
- *name == "beta.dat" ||
- *name == "start.dat" ||
- *name == "irunin.dat" ||
- *name == "vox.dat" ||
- name->contains("uninstall") ||
- enabled.contains(name))
- delete iter.removeItem();
- }
- }
+ disabled.destroy();
+
+ DataLoader* loader = DataLoader::GetLoader();
+
+ if (loader) {
+ loader->UseFileSystem(true);
+ loader->ListFiles("*.dat", disabled, true);
+ loader->UseFileSystem(Starshatter::UseFileSystem());
+
+ ListIter<Text> iter = disabled;
+ while (++iter) {
+ Text* name = iter.value();
+ name->setSensitive(false);
+
+ if (*name == "shatter.dat" ||
+ *name == "beta.dat" ||
+ *name == "start.dat" ||
+ *name == "irunin.dat" ||
+ *name == "vox.dat" ||
+ name->contains("uninstall") ||
+ enabled.contains(name))
+ delete iter.removeItem();
+ }
+ }
}
// +-------------------------------------------------------------------+
@@ -189,14 +189,14 @@ ModConfig::FindMods()
ModInfo*
ModConfig::GetModInfo(const char* filename)
{
- for (int i = 0; i < mods.size(); i++) {
- ModInfo* mod_info = mods[i];
+ for (int i = 0; i < mods.size(); i++) {
+ ModInfo* mod_info = mods[i];
- if (mod_info->Filename() == filename && mod_info->IsEnabled())
- return mod_info;
- }
+ if (mod_info->Filename() == filename && mod_info->IsEnabled())
+ return mod_info;
+ }
- return false;
+ return false;
}
// +-------------------------------------------------------------------+
@@ -204,14 +204,14 @@ ModConfig::GetModInfo(const char* filename)
bool
ModConfig::IsDeployed(const char* name)
{
- for (int i = 0; i < mods.size(); i++) {
- ModInfo* mod_info = mods[i];
+ for (int i = 0; i < mods.size(); i++) {
+ ModInfo* mod_info = mods[i];
- if (mod_info->Name() == name && mod_info->IsEnabled())
- return true;
- }
+ if (mod_info->Name() == name && mod_info->IsEnabled())
+ return true;
+ }
- return false;
+ return false;
}
// +-------------------------------------------------------------------+
@@ -219,66 +219,66 @@ ModConfig::IsDeployed(const char* name)
void
ModConfig::Deploy()
{
- Save();
+ Save();
- if (enabled.size() < 1)
- return;
+ if (enabled.size() < 1)
+ return;
#ifdef STARSHATTER_DEMO_RELEASE
- Print("\nPACKAGED MODS ARE NOT SUPPORTED IN THIS DEMO\n");
+ Print("\nPACKAGED MODS ARE NOT SUPPORTED IN THIS DEMO\n");
#else
- Print("\nDEPLOYING MODS\n--------------\n");
-
- int i = 1;
- ListIter<Text> iter = enabled;
- while (++iter) {
- Text* name = iter.value();
-
- if (IsDeployed(name->data())) {
- Print(" %d. %s is already deployed (skipping)\n", i++, name->data());
- continue;
- }
-
- Print(" %d. %s\n", i++, name->data());
-
- ModInfo* mod_info = new(__FILE__,__LINE__) ModInfo;
-
- if (mod_info->Load(name->data()) && mod_info->Enable()) {
- mods.append(mod_info);
- }
- else {
- Print(" Could not deploy '%s' - disabling\n", name->data());
-
- delete mod_info;
- iter.removeItem();
- disabled.append(name);
- }
- }
-
- Print("\n");
- Game::UseLocale(0);
+ Print("\nDEPLOYING MODS\n--------------\n");
+
+ int i = 1;
+ ListIter<Text> iter = enabled;
+ while (++iter) {
+ Text* name = iter.value();
+
+ if (IsDeployed(name->data())) {
+ Print(" %d. %s is already deployed (skipping)\n", i++, name->data());
+ continue;
+ }
+
+ Print(" %d. %s\n", i++, name->data());
+
+ ModInfo* mod_info = new(__FILE__,__LINE__) ModInfo;
+
+ if (mod_info->Load(name->data()) && mod_info->Enable()) {
+ mods.append(mod_info);
+ }
+ else {
+ Print(" Could not deploy '%s' - disabling\n", name->data());
+
+ delete mod_info;
+ iter.removeItem();
+ disabled.append(name);
+ }
+ }
+
+ Print("\n");
+ Game::UseLocale(0);
#endif
}
void
ModConfig::Undeploy()
{
- Print("UNDEPLOYING MODS\n");
- mods.destroy();
+ Print("UNDEPLOYING MODS\n");
+ mods.destroy();
- ShipDesign::ClearModCatalog();
- WeaponDesign::ClearModCatalog();
+ ShipDesign::ClearModCatalog();
+ WeaponDesign::ClearModCatalog();
}
void
ModConfig::Redeploy()
{
- Undeploy();
- Deploy();
+ Undeploy();
+ Deploy();
- Campaign::Close();
- Campaign::Initialize();
- Campaign::SelectCampaign("Single Missions");
+ Campaign::Close();
+ Campaign::Initialize();
+ Campaign::SelectCampaign("Single Missions");
}
// +-------------------------------------------------------------------+
@@ -287,70 +287,70 @@ void
ModConfig::EnableMod(const char* name)
{
#ifdef STARSHATTER_DEMO_RELEASE
- DisableMod(name);
+ DisableMod(name);
#else
- if (!name || !*name)
- return;
-
- Text* mod_name;
-
- ListIter<Text> iter = disabled;
- while (++iter) {
- Text* t = iter.value();
-
- if (*t == name) {
- mod_name = t;
- iter.removeItem();
- break;
- }
- }
-
- if (mod_name) {
- enabled.append(mod_name);
-
- if (!IsDeployed(*mod_name)) {
- ModInfo* mod_info = new(__FILE__,__LINE__) ModInfo;
-
- if (mod_info->Load(*mod_name) && mod_info->Enable()) {
- mods.append(mod_info);
- }
- }
- }
+ if (!name || !*name)
+ return;
+
+ Text* mod_name;
+
+ ListIter<Text> iter = disabled;
+ while (++iter) {
+ Text* t = iter.value();
+
+ if (*t == name) {
+ mod_name = t;
+ iter.removeItem();
+ break;
+ }
+ }
+
+ if (mod_name) {
+ enabled.append(mod_name);
+
+ if (!IsDeployed(*mod_name)) {
+ ModInfo* mod_info = new(__FILE__,__LINE__) ModInfo;
+
+ if (mod_info->Load(*mod_name) && mod_info->Enable()) {
+ mods.append(mod_info);
+ }
+ }
+ }
#endif
}
void
ModConfig::DisableMod(const char* name)
{
- if (!name || !*name)
- return;
-
- Text* mod_name;
-
- ListIter<Text> iter = enabled;
- while (++iter) {
- Text* t = iter.value();
-
- if (*t == name) {
- mod_name = t;
- iter.removeItem();
- break;
- }
- }
-
- if (mod_name) {
- disabled.append(mod_name);
-
- ListIter<ModInfo> iter = mods;
- while (++iter) {
- ModInfo* mod_info = iter.value();
- if (mod_info->Name() == *mod_name) {
- delete iter.removeItem();
- break;
- }
- }
- }
+ if (!name || !*name)
+ return;
+
+ Text* mod_name;
+
+ ListIter<Text> iter = enabled;
+ while (++iter) {
+ Text* t = iter.value();
+
+ if (*t == name) {
+ mod_name = t;
+ iter.removeItem();
+ break;
+ }
+ }
+
+ if (mod_name) {
+ disabled.append(mod_name);
+
+ ListIter<ModInfo> iter = mods;
+ while (++iter) {
+ ModInfo* mod_info = iter.value();
+ if (mod_info->Name() == *mod_name) {
+ delete iter.removeItem();
+ break;
+ }
+ }
+ }
}
// +-------------------------------------------------------------------+
@@ -358,24 +358,24 @@ ModConfig::DisableMod(const char* name)
void
ModConfig::IncreaseModPriority(int mod_index)
{
- if (mod_index > 0 && mod_index < enabled.size()) {
- Text* mod1 = enabled.at(mod_index-1);
- Text* mod2 = enabled.at(mod_index);
+ if (mod_index > 0 && mod_index < enabled.size()) {
+ Text* mod1 = enabled.at(mod_index-1);
+ Text* mod2 = enabled.at(mod_index);
- enabled.at(mod_index-1) = mod2;
- enabled.at(mod_index) = mod1;
- }
+ enabled.at(mod_index-1) = mod2;
+ enabled.at(mod_index) = mod1;
+ }
}
void
ModConfig::DecreaseModPriority(int mod_index)
{
- if (mod_index >= 0 && mod_index < enabled.size()-1) {
- Text* mod1 = enabled.at(mod_index);
- Text* mod2 = enabled.at(mod_index+1);
+ if (mod_index >= 0 && mod_index < enabled.size()-1) {
+ Text* mod1 = enabled.at(mod_index);
+ Text* mod2 = enabled.at(mod_index+1);
- enabled.at(mod_index) = mod2;
- enabled.at(mod_index+1) = mod1;
- }
+ enabled.at(mod_index) = mod2;
+ enabled.at(mod_index+1) = mod1;
+ }
}