mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-20 23:21:20 +02:00
Add a config option for standard stream redirection to log files
Equivalent to the redirect command line option.
This commit is contained in:
@@ -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>();
|
||||
Client::Ref().Initialize();
|
||||
Client::Ref().SetRedirectStd(redirectStd);
|
||||
|
||||
explicitSingletons->saveRenderer = std::make_unique<SaveRenderer>();
|
||||
explicitSingletons->favorite = std::make_unique<Favorite>();
|
||||
|
@@ -33,6 +33,7 @@ private:
|
||||
std::optional<UpdateInfo> updateInfo;
|
||||
|
||||
bool firstRun;
|
||||
bool redirectStd = false;
|
||||
|
||||
std::vector<ByteString> 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;
|
||||
}
|
||||
};
|
||||
|
@@ -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();
|
||||
|
@@ -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();
|
||||
|
@@ -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++)
|
||||
|
@@ -69,5 +69,7 @@ public:
|
||||
void SetPerfectCircle(bool perfectCircle);
|
||||
bool GetMomentumScroll();
|
||||
void SetMomentumScroll(bool momentumScroll);
|
||||
bool GetRedirectStd();
|
||||
void SetRedirectStd(bool newRedirectStd);
|
||||
virtual ~OptionsModel();
|
||||
};
|
||||
|
@@ -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_)
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user