Skip to content

Commit

Permalink
truncate logs on launch
Browse files Browse the repository at this point in the history
  • Loading branch information
bakatrouble committed May 1, 2020
1 parent 1b3b5b5 commit 06bb98a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ set(APP_AUTHOR "bakatrouble")

set(VERSION_MAJOR 0)
set(VERSION_MINOR 0)
set(VERSION_MICRO 8)
set(VERSION_MICRO 10)
set(APP_VERSION
"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}")

Expand Down
2 changes: 2 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ default_destination = default
upload_screenshots = true
upload_movies = true

; keep_logs = true

; url = https://screenuploader.bakatrouble.me/upload/<destid>/
; do not change previous line unless you setup your own server!

Expand Down
5 changes: 5 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ bool Config::refresh() {
m_defaultDestID = reader.Get("server", "destination_id", "undefined");
m_uploadScreenshots = reader.GetBoolean("server", "upload_screenshots", true);
m_uploadMovies = reader.GetBoolean("server", "upload_movies", true);
m_keepLogs = reader.GetBoolean("server", "keep_logs", false);

if (reader.Sections().count("destinations") > 0) {
map<string, string> destinations;
Expand Down Expand Up @@ -101,3 +102,7 @@ bool Config::uploadAllowed(string &tid, bool isMovie) {
return m_uploadScreenshots;
}
}

bool Config::keepLogs() {
return m_keepLogs;
}
2 changes: 2 additions & 0 deletions src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ class Config {
string getUrl(string &tid);
string getUrlParams();
bool uploadAllowed(string &tid, bool isMovie);
bool keepLogs();

protected:
string m_url = "https://screenuploader.bakatrouble.me/upload/" + URLplaceholder + "/";
string m_defaultDestID;
bool m_uploadScreenshots;
bool m_uploadMovies;
bool m_keepLogs;
map<string, string> m_titleSettings;
map<string, bool> m_titleScreenshots;
map<string, bool> m_titleMovies;
Expand Down
22 changes: 16 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,28 @@ extern "C" {
}
}

static ofstream log;

void openLogFile(bool truncate) {
log = ofstream ("sdmc:/config/sys-screenuploader/screenuploader.log", truncate ? ios::trunc : ios::app);
cout.rdbuf(log.rdbuf());
cerr.rdbuf(log.rdbuf());
cout << "=============================" << endl << endl << endl;
cout << "ScreenUploader v" << APP_VERSION << " is starting..." << endl;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
int main(int argc, char **argv) {
mkdir("sdmc:/config", 0700);
mkdir("sdmc:/config/sys-screenuploader", 0700);
ofstream log("sdmc:/config/sys-screenuploader/screenuploader.log", ios::app);
cout.rdbuf(log.rdbuf());
cerr.rdbuf(log.rdbuf());

cout << "=============================" << endl << endl << endl;
cout << "ScreenUploader v" << APP_VERSION << " is starting..." << endl;
openLogFile(false);
Config conf = Config::load();
if (!conf.keepLogs()) {
log.close();
openLogFile(true);
}

Result rc;
CapsAlbumStorage storage;
Expand All @@ -137,7 +148,6 @@ int main(int argc, char **argv) {
}
cout << "Mounted " << (storage ? "SD" : "NAND") << " storage" << endl;

Config conf = Config::load();
string tmpItem, lastItem = getLastAlbumItem(conf);
cout << "Current last item: " << lastItem << endl;

Expand Down
4 changes: 2 additions & 2 deletions src/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#define APP_TITLE "screenuploader"
#define APP_AUTHOR "bakatrouble"
#define APP_VERSION "0.0.8"
#define APP_VERSION "0.0.10"
#define VERSION_MAJOR "0"
#define VERSION_MINOR "0"
#define VERSION_MICRO "8"
#define VERSION_MICRO "10"

#endif // INCLUDE_GUARD

0 comments on commit 06bb98a

Please sign in to comment.