Skip to content

Commit 1651911

Browse files
committed
v1.0.2
1 parent 83d3002 commit 1651911

9 files changed

Lines changed: 252 additions & 85 deletions

changelog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# v1.0.2
2+
3+
* added the option to export and import backups and fixed some code
4+
5+
# v1.0.1
6+
7+
* changed the geode version compatable with the mod
8+
9+
# v1.0.0
10+
11+
* Initial release

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"geode": "v2.0.0",
33
"gd": "2.204",
4-
"version": "v1.0.1",
4+
"version": "v1.0.2",
55
"id": "abb2k.backup",
66
"name": "Backup",
77
"developer": "abb2k",

src/BackupCell.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ bool BackupCell::init(std::string folderPath, BackupsLayer* _mainLayer, bool _au
3131
autos = _autos;
3232

3333
std::ifstream dataFile;
34-
std::string dataPath = folderPath + "\\Backup.dat";
34+
std::string dataPath = folderPath + "/Backup.dat";
3535
dataFile.open(dataPath);
3636

3737
if (dataFile){
@@ -162,7 +162,7 @@ void BackupCell::LoadBackup(CCObject* object){
162162
}
163163

164164
void BackupCell::EditBackup(CCObject* object){
165-
RenameBackupLayer::create(mainLayer, _folderPath)->show(mainLayer);
165+
RenameBackupLayer::create(mainLayer, this)->show(mainLayer);
166166
}
167167

168168
void BackupCell::OnSelectedStateChanged(CCObject* object){
@@ -180,11 +180,11 @@ void BackupCell::FLAlert_Clicked(FLAlertLayer* p0, bool p1){
180180
if (p1){
181181
std::string GDAPPDATAPATH = CCFileUtils::get()->getWritablePath();
182182
geode::Result<> res;
183-
res = geode::utils::file::writeString(GDAPPDATAPATH + "\\CCGameManager.dat", geode::utils::file::readString(_folderPath + "\\CCGameManager.dat").value());
184-
res = geode::utils::file::writeString(GDAPPDATAPATH + "\\CCGameManager2.dat", geode::utils::file::readString(_folderPath + "\\CCGameManager2.dat").value());
183+
res = geode::utils::file::writeString(GDAPPDATAPATH + "/CCGameManager.dat", geode::utils::file::readString(_folderPath + "/CCGameManager.dat").value());
184+
res = geode::utils::file::writeString(GDAPPDATAPATH + "/CCGameManager2.dat", geode::utils::file::readString(_folderPath + "/CCGameManager2.dat").value());
185185

186-
res = geode::utils::file::writeString(GDAPPDATAPATH + "\\CCLocalLevels.dat", geode::utils::file::readString(_folderPath + "\\CCLocalLevels.dat").value());
187-
res = geode::utils::file::writeString(GDAPPDATAPATH + "\\CCLocalLevels2.dat", geode::utils::file::readString(_folderPath + "\\CCLocalLevels2.dat").value());
186+
res = geode::utils::file::writeString(GDAPPDATAPATH + "/CCLocalLevels.dat", geode::utils::file::readString(_folderPath + "/CCLocalLevels.dat").value());
187+
res = geode::utils::file::writeString(GDAPPDATAPATH + "/CCLocalLevels2.dat", geode::utils::file::readString(_folderPath + "/CCLocalLevels2.dat").value());
188188

189189
geode::utils::game::restart();
190190
abort();

src/BackupsLayer.cpp

Lines changed: 100 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ bool BackupsLayer::init(float _w, float _h, const char* _spr){
4848
CloseButton->setPosition(-_w / 2.1f, _h / 2.1f);
4949

5050
//create backups dir if doesnt exist
51-
std::string fileName = "\\Backups";
52-
std::filesystem::create_directory(Mod::get()->getSaveDir().string() + fileName);
53-
BackupsDir = Mod::get()->getSaveDir().string() + fileName;
51+
geode::Result<> res = geode::utils::file::createDirectory(Mod::get()->getSaveDir() / "Backups");
52+
BackupsDir = Mod::get()->getSaveDir().string() + "/Backups";
5453

55-
fileName += "\\Auto-Backups";
56-
std::filesystem::create_directory(Mod::get()->getSaveDir().string() + fileName);
54+
res = geode::utils::file::createDirectory(Mod::get()->getSaveDir() / "Backups/Auto-Backups");
55+
res = file::createDirectory(Mod::get()->getSaveDir() / "Backups/Exports");
5756

5857

5958
//create the backups list
@@ -131,6 +130,17 @@ bool BackupsLayer::init(float _w, float _h, const char* _spr){
131130
modeButton->setPosition({164, 0});
132131
m_buttonMenu->addChild(modeButton);
133132

133+
//add import button
134+
auto importBSprite = CCSprite::createWithSpriteFrameName("GJ_downloadBtn_001.png");
135+
auto importButton = CCMenuItemSpriteExtra::create(
136+
importBSprite,
137+
nullptr,
138+
this,
139+
menu_selector(BackupsLayer::importBackup)
140+
);
141+
importButton->setPosition({208, 0});
142+
m_buttonMenu->addChild(importButton);
143+
134144
this->setKeypadEnabled(true);
135145
this->setTouchEnabled(true);
136146
this->setTouchPriority(10);
@@ -186,7 +196,7 @@ void BackupsLayer::RefreshBackupsList(){
186196
std::string noBUMessage;
187197

188198
if (displayingAutos){
189-
readBackups = file::readDirectory(BackupsDir + "\\Auto-Backups");
199+
readBackups = file::readDirectory(BackupsDir + "/Auto-Backups");
190200
titleLol = "Auto Backups";
191201
noBUMessage = "You don't have any\nAuto Backups";
192202
}
@@ -202,7 +212,7 @@ void BackupsLayer::RefreshBackupsList(){
202212

203213
std::string dataPath = readBackups.value()[i].string();
204214
std::string OriginCellPath = dataPath;
205-
dataPath += "\\Backup.dat";
215+
dataPath += "/Backup.dat";
206216
file.open(dataPath);
207217
if (file){
208218
BackupCell* cell = BackupCell::create(OriginCellPath, this, displayingAutos);
@@ -282,4 +292,87 @@ void BackupsLayer::changeViewMode(CCObject* object){
282292
addButton->setVisible(true);
283293
}
284294
RefreshBackupsList();
295+
}
296+
297+
void BackupsLayer::importBackup(CCObject* object){
298+
ghc::filesystem::path path;
299+
file::FilePickOptions options;
300+
options.defaultPath = Mod::get()->getSaveDir() / ("Backups/Exports");
301+
file::FilePickOptions::Filter filterlol;
302+
filterlol.description = "gdbackups";
303+
std::unordered_set<std::string> set = {"*.gdbackup","*.gdbackup","*.gdbackup","*.gdbackup"};
304+
filterlol.files = set;
305+
std::vector<file::FilePickOptions::Filter> filters = {
306+
filterlol
307+
};
308+
options.filters = filters;
309+
Result<ghc::filesystem::path> res = file::pickFile(file::PickMode::OpenFile, options);
310+
if (res){
311+
path = res.value();
312+
}
313+
else{
314+
return;
315+
}
316+
317+
if (path.extension() == ".gdbackup"){
318+
std::string st = file::readString(path).value();
319+
320+
std::vector<std::string> things;
321+
std::string tempString = "";
322+
for (int i = 0; i < st.size(); i++)
323+
{
324+
if (st[i] == '\n' && st[i + 1] == '<' && st[i + 2] == '>' && st[i + 3] == ';'){
325+
i += 3;
326+
tempString = tempString.substr(0, tempString.size()-1);
327+
things.push_back(tempString);
328+
tempString = "";
329+
}
330+
else{
331+
tempString += st[i];
332+
}
333+
}
334+
335+
auto creationTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
336+
const char* Time = std::ctime(&creationTime);
337+
std::string t = Time;
338+
339+
for (size_t i = 0; i < t.length(); i++)
340+
{
341+
if (t[i] == ':'){
342+
t[i] = '-';
343+
}
344+
if (t[i] == ' '){
345+
t[i] = '_';
346+
}
347+
}
348+
std::string mycurrDir = (Mod::get()->getSaveDir() / ("Backups/(Imported) -" + t)).string();
349+
mycurrDir = mycurrDir.substr(0, mycurrDir.size()-1);
350+
Result<> res = file::createDirectory(mycurrDir);
351+
352+
std::string filenames[] = {
353+
"/Backup.dat",
354+
"/CCGameManager.dat",
355+
"/CCGameManager2.dat",
356+
"/CCLocalLevels.dat",
357+
"/CCLocalLevels2.dat"
358+
};
359+
360+
for (int i = 0; i < things.size(); i++)
361+
{
362+
std::ofstream datfile(mycurrDir + filenames[i]);
363+
364+
datfile << things[i];
365+
366+
datfile.close();
367+
}
368+
369+
RefreshBackupsList();
370+
}
371+
else{
372+
FLAlertLayer::create(
373+
"Import Failed!",
374+
"Please choose a \".gdbackup\" file",
375+
"OK"
376+
)->show();
377+
}
285378
}

src/BackupsLayer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ class BackupsLayer : public FLAlertLayer, public FLAlertLayerProtocol {
4141
CCMenuItemSpriteExtra* addButton;
4242

4343
void changeViewMode(CCObject* object);
44+
45+
void importBackup(CCObject* object);
4446
};

src/CreateBackupLayer.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void CreateBackupLayer::show(CCNode* parent) {
9898
m_mainLayer->runAction(CCEaseElasticOut::create(CCScaleTo::create(0.6f, 1.1f), 0.5f));
9999
this->runAction(CCFadeTo::create(0.14f, 100));
100100

101-
auto readBackups = file::readDirectory(Mod::get()->getSaveDir().string() + "\\Backups\\Auto-Backups");
101+
auto readBackups = file::readDirectory(Mod::get()->getSaveDir() / "Backups/Auto-Backups");
102102

103103
parent->addChild(this);
104104
}
@@ -118,7 +118,7 @@ void CreateBackupLayer::DoneAndSave(CCObject* object){
118118
auto creationTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
119119
const char* Time = std::ctime(&creationTime);
120120
std::string t = Time;
121-
std::string fileName = "\\" + t;
121+
std::string fileName = "/" + t;
122122
for (size_t i = 0; i < fileName.length(); i++)
123123
{
124124
if (fileName[i] == ':'){
@@ -134,19 +134,19 @@ void CreateBackupLayer::DoneAndSave(CCObject* object){
134134

135135
std::string GDAPPDATAPATH = CCFileUtils::get()->getWritablePath();
136136

137-
std::string CCManagerPath = GDAPPDATAPATH + "\\CCGameManager.dat";
137+
std::string CCManagerPath = GDAPPDATAPATH + "/CCGameManager.dat";
138138
std::filesystem::copy(CCManagerPath, fullpath, std::filesystem::copy_options::overwrite_existing);
139139

140-
std::string CCManagerPath2 = GDAPPDATAPATH + "\\CCGameManager2.dat";
140+
std::string CCManagerPath2 = GDAPPDATAPATH + "/CCGameManager2.dat";
141141
std::filesystem::copy(CCManagerPath2, fullpath, std::filesystem::copy_options::overwrite_existing);
142142

143-
std::string CCLevelsPath = GDAPPDATAPATH + "\\CCLocalLevels.dat";
143+
std::string CCLevelsPath = GDAPPDATAPATH + "/CCLocalLevels.dat";
144144
std::filesystem::copy(CCLevelsPath, fullpath, std::filesystem::copy_options::overwrite_existing);
145145

146-
std::string CCLevelsPath2 = GDAPPDATAPATH + "\\CCLocalLevels2.dat";
146+
std::string CCLevelsPath2 = GDAPPDATAPATH + "/CCLocalLevels2.dat";
147147
std::filesystem::copy(CCLevelsPath2, fullpath, std::filesystem::copy_options::overwrite_existing);
148148

149-
std::string dataPath = fullpath + "\\Backup.dat";
149+
std::string dataPath = fullpath + "/Backup.dat";
150150
std::ofstream bkData (dataPath);
151151

152152
bkData << NameInput->getString().c_str() << std::endl;

src/RenameBackupLayer.cpp

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#include "RenameBackupLayer.h"
33
#include <BackupCell.h>
44

5-
RenameBackupLayer* RenameBackupLayer::create(BackupsLayer* _parentLayer, std::string cellBackupDir) {
5+
RenameBackupLayer* RenameBackupLayer::create(BackupsLayer* _parentLayer, BackupCell* cell) {
66
auto ret = new RenameBackupLayer();
7-
if (ret && ret->init(280, 97, _parentLayer, cellBackupDir, "GJ_square01.png")) {
7+
if (ret && ret->init(280, 97, _parentLayer, cell, "GJ_square01.png")) {
88
ret->autorelease();
99
} else {
1010
delete ret;
@@ -13,13 +13,13 @@ RenameBackupLayer* RenameBackupLayer::create(BackupsLayer* _parentLayer, std::st
1313
return ret;
1414
}
1515

16-
bool RenameBackupLayer::init(float _w, float _h, BackupsLayer* _parentLayer, std::string _cellBackupDir, const char* _spr){
16+
bool RenameBackupLayer::init(float _w, float _h, BackupsLayer* _parentLayer, BackupCell* cell, const char* _spr){
1717
//create window
1818
auto winSize = CCDirector::sharedDirector()->getWinSize();
1919
CCSize size = {_w, _h};
2020

2121
parentLayer = _parentLayer;
22-
cellBackupDir = _cellBackupDir;
22+
backupCell = cell;
2323

2424
if (!this->initWithColor({0, 0, 0, 105})) return false;
2525
m_mainLayer = CCLayer::create();
@@ -44,13 +44,22 @@ bool RenameBackupLayer::init(float _w, float _h, BackupsLayer* _parentLayer, std
4444
menu_selector(RenameBackupLayer::backButtonCallback)
4545
);
4646
CloseButton->setUserData(reinterpret_cast<void*>(this));
47-
4847
m_buttonMenu->addChild(CloseButton);
49-
5048
CloseButton->setPosition(-_w / 2.1f, _h / 2.1f);
5149
CloseButton->setZOrder(1);
5250

53-
CCLabelBMFont* Label = CCLabelBMFont::create("Rename Backup", "bigFont.fnt");
51+
//add export button
52+
auto exportBackupSprite = CCSprite::createWithSpriteFrameName("accountBtn_myLevels_001.png");
53+
auto exportBackupButton = CCMenuItemSpriteExtra::create(
54+
exportBackupSprite,
55+
nullptr,
56+
this,
57+
menu_selector(RenameBackupLayer::OnExport)
58+
);
59+
exportBackupButton->setPosition(_w / 2.1f, -_h / 2.1f);
60+
m_buttonMenu->addChild(exportBackupButton);
61+
62+
CCLabelBMFont* Label = CCLabelBMFont::create("Backup Settings", "bigFont.fnt");
5463
Label->setPosition({285, 193});
5564
Label->setScale(0.75f);
5665
m_mainLayer->addChild(Label);
@@ -103,6 +112,17 @@ void RenameBackupLayer::show(CCNode* parent) {
103112
parent->addChild(this);
104113
}
105114

115+
void RenameBackupLayer::OnExport(CCObject* object){
116+
exportAlert = FLAlertLayer::create(
117+
this,
118+
"Export Backup",
119+
"Do you want to export\n \"" + backupCell->Name + "\"?",
120+
"No",
121+
"Yes"
122+
);
123+
exportAlert->show();
124+
}
125+
106126
void RenameBackupLayer::keyBackClicked() {
107127
parentLayer->RefreshBackupsList();
108128
this->setKeyboardEnabled(false);
@@ -117,7 +137,7 @@ void RenameBackupLayer::DoneAndSave(CCObject* object){
117137
if (NameInput->getString() != ""){
118138
std::fstream file;
119139

120-
file.open(cellBackupDir + "\\Backup.dat");
140+
file.open(backupCell->_folderPath + "/Backup.dat");
121141

122142
if (!file.fail()){
123143
std::vector<std::string> lines;
@@ -131,7 +151,7 @@ void RenameBackupLayer::DoneAndSave(CCObject* object){
131151
if (0 <= lines.size()){
132152
std::ofstream fileW;
133153

134-
fileW.open(cellBackupDir + "\\Backup.dat");
154+
fileW.open(backupCell->_folderPath + "/Backup.dat");
135155

136156
if (!fileW.fail()){
137157
for (int i = 0; i < lines.size(); i++)
@@ -173,4 +193,31 @@ void RenameBackupLayer::DoneAndSave(CCObject* object){
173193
"Back"
174194
)->show();
175195
}
196+
}
197+
198+
void RenameBackupLayer::FLAlert_Clicked(FLAlertLayer* p0, bool p1){
199+
if (exportAlert == p0 && p1){
200+
Result<std::vector<ghc::filesystem::path>> readBackups;
201+
readBackups = file::readDirectory(backupCell->_folderPath);
202+
std::string currFileData = "";
203+
for (int i = 0; i < readBackups.value().size(); i++)
204+
{
205+
currFileData += file::readString(readBackups.value()[i]).value();
206+
currFileData += "\n<>;";
207+
}
208+
209+
std::ofstream exportFile(Mod::get()->getSaveDir() / ("Backups/Exports/" + backupCell->Name + ".gdbackup"));
210+
211+
exportFile << currFileData;
212+
213+
exportFile.close();
214+
215+
FLAlertLayer::create(
216+
"Exported!",
217+
backupCell->Name + " was exported to\n" + Mod::get()->getSaveDir().string() + "/Backups/Exports",
218+
"OK"
219+
)->show();
220+
221+
keyBackClicked();
222+
}
176223
}

0 commit comments

Comments
 (0)