diff --git a/src/PowderToy.cpp b/src/PowderToy.cpp index 9f0424794..36cf4c354 100644 --- a/src/PowderToy.cpp +++ b/src/PowderToy.cpp @@ -379,7 +379,8 @@ int Main(int argc, char *argv[]) prefs.Set("Fullscreen", windowFrameOps.fullscreen); } - if (true_arg(arguments["redirect"])) + auto redirectStd = prefs.Get("RedirectStd", false); + if (true_arg(arguments["redirect"]) || redirectStd) { FILE *new_stdout = freopen("stdout.log", "w", stdout); FILE *new_stderr = freopen("stderr.log", "w", stderr); @@ -428,6 +429,7 @@ int Main(int argc, char *argv[]) explicitSingletons->client = std::make_unique(); Client::Ref().Initialize(); + Client::Ref().SetRedirectStd(redirectStd); explicitSingletons->saveRenderer = std::make_unique(); explicitSingletons->favorite = std::make_unique(); diff --git a/src/client/Client.h b/src/client/Client.h index c3beb6f7b..532ab9b5d 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -33,6 +33,7 @@ private: std::optional updateInfo; bool firstRun; + bool redirectStd = false; std::vector stampIDs; uint64_t lastStampTime = 0; @@ -104,4 +105,14 @@ public: void Tick(); String DoMigration(ByteString fromDir, ByteString toDir); + + bool GetRedirectStd() + { + return redirectStd; + } + + void SetRedirectStd(bool newRedirectStd) + { + redirectStd = newRedirectStd; + } }; diff --git a/src/gui/options/OptionsController.cpp b/src/gui/options/OptionsController.cpp index cd25ea798..62fc4c92f 100644 --- a/src/gui/options/OptionsController.cpp +++ b/src/gui/options/OptionsController.cpp @@ -162,6 +162,11 @@ void OptionsController::SetMomentumScroll(bool momentumScroll) model->SetMomentumScroll(momentumScroll); } +void OptionsController::SetRedirectStd(bool newRedirectStd) +{ + model->SetRedirectStd(newRedirectStd); +} + void OptionsController::Exit() { view->CloseActiveWindow(); diff --git a/src/gui/options/OptionsController.h b/src/gui/options/OptionsController.h index a9ea5a1b0..013088500 100644 --- a/src/gui/options/OptionsController.h +++ b/src/gui/options/OptionsController.h @@ -41,6 +41,7 @@ public: void SetIncludePressure(bool includePressure); void SetPerfectCircle(bool perfectCircle); void SetMomentumScroll(bool momentumScroll); + void SetRedirectStd(bool newRedirectStd); void Exit(); OptionsView * GetView(); diff --git a/src/gui/options/OptionsModel.cpp b/src/gui/options/OptionsModel.cpp index b721fdf85..a9bbee9f6 100644 --- a/src/gui/options/OptionsModel.cpp +++ b/src/gui/options/OptionsModel.cpp @@ -7,6 +7,7 @@ #include "common/clipboard/Clipboard.h" #include "gui/interface/Engine.h" #include "gui/game/GameModel.h" +#include "client/Client.h" OptionsModel::OptionsModel(GameModel * gModel_) { gModel = gModel_; @@ -338,6 +339,18 @@ void OptionsModel::SetMomentumScroll(bool state) notifySettingsChanged(); } +bool OptionsModel::GetRedirectStd() +{ + return Client::Ref().GetRedirectStd(); +} + +void OptionsModel::SetRedirectStd(bool newRedirectStd) +{ + GlobalPrefs::Ref().Set("RedirectStd", newRedirectStd); + Client::Ref().SetRedirectStd(newRedirectStd); + notifySettingsChanged(); +} + void OptionsModel::notifySettingsChanged() { for (size_t i = 0; i < observers.size(); i++) diff --git a/src/gui/options/OptionsModel.h b/src/gui/options/OptionsModel.h index 165717fef..c626ad030 100644 --- a/src/gui/options/OptionsModel.h +++ b/src/gui/options/OptionsModel.h @@ -69,5 +69,7 @@ public: void SetPerfectCircle(bool perfectCircle); bool GetMomentumScroll(); void SetMomentumScroll(bool momentumScroll); + bool GetRedirectStd(); + void SetRedirectStd(bool newRedirectStd); virtual ~OptionsModel(); }; diff --git a/src/gui/options/OptionsView.cpp b/src/gui/options/OptionsView.cpp index b1fe5bfaa..701e85116 100644 --- a/src/gui/options/OptionsView.cpp +++ b/src/gui/options/OptionsView.cpp @@ -354,6 +354,9 @@ OptionsView::OptionsView() : ui::Window(ui::Point(-1, -1), ui::Point(320, 340)) } currentY += 26; } + redirectStd = addCheckbox(0, "Save errors and other messages to a file", "Developers may ask for this when trying to fix problems", [this] { + c->SetRedirectStd(redirectStd->GetChecked()); + }); { addSeparator(); @@ -511,6 +514,7 @@ void OptionsView::NotifySettingsChanged(OptionsModel * sender) graveExitsConsole->SetChecked(sender->GetGraveExitsConsole()); threadedRendering->SetChecked(sender->GetThreadedRendering()); momentumScroll->SetChecked(sender->GetMomentumScroll()); + redirectStd->SetChecked(sender->GetRedirectStd()); } void OptionsView::AttachController(OptionsController * c_) diff --git a/src/gui/options/OptionsView.h b/src/gui/options/OptionsView.h index 15e0a6be2..aac0e1785 100644 --- a/src/gui/options/OptionsView.h +++ b/src/gui/options/OptionsView.h @@ -43,6 +43,7 @@ class OptionsView: public ui::Window ui::Checkbox *graveExitsConsole{}; ui::Checkbox *nativeClipoard{}; ui::Checkbox *threadedRendering{}; + ui::Checkbox *redirectStd{}; ui::ScrollPanel *scrollPanel{}; float customGravityX, customGravityY; void UpdateAmbientAirTempPreview(float airTemp, bool isValid);