diff --git a/inc/ui/fm.h b/inc/ui/fm.h index 7a91af0..e9dcfac 100644 --- a/inc/ui/fm.h +++ b/inc/ui/fm.h @@ -4,7 +4,7 @@ namespace ui { void fmInit(); void fmExit(); - void fmPrep(const FsSaveDataType& _type, const std::string& _dev, bool _commit); + void fmPrep(const FsSaveDataType& _type, const std::string& _dev, const std::string& _baseSDMC, bool _commit); void fmUpdate(); void fmDraw(SDL_Texture *target); } diff --git a/src/fs/drive.cpp b/src/fs/drive.cpp index 224ddc1..ab6cade 100644 --- a/src/fs/drive.cpp +++ b/src/fs/drive.cpp @@ -17,6 +17,12 @@ void fs::driveInit() } else { + if(!cfg::driveAuthCode.empty() && fs::gDrive->hasToken()) + { + cfg::driveRefreshToken = fs::gDrive->getRefreshToken(); + cfg::saveConfig(); + } + fs::gDrive->loadDriveList("name = 'JKSV'"); if(!fs::gDrive->dirExists("JKSV")) diff --git a/src/gd.cpp b/src/gd.cpp index c52734e..fe55eb9 100644 --- a/src/gd.cpp +++ b/src/gd.cpp @@ -116,7 +116,6 @@ void drive::gd::exhangeAuthCode(const std::string& _authCode) postHeader = curl_slist_append(postHeader, HEADER_CONTENT_TYPE_APP_JSON); // Post json - std::string *postJson = new std::string; json_object *post = json_object_new_object(); json_object *clientIDString = json_object_new_string(clientID.c_str()); json_object *secretIDString = json_object_new_string(secretID.c_str()); @@ -128,7 +127,6 @@ void drive::gd::exhangeAuthCode(const std::string& _authCode) json_object_object_add(post, "code", authCodeString); json_object_object_add(post, "redirect_uri", redirectUriString); json_object_object_add(post, "grant_type", grantTypeString); - postJson->assign(json_object_to_json_string_ext(post, JSON_C_TO_STRING_NOSLASHESCAPE)); // Curl Request std::string *jsonResp = new std::string; @@ -139,8 +137,7 @@ void drive::gd::exhangeAuthCode(const std::string& _authCode) curl_easy_setopt(curl, CURLOPT_URL, tokenURL); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlFuncs::writeDataString); curl_easy_setopt(curl, CURLOPT_WRITEDATA, jsonResp); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postJson->c_str()); - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, postJson->length()); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json_object_get_string(post)); int error = curl_easy_perform(curl); @@ -161,7 +158,6 @@ void drive::gd::exhangeAuthCode(const std::string& _authCode) else writeCurlError("exchangeAuthCode", error); - delete postJson; delete jsonResp; json_object_put(post); json_object_put(respParse); @@ -176,7 +172,6 @@ void drive::gd::refreshToken() header = curl_slist_append(header, HEADER_CONTENT_TYPE_APP_JSON); // Post Json - std::string *jsonPost = new std::string; json_object *post = json_object_new_object(); json_object *clientIDString = json_object_new_string(clientID.c_str()); json_object *secretIDString = json_object_new_string(secretID.c_str()); @@ -186,7 +181,6 @@ void drive::gd::refreshToken() json_object_object_add(post, "client_secret", secretIDString); json_object_object_add(post, "refresh_token", refreshTokenString); json_object_object_add(post, "grant_type", grantTypeString); - jsonPost->assign(json_object_to_json_string(post)); // Curl std::string *jsonResp = new std::string; @@ -197,8 +191,7 @@ void drive::gd::refreshToken() curl_easy_setopt(curl, CURLOPT_URL, tokenURL); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlFuncs::writeDataString); curl_easy_setopt(curl, CURLOPT_WRITEDATA, jsonResp); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsonPost->c_str()); - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, jsonPost->length()); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json_object_get_string(post)); int error = curl_easy_perform(curl); json_object *parse = json_tokener_parse(jsonResp->c_str()); @@ -212,7 +205,6 @@ void drive::gd::refreshToken() writeDriveError("refreshToken", "Error refreshing token."); } - delete jsonPost; delete jsonResp; json_object_put(post); json_object_put(parse); @@ -362,7 +354,6 @@ bool drive::gd::createDir(const std::string& _dirName) postHeaders = curl_slist_append(postHeaders, HEADER_CONTENT_TYPE_APP_JSON); // JSON To Post - std::string *jsonPost = new std::string; json_object *post = json_object_new_object(); json_object *nameString = json_object_new_string(_dirName.c_str()); json_object *mimeTypeString = json_object_new_string(MIMETYPE_FOLDER); @@ -375,7 +366,6 @@ bool drive::gd::createDir(const std::string& _dirName) json_object_array_add(parentsArray, parentString); json_object_object_add(post, "parents", parentsArray); } - jsonPost->assign(json_object_to_json_string_ext(post, JSON_C_TO_STRING_NOSLASHESCAPE)); // Curl Request std::string *jsonResp = new std::string; @@ -386,8 +376,7 @@ bool drive::gd::createDir(const std::string& _dirName) curl_easy_setopt(curl, CURLOPT_URL, driveURL); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlFuncs::writeDataString); curl_easy_setopt(curl, CURLOPT_WRITEDATA, jsonResp); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsonPost->c_str()); - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, jsonPost->length()); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json_object_get_string(post)); int error = curl_easy_perform(curl); json_object *respParse = json_tokener_parse(jsonResp->c_str()), *checkError; @@ -408,7 +397,6 @@ bool drive::gd::createDir(const std::string& _dirName) else ret = false; - delete jsonPost; delete jsonResp; json_object_put(post); json_object_put(respParse); @@ -463,7 +451,6 @@ void drive::gd::uploadFile(const std::string& _filename, curlFuncs::curlUpArgs * postHeaders = curl_slist_append(postHeaders, HEADER_CONTENT_TYPE_APP_JSON); // Post JSON - std::string *jsonPost = new std::string; json_object *post = json_object_new_object(); json_object *nameString = json_object_new_string(_filename.c_str()); json_object_object_add(post, "name", nameString); @@ -474,7 +461,6 @@ void drive::gd::uploadFile(const std::string& _filename, curlFuncs::curlUpArgs * json_object_array_add(parentArray, parentString); json_object_object_add(post, "parents", parentArray); } - jsonPost->assign(json_object_to_json_string_ext(post, JSON_C_TO_STRING_NOSLASHESCAPE)); // Curl upload request std::string *jsonResp = new std::string; @@ -486,8 +472,7 @@ void drive::gd::uploadFile(const std::string& _filename, curlFuncs::curlUpArgs * curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, curlFuncs::writeHeaders); curl_easy_setopt(curl, CURLOPT_HEADERDATA, headers); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsonPost->c_str()); - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, jsonPost->length()); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json_object_get_string(post)); int error = curl_easy_perform(curl); std::string location = curlFuncs::getHeader("Location", headers); @@ -524,7 +509,6 @@ void drive::gd::uploadFile(const std::string& _filename, curlFuncs::curlUpArgs * else writeCurlError("uploadFile", error); - delete jsonPost; delete jsonResp; delete headers; json_object_put(post); diff --git a/src/ui/ext.cpp b/src/ui/ext.cpp index 3d7d445..d3aeed1 100644 --- a/src/ui/ext.cpp +++ b/src/ui/ext.cpp @@ -28,7 +28,7 @@ static inline void closeUserPanel() static void toFMSDtoSD(void *a) { - ui::fmPrep(FsSaveDataType_Account, "sdmc:/", false); + ui::fmPrep(FsSaveDataType_Account, "sdmc:/", "sdmc:/", false); closeUserPanel(); ui::changeState(FIL_MDE); } @@ -39,7 +39,7 @@ static void toFMProdInfoF(void *a) fsOpenBisFileSystem(&prodf, FsBisPartitionId_CalibrationFile, ""); fsdevMountDevice("prod-f", prodf); closeUserPanel(); - ui::fmPrep(FsSaveDataType_System, "prod-f:/", false); + ui::fmPrep(FsSaveDataType_System, "prod-f:/", "sdmc:/", false); ui::changeState(FIL_MDE); } @@ -49,7 +49,7 @@ static void toFMSafe(void *a) fsOpenBisFileSystem(&safe, FsBisPartitionId_SafeMode, ""); fsdevMountDevice("safe", safe); closeUserPanel(); - ui::fmPrep(FsSaveDataType_System, "safe:/", false); + ui::fmPrep(FsSaveDataType_System, "safe:/", "sdmc:/", false); ui::changeState(FIL_MDE); } @@ -59,7 +59,7 @@ static void toFMSystem(void *a) fsOpenBisFileSystem(&sys, FsBisPartitionId_System, ""); fsdevMountDevice("sys", sys); closeUserPanel(); - ui::fmPrep(FsSaveDataType_System, "sys:/", false); + ui::fmPrep(FsSaveDataType_System, "sys:/", "sdmc:/", false); ui::changeState(FIL_MDE); } @@ -69,7 +69,7 @@ static void toFMUser(void *a) fsOpenBisFileSystem(&user, FsBisPartitionId_User, ""); fsdevMountDevice("user", user); closeUserPanel(); - ui::fmPrep(FsSaveDataType_System, "user:/", false); + ui::fmPrep(FsSaveDataType_System, "user:/", "sdmc:/", false); ui::changeState(FIL_MDE); } @@ -109,7 +109,7 @@ static void extMenuMountSysSave(void *a) if(R_SUCCEEDED(fsOpen_SystemSaveData(&sys, FsSaveDataSpaceId_System, mountID, (AccountUid) {0}))) { fsdevMountDevice("sv", sys); - ui::fmPrep(FsSaveDataType_System, "sv:/", true); + ui::fmPrep(FsSaveDataType_System, "sv:/", "sdmc:/", true); ui::usrSelPanel->closePanel(); ui::changeState(FIL_MDE); } @@ -129,8 +129,8 @@ static void extMenuMountRomFS(void *a) if(R_SUCCEEDED(fsOpenDataFileSystemByCurrentProcess(&tromfs))) { fsdevMountDevice("tromfs", tromfs); - ui::fmPrep(FsSaveDataType_System, "tromfs:/", false); - ui::usrSelPanel->closePanel(); + ui::fmPrep(FsSaveDataType_System, "tromfs:/", "sdmc:/", false); + ui::usrSelPanel->closePanel(); ui::changeState(FIL_MDE); } } diff --git a/src/ui/fld.cpp b/src/ui/fld.cpp index 099d1d0..180d7a2 100644 --- a/src/ui/fld.cpp +++ b/src/ui/fld.cpp @@ -239,12 +239,40 @@ static void fldFuncDriveDelete(void *a) //TODO static void fldFuncDriveRestore_t(void *a) { + threadInfo *t = (threadInfo *)a; + drive::gdDirItem *gdi = (drive::gdDirItem *)t->argPtr; + t->status->setStatus(ui::getUICString("threadStatusDownloadingFile", 0), gdi->name.c_str()); + fs::copyArgs *cpy = fs::copyArgsCreate("", "", "", NULL, NULL, false, false, 0); + cpy->prog->setMax(gdi->size); + cpy->prog->update(0); + t->argPtr = cpy; + t->drawFunc = fs::fileDrawFunc; + + curlFuncs::curlDlArgs dlFile; + dlFile.path = "sdmc:/tmp.zip"; + dlFile.size = gdi->size; + dlFile.o = &cpy->offset; + + fs::gDrive->downloadFile(gdi->id, &dlFile); + + unzFile tmp = unzOpen64("sdmc:/tmp.zip"); + fs::copyZipToDir(tmp, "sv:/", "sv", t); + unzClose(tmp); + fs::delfile("sdmc:/tmp.zip"); + + fs::copyArgsDestroy(cpy); + t->argPtr = NULL; + t->drawFunc = NULL; + + t->finished = true; } static void fldFuncDriveRestore(void *a) { - + drive::gdDirItem *in = (drive::gdDirItem *)a; + ui::confirmArgs *conf = ui::confirmArgsCreate(cfg::config["holdOver"], fldFuncDriveRestore_t, NULL, a, ui::getUICString("confirmRestore", 0), in->name.c_str()); + ui::confirm(conf); } void ui::fldInit() @@ -311,6 +339,7 @@ void ui::fldPopulateMenu() fldMenu->optAddButtonEvent(fldInd, HidNpadButton_A, fldFuncDownload, gdi); fldMenu->optAddButtonEvent(fldInd, HidNpadButton_X, fldFuncDriveDelete, gdi); + fldMenu->optAddButtonEvent(fldInd, HidNpadButton_Y, fldFuncDriveRestore, gdi); } } @@ -356,6 +385,7 @@ void ui::fldRefreshMenu(bool _updateDrive) fldMenu->optAddButtonEvent(fldInd, HidNpadButton_A, fldFuncDownload, gdi); fldMenu->optAddButtonEvent(fldInd, HidNpadButton_X, fldFuncDriveDelete, gdi); + fldMenu->optAddButtonEvent(fldInd, HidNpadButton_Y, fldFuncDriveRestore, gdi); } } diff --git a/src/ui/fm.cpp b/src/ui/fm.cpp index 357487e..353c496 100644 --- a/src/ui/fm.cpp +++ b/src/ui/fm.cpp @@ -159,6 +159,11 @@ static void _listFunctionA(void *a) m->optAddButtonEvent(i, HidNpadButton_A, _listFunctionA, ma); } +static void _copyMenuUpload(void *a) +{ + +} + static void _copyMenuCopy_t(void *a) { threadInfo *t = (threadInfo *)a; @@ -514,13 +519,13 @@ void ui::fmExit() delete sdmcArgs; } -void ui::fmPrep(const FsSaveDataType& _type, const std::string& _dev, bool _commit) +void ui::fmPrep(const FsSaveDataType& _type, const std::string& _dev, const std::string& _baseSDMC, bool _commit) { type = _type; dev = _dev; commit = _commit; devPath = _dev; - sdPath = "sdmc:/"; + sdPath = _baseSDMC; sdCopyMenu->editOpt(0, NULL, ui::getUIString("fileModeMenu", 0) + _dev); diff --git a/src/ui/ttl.cpp b/src/ui/ttl.cpp index a4eb598..4c4ea58 100644 --- a/src/ui/ttl.cpp +++ b/src/ui/ttl.cpp @@ -127,7 +127,9 @@ static void ttlOptsToFileMode(void *a) data::userTitleInfo *d = data::getCurrentUserTitleInfo(); if(fs::mountSave(d->saveInfo)) { - ui::fmPrep((FsSaveDataType)d->saveInfo.save_data_type, "sv:/", true); + data::userTitleInfo *utinfo = data::getCurrentUserTitleInfo(); + std::string sdmcPath = util::generatePathByTID(utinfo->tid); + ui::fmPrep((FsSaveDataType)d->saveInfo.save_data_type, "sv:/", sdmcPath, true); ui::usrSelPanel->closePanel(); ui::ttlOptsPanel->closePanel(); ui::changeState(FIL_MDE);