Skip to content

Commit 24dfe75

Browse files
committed
Add option to set the temp folder.
1 parent 74d1164 commit 24dfe75

File tree

6 files changed

+37
-20
lines changed

6 files changed

+37
-20
lines changed

Common/Cpp/Options/StringOption.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ StringCell::operator std::string() const{
7171
return m_data->m_current;
7272
}
7373
void StringCell::set(std::string x){
74+
sanitize(x);
7475
{
7576
WriteSpinLock lg(m_data->m_lock);
7677
if (m_data->m_current == x){

Common/Cpp/Options/StringOption.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class StringCell : public ConfigOption{
3838

3939
virtual ConfigWidget* make_QtWidget(QWidget& parent) override;
4040

41+
protected:
42+
virtual void sanitize(std::string& str){}
43+
4144
private:
4245
struct Data;
4346
Pimpl<Data> m_data;

SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,12 @@ GlobalSettings::GlobalSettings()
9696
"UserSettings/PA-Stats.txt",
9797
"UserSettings/PA-Stats.txt"
9898
)
99-
, ALL_STATS(
100-
"<b>All Stats:</b><br>Include all-time stats for notifications.",
101-
LockMode::UNLOCK_WHILE_RUNNING,
102-
true
99+
, TEMP_FOLDER(
100+
false,
101+
"<b>Temp Folder:</b><br>Place temporary files in this directory.",
102+
LockMode::LOCK_WHILE_RUNNING,
103+
"TempFiles/",
104+
"TempFiles/"
103105
)
104106
, WINDOW_SIZE(
105107
"Window Size:",
@@ -114,6 +116,11 @@ GlobalSettings::GlobalSettings()
114116
"online documentation"
115117
) + ")</font>"
116118
)
119+
, ALL_STATS(
120+
"<b>All Stats:</b><br>Include all-time stats for notifications.",
121+
LockMode::UNLOCK_WHILE_RUNNING,
122+
true
123+
)
117124
, m_advanced_options(
118125
"<font size=4><b>Advanced Options:</b> You should not need to touch anything below here.</font>"
119126
)
@@ -221,6 +228,7 @@ GlobalSettings::GlobalSettings()
221228
{
222229
PA_ADD_OPTION(CHECK_FOR_UPDATES);
223230
PA_ADD_OPTION(STATS_FILE);
231+
PA_ADD_OPTION(TEMP_FOLDER);
224232
PA_ADD_OPTION(ALL_STATS);
225233
PA_ADD_OPTION(THEME);
226234
PA_ADD_OPTION(WINDOW_SIZE);

SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ namespace PokemonAutomation{
3333

3434

3535

36+
class FolderInputOption : public StringOption{
37+
public:
38+
using StringOption::StringOption;
39+
40+
virtual void sanitize(std::string& str) override{
41+
if (!str.empty() && str.back() != '/'){
42+
str += '/';
43+
}
44+
}
45+
};
46+
3647

3748
struct DebugSettings{
3849
bool COLOR_CHECK = false;
@@ -74,7 +85,7 @@ class GlobalSettings : public BatchOption, private ConfigOption::Listener{
7485
BooleanCheckBoxOption CHECK_FOR_UPDATES;
7586

7687
StringOption STATS_FILE;
77-
BooleanCheckBoxOption ALL_STATS;
88+
FolderInputOption TEMP_FOLDER;
7889

7990
ThemeSelectorOption THEME;
8091
ResolutionOption WINDOW_SIZE;
@@ -83,6 +94,7 @@ class GlobalSettings : public BatchOption, private ConfigOption::Listener{
8394
SleepSuppressOptions SLEEP_SUPPRESS;
8495

8596
SectionDividerOption m_discord_settings;
97+
BooleanCheckBoxOption ALL_STATS;
8698
Integration::DiscordSettingsOption DISCORD;
8799

88100
SectionDividerOption m_advanced_options;

SerialPrograms/Source/CommonFramework/Notifications/MessageAttachment.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <QFile>
99
#include "Common/Cpp/PrettyPrint.h"
1010
#include "CommonFramework/Globals.h"
11+
#include "CommonFramework/GlobalSettingsPanel.h"
1112
#include "MessageAttachment.h"
1213

1314
namespace PokemonAutomation{
@@ -49,16 +50,6 @@ PendingFileSend::PendingFileSend(const std::string& file, bool keep_file)
4950
QFileInfo info(QString::fromStdString(file));
5051
m_filename = info.fileName().toStdString();
5152
}
52-
#if 0
53-
PendingFileSend::PendingFileSend(Logger& logger, const std::string& text_attachment)
54-
: m_keep_file(false)
55-
, m_extend_lifetime(false)
56-
, m_filename(now_to_filestring() + ".txt")
57-
, m_filepath("TempFiles/" + m_filename)
58-
{
59-
QFile file(QString::fromStdString(m_filepath));
60-
}
61-
#endif
6253
PendingFileSend::PendingFileSend(Logger& logger, const ImageAttachment& image)
6354
: m_keep_file(image.keep_file)
6455
, m_extend_lifetime(false)
@@ -88,9 +79,9 @@ PendingFileSend::PendingFileSend(Logger& logger, const ImageAttachment& image)
8879
if (image.keep_file){
8980
m_filepath = SCREENSHOTS_PATH() + m_filename;
9081
}else{
91-
QDir().mkdir("TempFiles");
92-
// m_filename = "temp-" + m_filename;
93-
m_filepath = "TempFiles/" + m_filename;
82+
m_filepath = GlobalSettings::instance().TEMP_FOLDER;
83+
QDir().mkdir(QString::fromStdString(m_filepath));
84+
m_filepath += m_filename;
9485
}
9586

9687
if (image.image.save(m_filepath)){

SerialPrograms/Source/CommonFramework/Recording/StreamRecorder.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ StreamRecording::StreamRecording(
4545
, m_buffer_limit(buffer_limit)
4646
, m_audio_samples_per_frame(audio_samples_per_frame)
4747
, m_start_time(start_time)
48-
, m_filename("TempFiles/" + now_to_filestring() + ".mp4")
48+
, m_filename(GlobalSettings::instance().TEMP_FOLDER)
4949
, m_state(State::STARTING)
5050
, m_last_drop(current_time())
5151
{
@@ -55,8 +55,10 @@ StreamRecording::StreamRecording(
5555
m_audio_format.setSampleFormat(QAudioFormat::Float);
5656

5757
#ifndef PA_STREAM_HISTORY_LOCAL_BUFFER
58-
QDir().mkdir("TempFiles");
58+
QDir().mkdir(QString::fromStdString(m_filename));
5959
#endif
60+
m_filename += now_to_filestring() + ".mp4";
61+
6062
start();
6163
}
6264
StreamRecording::~StreamRecording(){

0 commit comments

Comments
 (0)