WoW Addon Manager Client  0.0.1-alpha
A p2p World of Warcraft addon manager
settingsmanager.cpp
Go to the documentation of this file.
1 //
2 // Created by jordan on 12/24/19.
3 //
4 #include <json/json.h>
5 #include <boost/filesystem.hpp>
6 #include <string>
7 #include <iostream>
8 #include <fstream>
9 #include <ostream>
10 #include "settingsmanager.h"
11 #include "utils.h"
12 #include "mainwindow.h"
13 
14 
15 
17  auto file = std::fstream("settings.json");
18  this->settings_root["wow_path"] = this->get_base_wow_path();
19  this->m_retail_addons_path = this->m_base_wow_folder_path + "/_retail_/Interface/AddOns";
20  this->m_classic_addons_path = this->m_base_wow_folder_path + "/_classic_/Interface/AddOns";
21  this->m_ptr_addons_path = this->m_base_wow_folder_path + "/_ptr_/Interface/AddOns";
22  file << this->settings_root;
23  file.close();
24 }
25 
29 }
30 
32  return this->m_retail_addons_path;
33 }
34 
36  return this->m_base_wow_folder_path;
37 }
38 
39 void SettingsManager::set_base_wow_path(const std::string &path) {
40  this->m_base_wow_folder_path = path;
41 }
42 
44  if (boost::filesystem::exists("settings.json")) {
45  if (boost::filesystem::is_empty("settings.json")) {
46  this->settings_root["wow_path"] = "";
47  this->settings_root["first_time"] = true;
48  auto file = std::ofstream("settings.json");
49  file << this->settings_root;
50  }
51  else {
52  std::string content = read_file_to_string("settings.json");
53  this->settings_root = string_to_json(content);
54  this->m_base_wow_folder_path = this->settings_root["wow_path"].asString();
55  this->first_time = this->settings_root["first_time"].asBool();
56  this->set_wow_folder_paths();
57 
58  }
59  }
60  else {
61  auto file = std::ofstream("settings.json");
62  this->settings_root["wow_path"] = "";
63  this->settings_root["first_time"] = true;
64  file << this->settings_root;
65 
66  }
67 }
68 
70  boost::filesystem::create_directories("wam_files");
71  boost::filesystem::create_directories("wam_files/retail");
72  boost::filesystem::create_directories("wam_files/classic");
73  boost::filesystem::create_directories("wam_files/ptr");
74 }
SettingsManager::m_ptr_addons_path
std::string m_ptr_addons_path
Definition: settingsmanager.h:20
SettingsManager::m_retail_addons_path
std::string m_retail_addons_path
Definition: settingsmanager.h:18
read_file_to_string
std::string read_file_to_string(const std::string &path)
Definition: utils.cpp:7
SettingsManager::set_wow_folder_paths
void set_wow_folder_paths()
Definition: settingsmanager.cpp:16
utils.h
SettingsManager::SettingsManager
SettingsManager()
Definition: settingsmanager.cpp:26
SettingsManager::m_classic_addons_path
std::string m_classic_addons_path
Definition: settingsmanager.h:19
SettingsManager::settings_root
Json::Value settings_root
Definition: settingsmanager.h:31
SettingsManager::generate_folder_structure
static void generate_folder_structure()
Definition: settingsmanager.cpp:69
SettingsManager::get_retail_addons_path
std::string get_retail_addons_path() const
Definition: settingsmanager.cpp:31
settingsmanager.h
SettingsManager::generate_settings_file
void generate_settings_file()
Definition: settingsmanager.cpp:43
SettingsManager::get_base_wow_path
std::string get_base_wow_path() const
Definition: settingsmanager.cpp:35
SettingsManager::first_time
bool first_time
Definition: settingsmanager.h:24
SettingsManager::m_base_wow_folder_path
std::string m_base_wow_folder_path
Definition: settingsmanager.h:17
SettingsManager::set_base_wow_path
void set_base_wow_path(const std::string &path)
Definition: settingsmanager.cpp:39
string_to_json
Json::Value string_to_json(const std::string &string)
Definition: utils.cpp:15
mainwindow.h