Skip to content

Commit c84cbaf

Browse files
committed
csv idk maybe
1 parent d7046bc commit c84cbaf

2 files changed

Lines changed: 48 additions & 33 deletions

File tree

src/nodes/optionNodes/SaveOptions.cpp

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,6 @@ void SaveOptions::updateBackupsList(){
361361
}
362362

363363
void SaveOptions::onExport(CCObject*){
364-
saveToDT();
365-
}
366-
367-
void SaveOptions::onImport(CCObject*){
368-
ImportPopup::create()->show();
369-
}
370-
371-
void SaveOptions::saveToDT(){
372364
auto dtLayer = DTLayer::get();
373365
if (dtLayer == nullptr || dtLayer->m_MyLevelStats.isErr()) return;
374366

@@ -381,6 +373,12 @@ void SaveOptions::saveToDT(){
381373
.files = {
382374
"*.dt"
383375
}
376+
},
377+
file::FilePickOptions::Filter{
378+
.description = "CSV file",
379+
.files = {
380+
"*.csv"
381+
}
384382
}
385383
}
386384
}),
@@ -396,36 +394,53 @@ void SaveOptions::saveToDT(){
396394
if (!pickOpt.has_value()) return;
397395
auto pick = pickOpt.value();
398396

399-
pick = pick.replace_extension(".dt");
400-
401-
auto toZip = StatsManager::getSavesFolderPath() / dtLayer->m_MyLevelStats.unwrap().levelKey;
397+
auto source = StatsManager::getSavesFolderPath() / dtLayer->m_MyLevelStats.unwrap().levelKey;
402398

403-
auto zipFileRes = geode::utils::file::Zip::create(pick);
404-
if (zipFileRes.isErr()){
405-
Notification::create("Failed to create zip file!", NotificationIcon::Error)->show();
406-
log::error("{}", zipFileRes.unwrapErr());
399+
if (pick.extension() == ".csv"){
400+
saveToCSV(pick, source);
407401
return;
408402
}
409403

410-
auto zip = std::move(zipFileRes).unwrap();
404+
pick = pick.replace_extension(".dt");
411405

412-
for (const auto& entry : std::filesystem::directory_iterator(toZip)) {
413-
Result<> didFileWrite = Err("");
414-
415-
if (entry.path().filename() == "backups") continue;
406+
saveToDT(pick, source);
407+
}
408+
);
409+
}
416410

417-
if (std::filesystem::is_directory(entry)){
418-
didFileWrite = zip.addAllFrom(entry);
419-
}
420-
else {
421-
didFileWrite = zip.addFrom(entry);
422-
}
411+
void SaveOptions::onImport(CCObject*){
412+
ImportPopup::create()->show();
413+
}
423414

424-
if (didFileWrite.isErr()){
425-
Notification::create("Failed to write zip file!", NotificationIcon::Error)->show();
426-
return;
427-
}
428-
}
415+
void SaveOptions::saveToDT(std::filesystem::path const& pick, std::filesystem::path const& source){
416+
auto zipFileRes = geode::utils::file::Zip::create(pick);
417+
if (zipFileRes.isErr()){
418+
Notification::create("Failed to create zip file!", NotificationIcon::Error)->show();
419+
log::error("{}", zipFileRes.unwrapErr());
420+
return;
421+
}
422+
423+
auto zip = std::move(zipFileRes).unwrap();
424+
425+
for (const auto& entry : std::filesystem::directory_iterator(source)) {
426+
Result<> didFileWrite = Err("");
427+
428+
if (entry.path().filename() == "backups") continue;
429+
430+
if (std::filesystem::is_directory(entry)){
431+
didFileWrite = zip.addAllFrom(entry);
429432
}
430-
);
433+
else {
434+
didFileWrite = zip.addFrom(entry);
435+
}
436+
437+
if (didFileWrite.isErr()){
438+
Notification::create("Failed to write zip file!", NotificationIcon::Error)->show();
439+
return;
440+
}
441+
}
442+
}
443+
444+
void SaveOptions::saveToCSV(std::filesystem::path const& pick, std::filesystem::path const& source){
445+
431446
}

src/nodes/optionNodes/SaveOptions.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SaveOptions : public OptionsNode, public FLAlertLayerProtocol {
3131
void updateBackupsList();
3232

3333
async::TaskHolder<file::PickResult> filepicklistener;
34-
void saveToDT();
34+
void saveToDT(std::filesystem::path const& pick, std::filesystem::path const& source);
3535

3636
public:
3737
virtual void onOpened() override;

0 commit comments

Comments
 (0)