55 */
66
77#include < QFile>
8+ #include < QDir>
89#include < QMessageBox>
910#include < QApplication>
1011#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
@@ -23,27 +24,27 @@ using std::endl;
2324
2425namespace PokemonAutomation {
2526
26- bool migrate_settings (Logger& logger, std::string file_name){
27- QFile root_file (QString::fromStdString (file_name));
27+ bool migrate_settings (Logger& logger, const std::string& file_name){
28+ QFile cur_dir_file (QString::fromStdString (file_name));
2829 QFile folder_file (QString::fromStdString (SETTINGS_PATH () + file_name));
2930
30- logger.log (" Checking settings configuration ..." );
31+ logger.log (" Checking if user setting JSON file need to be migrated ..." );
3132
32- if (!root_file .exists () && !folder_file.exists ()){
33- logger.log (" Clean install, nothing to do ." );
33+ if (!cur_dir_file .exists () && !folder_file.exists ()){
34+ logger.log (" Clean install, nothing to migrate ." );
3435 return true ;
3536 }
3637
37- if (!root_file .exists () && folder_file.exists ()){
38+ if (!cur_dir_file .exists () && folder_file.exists ()){
3839 logger.log (" Migrated, nothing to do." );
3940 return true ;
4041 }
4142
42- if (root_file .exists () && !folder_file.exists ()){
43- logger.log (" Migrating root file to the folder..." );
44- root_file .copy (folder_file.fileName ());
45- logger.log (" Renaming root file as backup..." );
46- root_file .rename (root_file .fileName () + " .bak" );
43+ if (cur_dir_file .exists () && !folder_file.exists ()){
44+ logger.log (" Migrating old setting file to the new folder..." );
45+ cur_dir_file .copy (folder_file.fileName ());
46+ logger.log (" Renaming old setting file as backup..." );
47+ cur_dir_file .rename (cur_dir_file .fileName () + " .bak" );
4748 logger.log (" Migrated." );
4849 QMessageBox box;
4950 box.setTextFormat (Qt::RichText);
@@ -58,29 +59,26 @@ bool migrate_settings(Logger& logger, std::string file_name){
5859 return true ;
5960 }
6061
61- if (root_file.exists () && folder_file.exists ()){
62- logger.log (" Two configs detected, showing prompt..." );
63- QMessageBox box;
64- box.setTextFormat (Qt::RichText);
65- box.critical (
66- nullptr ,
67- " Two settings files detected!" ,
68- QString::fromStdString (
69- " Detected two settings files at these locations:<br><br>" +
70- root_file.fileName ().toStdString () + " (versions 0.29 and older)<br>" +
71- folder_file.fileName ().toStdString () + " (version 0.30)" +
72- " <br><br>This probably happened because you used an early beta of v0.30.x which created a new settings file at the new location. "
73- " Please either delete or rename the file you do not want to use."
74- )
75- );
76- return false ;
77- }
78-
79- return true ;
62+ // last case: cur_dir_file.exists() && folder_file.exists()
63+ logger.log (" Two configs detected, showing prompt..." );
64+ QMessageBox box;
65+ box.setTextFormat (Qt::RichText);
66+ box.critical (
67+ nullptr ,
68+ " Two settings files detected!" ,
69+ QString::fromStdString (
70+ " Detected two settings files at these locations:<br><br>" +
71+ cur_dir_file.fileName ().toStdString () + " (versions 0.29 and older)<br>" +
72+ folder_file.fileName ().toStdString () + " (version 0.30)" +
73+ " <br><br>This probably happened because you used an early beta of v0.30.x which created a new "
74+ " settings file at the new location. Please either delete or rename the file you do not want to use."
75+ )
76+ );
77+ return false ;
8078}
8179
8280bool migrate_stats (Logger& logger){
83- logger.log (" Checking if stats should be migrated..." );
81+ logger.log (" Checking if stats file should be migrated..." );
8482
8583 std::string path = GlobalSettings::instance ().STATS_FILE ;
8684 if (path != " PA-Stats.txt" ){
@@ -90,25 +88,27 @@ bool migrate_stats(Logger& logger){
9088
9189 const std::string new_path = GlobalSettings::instance ().STATS_FILE .default_value ();
9290
93- QFile root_file (QString::fromStdString (path));
91+ // old location: current working directory
92+ QFile cur_dir_file (QString::fromStdString (path));
93+ // new location:
9494 QFile folder_file (QString::fromStdString (new_path));
9595
96- if (!root_file .exists () && !folder_file.exists ()){
97- logger.log (" Clean install, nothing to do ." );
96+ if (!cur_dir_file .exists () && !folder_file.exists ()){
97+ logger.log (" Clean install, nothing to migrate ." );
9898 return true ;
9999 }
100100
101- if (!root_file .exists () && folder_file.exists ()){
101+ if (!cur_dir_file .exists () && folder_file.exists ()){
102102 logger.log (" File migrated. Stats path in settings not updated. Updating..." );
103103 GlobalSettings::instance ().STATS_FILE .restore_defaults ();
104104 return true ;
105105 }
106106
107- if (root_file .exists () && !folder_file.exists ()){
108- logger.log (" Migrating root file to the folder..." );
109- root_file .copy (folder_file.fileName ());
110- logger.log (" Renaming root file as backup..." );
111- root_file .rename (root_file .fileName () + " .bak" );
107+ if (cur_dir_file .exists () && !folder_file.exists ()){
108+ logger.log (" Migrating old stats file to the folder..." );
109+ cur_dir_file .copy (folder_file.fileName ());
110+ logger.log (" Renaming old stats file as backup..." );
111+ cur_dir_file .rename (cur_dir_file .fileName () + " .bak" );
112112 GlobalSettings::instance ().STATS_FILE .restore_defaults ();
113113 logger.log (" Migrated." );
114114 QMessageBox box;
@@ -124,25 +124,22 @@ bool migrate_stats(Logger& logger){
124124 return true ;
125125 }
126126
127- if (root_file.exists () && folder_file.exists ()){
128- logger.log (" Two stats files detected, showing prompt..." );
129- QMessageBox box;
130- box.setTextFormat (Qt::RichText);
131- box.critical (
132- nullptr ,
133- " Two settings files detected!" ,
134- QString::fromStdString (
135- " Detected two stats files at these locations:<br><br>" +
136- root_file.fileName ().toStdString () + " (versions 0.29 and older)<br>" +
137- folder_file.fileName ().toStdString () + " (version 0.30)" +
138- " <br><br>This probably happened because you used an early beta of v0.30.x which created a new stats file at the new location. "
139- " Please either delete or rename the file you do not want to use."
140- )
141- );
142- return false ;
143- }
144-
145- return true ;
127+ // last case: cur_dir_file.exists() && folder_file.exists()
128+ logger.log (" Two stats files detected, showing prompt..." );
129+ QMessageBox box;
130+ box.setTextFormat (Qt::RichText);
131+ box.critical (
132+ nullptr ,
133+ " Two settings files detected!" ,
134+ QString::fromStdString (
135+ " Detected two stats files at these locations:<br><br>" +
136+ cur_dir_file.fileName ().toStdString () + " (versions 0.29 and older)<br>" +
137+ folder_file.fileName ().toStdString () + " (version 0.30)" +
138+ " <br><br>This probably happened because you used an early beta of v0.30.x which created a new stats file at the new location. "
139+ " Please either delete or rename the file you do not want to use."
140+ )
141+ );
142+ return false ;
146143}
147144
148145
@@ -198,6 +195,28 @@ void set_permissions(QObject& object){
198195}
199196
200197
198+ bool check_resource_folder (Logger& logger){
199+ QDir resources_folder (QString::fromStdString (RESOURCE_PATH ()));
200+ if (resources_folder.exists ()){
201+ logger.log (" Found Resource folder at " + RESOURCE_PATH ());
202+ return true ;
203+ }
204+ logger.log (" No Resources/ folder at " + RESOURCE_PATH ());
205+ QMessageBox box;
206+ box.setTextFormat (Qt::RichText);
207+ box.critical (
208+ nullptr ,
209+ " No Resources Folder!" ,
210+ QString::fromStdString (
211+ " No Resources Folder:<br><br>"
212+ " Make sure you download Resources folder from latest release at<br>"
213+ " https://github.com/PokemonAutomation/ComputerControl/releases/<br><br>"
214+ " The Resources folder is part of PA-SerialPrograms-[VERSION]-[DATE].zip<br><br>"
215+ " Extract the Resources folder from the zip file and place it at following path:<br><br>" + RESOURCE_PATH ()
216+ )
217+ );
218+ return false ;
219+ }
201220
202221
203222
0 commit comments