Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

Commit

Permalink
Added cheats deletion and opt-in instructions download
Browse files Browse the repository at this point in the history
  • Loading branch information
HamletDuFromage committed Apr 10, 2020
1 parent b5629c5 commit e3c6c65
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -45,7 +45,7 @@ INCLUDES := include libs/minizip/include
#ROMFS := romfs
APP_TITLE := Cheats Updater
APP_AUTHOR := HamletDuFromage
APP_VERSION := 1.0
APP_VERSION := 1.1

#---------------------------------------------------------------------------------
# options for code generation
Expand Down
5 changes: 3 additions & 2 deletions include/extract.hpp
Expand Up @@ -11,6 +11,7 @@
#include <iterator>
#include <string.h>
#include <stdio.h>
#include <filesystem>

#include <unzipper.h>

Expand All @@ -23,9 +24,9 @@ std::vector<std::string> getInstalledTitles();

std::string formatApplicationId(u64 ApplicationId);

int extractCheats(std::string zipPath, std::vector<std::string> titles, bool sxos);
int extractCheats(std::string zipPath, std::vector<std::string> titles, bool sxos, bool credits);

int isSXOS();
int removeCheats(bool sxos);

struct caselessCompare;

Expand Down
81 changes: 32 additions & 49 deletions source/extract.cpp
Expand Up @@ -47,7 +47,7 @@ struct caselessCompare {
}
};

int extractCheats(std::string zipPath, std::vector<std::string> titles, bool sxos){
int extractCheats(std::string zipPath, std::vector<std::string> titles, bool sxos, bool credits){
zipper::Unzipper unzipper(zipPath);
std::vector<zipper::ZipEntry> entries = unzipper.entries();

Expand Down Expand Up @@ -80,7 +80,14 @@ int extractCheats(std::string zipPath, std::vector<std::string> titles, bool sxo
parents.push_back(entriesNames[k]);
k++;
while(entriesNames[k].length() != (size_t) (offset + 17) && k < entriesNames.size()){
tempChildren.push_back(entriesNames[k]);
if(credits == false){
if(strcasecmp(entriesNames[k].substr(offset + 16, 7).c_str(), "/cheats") == 0){
tempChildren.push_back(entriesNames[k]);
}
}
else{
tempChildren.push_back(entriesNames[k]);
}
k++;
}
children.push_back(tempChildren);
Expand All @@ -93,6 +100,7 @@ int extractCheats(std::string zipPath, std::vector<std::string> titles, bool sxo

std::cout << "\033[4;31m"<< "\n*** Extracting cheats (this may take a while) ***" << "\033[0m" <<std::endl;

int count = 0;
size_t lastL = 0;
for(size_t j = 0; j < titles.size(); j++){
for(size_t l = lastL; l < parents.size(); l++){
Expand All @@ -102,6 +110,7 @@ int extractCheats(std::string zipPath, std::vector<std::string> titles, bool sxo
unzipper.extractEntry(e);
std::cout << std::setfill(' ') << std::setw(80) << '\r';
std::cout << e.substr(0, 79) << "\r";
count++;
consoleUpdate(NULL);
}
lastL = l;
Expand All @@ -112,55 +121,29 @@ int extractCheats(std::string zipPath, std::vector<std::string> titles, bool sxo
std::cout << std::endl;

unzipper.close();
return parents.size();
return count;
}


/*
int extractCheats(std::string zipPath, std::vector<std::string> titles){
zipper::Unzipper unzipper(zipPath);
std::vector<zipper::ZipEntry> entries = unzipper.entries();
std::cout << "Found " << entries.size() << " entries" << std::endl;
std::vector<std::string> entriesNames;
std::vector<int> parentIndexes;
for (auto& e : entries){
if (e.name.size() == 24){
entriesNames.push_back(e.name.substr(7, 16)); // 16 + titles
//std :: cout << e.name.substr(7, 22) << std::endl;
}
int removeCheats(bool sxos){
std::string path;
if(sxos){
path = std::string(SXOS_PATH) + std::string(TITLES_PATH);
std::filesystem::remove("./titles.zip");
}
//std::cout << entriesNames[0] << std::endl;
//std::cout << titles[0] << std::endl;
std::sort(entriesNames.begin(), entriesNames.end());
std::sort(titles.begin(), titles.end());
std::vector<std::string> v;
//(entriesNames.size() + titles.size());
//std::vector<std::string>::iterator it;
std::set_intersection(entriesNames.begin(), entriesNames.end(),
begin(titles), titles.end(),
std::back_inserter(v), caselessCompare());
//std::back_inserter(v));
//switch(IsSXOS()){
switch(0){
case 0:
for(auto& t : v){
//unzipper.extractEntry("titles/" + t + "/", "/atmosphere/contents/");}
unzipper.extractEntry("titles/" + t + "/", "./test/");
else{
path = std::string(AMS_PATH) + std::string(CONTENTS_PATH);
std::filesystem::remove("./contents.zip");
}
int c = 0;
for (const auto & entry : std::filesystem::directory_iterator(path)){
std::string cheatsPath = entry.path().string() + "/cheats";
if(std::filesystem::exists(cheatsPath)){
for (const auto & cheat : std::filesystem::directory_iterator(cheatsPath)){
std::filesystem::remove(cheat);
c++;
}
break;
case 1:
for(auto& t : v){
unzipper.extractEntry("titles/" + t + "/", "sxos/titles/");}
break;
std::filesystem::remove(cheatsPath);
}
}
//unzipper.extract("./test/");
unzipper.close();
return (int) v.size();
} */
return c;
}
27 changes: 24 additions & 3 deletions source/main.cpp
Expand Up @@ -8,7 +8,7 @@

#include <switch.h>

#define VERSION "1.0"
#define VERSION "1.1"
#define RELEASE_URL "https://github.com/HamletDuFromage/switch-cheats-db/releases/tag/v1.0"
#define ARCHIVE_URL "https://github.com/HamletDuFromage/switch-cheats-db/releases/download/v1.0/"

Expand Down Expand Up @@ -62,6 +62,8 @@ bool isServiceRunning(const char *serviceName) {
void run(){

bool sxos = !(isServiceRunning("dmnt:cht") && !(isServiceRunning("tx") && !isServiceRunning("rnx")));
u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
bool credits = kHeld & KEY_L;
std::string filename;
if(sxos){
filename = "titles.zip";
Expand Down Expand Up @@ -90,7 +92,7 @@ void run(){
else{
std::string url = std::string(ARCHIVE_URL) + filename;
if(downloadFile(url.c_str(), filename.c_str(), OFF)){
int upd = extractCheats(filename.c_str(), titles, sxos);
int upd = extractCheats(filename.c_str(), titles, sxos, credits);
std::cout << "Successfully extacted " << upd << " cheat files" << std::endl;
saveVersion("version.dat", ver);
}
Expand All @@ -101,13 +103,22 @@ void run(){
consoleUpdate(NULL);
}

void cleanUp(){
bool sxos = !(isServiceRunning("dmnt:cht") && !(isServiceRunning("tx") && !isServiceRunning("rnx")));
int c = removeCheats(sxos);
saveVersion("version.dat", "0");
std::cout << "Removed " << c << " cheat files" << std::endl;
}

int main(int argc, char* argv[])
{
initServices();

std::cout << "\033[1;31m" <<"Cheats Updater v" << VERSION << " by HamletDuFromage" << "\033[0m" <<std::endl;
std::cout << "Press [A] to download and update cheat files" << std::endl;
std::cout << "Press [+] to quit" << std::endl;
std::cout << "Hold [L] and press [A] to also download cheat credits and instructions" << std::endl;
std::cout << "Press [X] to delete all existing cheat files" << std::endl;
std::cout << "Press [+] to quit" << std::endl << std::endl;

consoleUpdate(NULL);

Expand All @@ -129,6 +140,16 @@ int main(int argc, char* argv[])
}
}

if (kDown & KEY_X){
if(!done){
cleanUp();
done = true;
std::cout << "\033[7;37m"<< "\nPress [+] to quit" << "\033[0m" <<std::endl;
consoleUpdate(NULL);

}
}

if (kDown & KEY_PLUS)
break;
}
Expand Down

0 comments on commit e3c6c65

Please sign in to comment.