Skip to content

Commit 85f31fe

Browse files
authored
avoid corrupt dumps by creating new files instead of appending, … (#77)
1 parent bb4e0ae commit 85f31fe

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

include/DMDUtil/Config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class DMDUTILAPI Config
5555
void SetShowNotColorizedFrames(bool showNotColorizedFrames) { m_showNotColorizedFrames = showNotColorizedFrames; }
5656
bool IsDumpNotColorizedFrames() const { return m_dumpNotColorizedFrames; }
5757
void SetDumpNotColorizedFrames(bool dumpNotColorizedFrames) { m_dumpNotColorizedFrames = dumpNotColorizedFrames; }
58+
bool IsDumpFrames() const { return m_dumpFrames; }
59+
void SetDumpFrames(bool dumpFrames) { m_dumpFrames = dumpFrames; }
60+
void SetDumpPath(const char* path) { m_dumpPath = path; }
61+
const char* GetDumpPath() const { return m_dumpPath.c_str(); }
5862
bool IsFilterTransitionalFrames() const { return m_filterTransitionalFrames; }
5963
void SetFilterTransitionalFrames(bool filterTransitionalFrames)
6064
{
@@ -107,6 +111,8 @@ class DMDUTILAPI Config
107111
int m_framesToSkip;
108112
bool m_showNotColorizedFrames;
109113
bool m_dumpNotColorizedFrames;
114+
bool m_dumpFrames;
115+
std::string m_dumpPath;
110116
bool m_filterTransitionalFrames;
111117
bool m_zedmd;
112118
std::string m_zedmdDevice;

include/DMDUtil/DMD.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ class DMDUTILAPI DMD
183183
void AdjustRGB24Depth(uint8_t* pData, uint8_t* pDstData, int length, uint8_t* palette, uint8_t depth);
184184
void HandleTrigger(uint16_t id);
185185
void QueueSerumFrames(Update* dmdUpdate, bool render32 = true, bool render64 = true);
186+
void GenerateRandomSuffix(char* buffer, size_t length);
186187

187188
void DmdFrameThread();
188189
void LevelDMDThread();
@@ -197,6 +198,7 @@ class DMDUTILAPI DMD
197198
char m_romName[DMDUTIL_MAX_NAME_SIZE] = {0};
198199
char m_altColorPath[DMDUTIL_MAX_PATH_SIZE] = {0};
199200
char m_pupVideosPath[DMDUTIL_MAX_PATH_SIZE] = {0};
201+
char m_dumpPath[DMDUTIL_MAX_PATH_SIZE] = {0};
200202
AlphaNumeric* m_pAlphaNumeric;
201203
SerumFrameStruct* m_pSerum;
202204
ZeDMD* m_pZeDMD;

src/Config.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Config::Config()
2525
m_framesToSkip = 0;
2626
m_showNotColorizedFrames = false;
2727
m_dumpNotColorizedFrames = false;
28+
m_dumpFrames = false;
2829
m_filterTransitionalFrames = false;
2930
m_zedmd = true;
3031
m_zedmdDevice.clear();
@@ -44,6 +45,7 @@ void Config::parseConfigFile(const char* path)
4445
{
4546
inih::INIReader r{path};
4647

48+
// DMDServer
4749
SetDMDServerAddr(r.Get<std::string>("DMDServer", "Addr", "localhost").c_str());
4850
SetDMDServerPort(r.Get<int>("DMDServer", "Port", 6789));
4951
SetAltColor(r.Get<bool>("DMDServer", "AltColor", true));
@@ -62,6 +64,15 @@ void Config::parseConfigFile(const char* path)
6264
// Pixelcade
6365
SetPixelcade(r.Get<bool>("Pixelcade", "Enabled", true));
6466
SetPixelcadeDevice(r.Get<std::string>("Pixelcade", "Device", "").c_str());
67+
// Serum
68+
SetIgnoreUnknownFramesTimeout(r.Get<int>("Serum", "IgnoreUnknownFramesTimeout", 0));
69+
SetMaximumUnknownFramesToSkip(r.Get<int>("Serum", "MaximumUnknownFramesToSkip", 0));
70+
SetShowNotColorizedFrames(r.Get<bool>("Serum", "ShowNotColorizedFrames", false));
71+
// Dump
72+
SetDumpNotColorizedFrames(r.Get<bool>("Dump", "DumpNotColorizedFrames", false));
73+
SetDumpFrames(r.Get<bool>("Dump", "DumpFrames", false));
74+
SetDumpPath(r.Get<std::string>("Dump", "DumpPath", "").c_str());
75+
SetFilterTransitionalFrames(r.Get<bool>("Dump", "FilterTransitionalFrames", false));
6576
}
6677

6778
} // namespace DMDUtil

src/DMD.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,18 @@ void DMD::AdjustRGB24Depth(uint8_t* pData, uint8_t* pDstData, int length, uint8_
14631463
}
14641464
}
14651465

1466+
void DMD::GenerateRandomSuffix(char* buffer, size_t length)
1467+
{
1468+
const char charset[] = "abcdefghijklmnopqrstuvwxyz0123456789";
1469+
size_t charsetSize = sizeof(charset) - 1; // exclude null terminator
1470+
1471+
for (size_t i = 0; i < length; ++i)
1472+
{
1473+
buffer[i] = charset[rand() % charsetSize];
1474+
}
1475+
buffer[length] = '\0';
1476+
}
1477+
14661478
void DMD::DumpDMDTxtThread()
14671479
{
14681480
char name[DMDUTIL_MAX_NAME_SIZE] = {0};
@@ -1522,9 +1534,19 @@ void DMD::DumpDMDTxtThread()
15221534

15231535
if (name[0] != '\0')
15241536
{
1525-
char filename[128];
1526-
snprintf(filename, DMDUTIL_MAX_NAME_SIZE + 5, "%s.txt", name);
1527-
f = fopen(filename, "a");
1537+
char filename[DMDUTIL_MAX_NAME_SIZE + 128 + 8 + 5];
1538+
char suffix[9]; // 8 chars + null terminator
1539+
GenerateRandomSuffix(suffix, 8);
1540+
if (m_dumpPath[0] == '\0') strcpy(m_dumpPath, Config::GetInstance()->GetDumpPath());
1541+
if (m_dumpPath[strlen(m_dumpPath) - 1] == '/' || m_dumpPath[strlen(m_dumpPath) - 1] == '\\')
1542+
{
1543+
snprintf(filename, sizeof(filename), "%s%s-%s.txt", m_dumpPath, name, suffix);
1544+
}
1545+
else
1546+
{
1547+
snprintf(filename, sizeof(filename), "%s/%s-%s.txt", m_dumpPath, name, suffix);
1548+
}
1549+
f = fopen(filename, "w");
15281550
update = true;
15291551
memset(renderBuffer, 0, 2 * 256 * 64);
15301552
passed[0] = passed[1] = 0;

0 commit comments

Comments
 (0)