Skip to content

Commit 7f0b0ea

Browse files
committed
Remove empty folders when deactivating mods, code cleanup
1 parent 08ef302 commit 7f0b0ea

File tree

6 files changed

+47
-26
lines changed

6 files changed

+47
-26
lines changed

modules/ModManager.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,12 @@ void ModManager::ActivateButton_isPressed() {
142142
(ModUniqueFolderPath / relative_path.parent_path()));
143143
}
144144
if (std::filesystem::exists(ModInstallPath / "dvdroot_ps4" / relative_path)) {
145+
145146
std::filesystem::copy_file(ModInstallPath / "dvdroot_ps4" / relative_path,
146147
(ModBackupFolderPath / relative_path),
147148
std::filesystem::copy_options::overwrite_existing);
148149
} else {
150+
149151
std::filesystem::copy_file(ModSourcePath / relative_path,
150152
(ModUniqueFolderPath / relative_path),
151153
std::filesystem::copy_options::overwrite_existing);
@@ -291,6 +293,22 @@ void ModManager::DeactivateButton_isPressed() {
291293
}
292294
}
293295

296+
std::filesystem::path dir_path;
297+
std::vector<std::filesystem::path> directories;
298+
for (auto& p : std::filesystem::recursive_directory_iterator(ModInstallPath / "dvdroot_ps4")) {
299+
dir_path = p.path();
300+
if (std::filesystem::is_directory(p)) {
301+
directories.push_back(std::filesystem::canonical(dir_path));
302+
}
303+
}
304+
305+
for (std::vector<std::filesystem::path>::reverse_iterator rit = directories.rbegin();
306+
rit != directories.rend(); ++rit) {
307+
if (std::filesystem::is_empty(*rit)) {
308+
std::filesystem::remove(*rit);
309+
}
310+
}
311+
294312
ui->progressBar->setValue(0);
295313
ui->FileTransferLabel->setText("Moving backup to Install Folder");
296314
ui->progressBar->setMaximum(getFileCount(ModBackupFolderPath));
@@ -299,6 +317,11 @@ void ModManager::DeactivateButton_isPressed() {
299317
auto relative_path = std::filesystem::relative(entry, ModBackupFolderPath);
300318
if (!entry.is_directory()) {
301319
try {
320+
if (!std::filesystem::exists(ModInstallPath / "dvdroot_ps4" /
321+
relative_path.parent_path())) {
322+
std::filesystem::create_directories(ModInstallPath / "dvdroot_ps4" /
323+
relative_path.parent_path());
324+
}
302325
std::filesystem::rename(ModBackupFolderPath / relative_path,
303326
ModInstallPath / "dvdroot_ps4" / relative_path);
304327
} catch (std::exception& ex) {

modules/ModManager.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ class ModManager;
99
}
1010

1111
const std::filesystem::path ModPath = std::filesystem::current_path() / "BBLauncher" / "Mods";
12-
const std::filesystem::path ModBackupPath =
13-
std::filesystem::current_path() / "BBLauncher" / "Mods-BACKUP";
14-
const std::filesystem::path ModUniquePath =
15-
std::filesystem::current_path() / "BBLauncher" / "Mods-BACKUP" / "Mods-UNIQUEFILES";
16-
const std::vector<std::string> BBFolders = {"dvdroot_ps4", "action", "chr", "event", "facegen",
17-
"map", "menu", "movie", "msg", "mtd",
18-
"obj", "other", "param", "paramdef", "parts",
19-
"remo", "script", "sfx", "shader", "sound"};
2012

2113
class ModManager : public QDialog {
2214
Q_OBJECT
@@ -41,4 +33,13 @@ private slots:
4133
void ConflictAdd(std::string ModName);
4234
void ConflictRemove(std::string ModName);
4335
std::string PathToU8(const std::filesystem::path& path);
36+
37+
const std::filesystem::path ModBackupPath =
38+
std::filesystem::current_path() / "BBLauncher" / "Mods-BACKUP";
39+
const std::filesystem::path ModUniquePath =
40+
std::filesystem::current_path() / "BBLauncher" / "Mods-BACKUP" / "Mods-UNIQUEFILES";
41+
const std::vector<std::string> BBFolders = {
42+
"dvdroot_ps4", "action", "chr", "event", "facegen", "map", "menu",
43+
"movie", "msg", "mtd", "obj", "other", "param", "paramdef",
44+
"parts", "remo", "script", "sfx", "shader", "sound"};
4445
};

modules/bblauncher.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ BBLauncher::BBLauncher(QWidget* parent) : QMainWindow(parent), ui(new Ui::BBLaun
2525
this->setFixedSize(this->width(), this->height());
2626
this->statusBar()->setSizeGripEnabled(false);
2727
QApplication::setStyle("Fusion");
28+
setWindowTitle("BB Launcher Release 3.5");
2829

2930
// this->installEventFilter(this); if needed
3031

@@ -189,7 +190,7 @@ void BBLauncher::startShad() {
189190
[=](int exitCode, QProcess::ExitStatus exitStatus) { QApplication::quit(); });
190191
}
191192

192-
void StartBackupSave() {
193+
void BBLauncher::StartBackupSave() {
193194
const std::filesystem::path BackupPath =
194195
std::filesystem::current_path() / "BBLauncher" / "SaveBackups";
195196

modules/bblauncher.h

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,18 @@
66
#include <filesystem>
77
#include <QMainWindow>
88

9-
void PathToQString(QString& result, const std::filesystem::path& path);
10-
11-
QT_BEGIN_NAMESPACE
129
namespace Ui {
1310
class BBLauncher;
1411
}
15-
QT_END_NAMESPACE
1612

17-
const std::vector<std::string> BBSerialList = {"CUSA03173", "CUSA00900", "CUSA00208",
18-
"CUSA00207", "CUSA01363", "CUSA03023"};
13+
void PathToQString(QString& result, const std::filesystem::path& path);
14+
std::filesystem::path GetShadUserDir();
1915

20-
extern std::filesystem::path userPath;
2116
extern std::string game_serial;
2217
extern std::filesystem::path installPath;
2318
extern std::string installPathString;
2419
extern std::filesystem::path EbootPath;
2520

26-
void StartBackupSave();
27-
std::filesystem::path GetShadUserDir();
28-
2921
class BBLauncher : public QMainWindow {
3022
Q_OBJECT
3123

@@ -35,17 +27,21 @@ class BBLauncher : public QMainWindow {
3527
// bool eventFilter(QObject* obj, QEvent* event);
3628

3729
public slots:
38-
void UpdateSettingsList();
39-
void UpdateModList();
4030

4131
private slots:
4232
void ExeSelectButton_isPressed();
4333
void WIPButton_isPressed();
4434
void LaunchButton_isPressed();
45-
static void startShad();
4635
void SaveInstallLoc();
4736
void CheckBBInstall();
37+
void UpdateSettingsList();
38+
void UpdateModList();
39+
static void startShad();
4840

4941
private:
5042
Ui::BBLauncher* ui;
43+
static void StartBackupSave();
44+
45+
const std::vector<std::string> BBSerialList = {"CUSA03173", "CUSA00900", "CUSA00208",
46+
"CUSA00207", "CUSA01363", "CUSA03023"};
5147
};

settings/LauncherSettings.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ void LoadLauncherSettings();
1212
void CreateSettingsFile();
1313
void SetTheme(std::string theme);
1414

15-
const QStringList BackupNumList = {"1", "2", "3", "4", "5"};
16-
const QStringList BackupFreqList = {"5", "10", "15", "20", "25", "30"};
17-
1815
extern std::filesystem::path SettingsPath;
1916
extern std::filesystem::path SettingsFile;
2017

@@ -39,4 +36,7 @@ public slots:
3936
private:
4037
Ui::LauncherSettings* ui;
4138
void OnBackupStateChanged();
39+
40+
const QStringList BackupNumList = {"1", "2", "3", "4", "5"};
41+
const QStringList BackupFreqList = {"5", "10", "15", "20", "25", "30"};
4242
};

settings/ShadSettings.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</font>
2929
</property>
3030
<property name="windowTitle">
31-
<string>Settings</string>
31+
<string>shadPS4 Settings</string>
3232
</property>
3333
<property name="windowIcon">
3434
<iconset>

0 commit comments

Comments
 (0)