-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from thearst3rd/autosplitter
Add support for autosplitters
- Loading branch information
Showing
9 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include <cstdio> | ||
|
||
#include "autosplitter.h" | ||
#include "platform/platform.h" | ||
|
||
|
||
Autosplitter *Autosplitter::smInstance = nullptr; | ||
|
||
void Autosplitter::init() | ||
{ | ||
if (smInstance) | ||
return; | ||
|
||
smInstance = new Autosplitter(); | ||
} | ||
|
||
void Autosplitter::destroy() | ||
{ | ||
if (!smInstance) | ||
return; | ||
|
||
delete smInstance; | ||
smInstance = nullptr; | ||
} | ||
|
||
Autosplitter *Autosplitter::get() | ||
{ | ||
if (!smInstance) | ||
init(); | ||
|
||
return smInstance; | ||
} | ||
|
||
Autosplitter::Autosplitter() | ||
{ | ||
mActive = false; | ||
mFilename = Platform::getPrefsPath(AUTOSPLITTER_FILE_NAME); | ||
mFile.open(mFilename, std::ios_base::app); | ||
if (!mFile.is_open()) | ||
{ | ||
Con::errorf("Failed to open autosplitter file %s.", mFilename); | ||
Con::errorf("Autosplitter is disabled."); | ||
return; | ||
} | ||
Con::printf("Autosplitter Initialized to file %s", mFilename.c_str()); | ||
mActive = true; | ||
} | ||
|
||
Autosplitter::~Autosplitter() | ||
{ | ||
mFile.close(); | ||
std::remove(mFilename.c_str()); | ||
} | ||
|
||
void Autosplitter::sendData(const char *data) | ||
{ | ||
if (!mActive) | ||
return; | ||
|
||
mFile << data << std::endl; | ||
} | ||
|
||
ConsoleFunction(sendAutosplitterData, void, 2, 2, "") | ||
{ | ||
Autosplitter *autosplitter = Autosplitter::get(); | ||
if (!autosplitter->isActive()) | ||
return; | ||
|
||
Con::printf("Sending autosplitter message '%s'", argv[1]); | ||
|
||
autosplitter->sendData(argv[1]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef _AUTOSPLITTER_H_ | ||
#define _AUTOSPLITTER_H_ | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
|
||
#include "console/console.h" | ||
|
||
constexpr const char *AUTOSPLITTER_FILE_NAME = "autosplitter.txt"; | ||
constexpr U32 AUTOSPLITTER_BUF_SIZE = 512; | ||
|
||
class Autosplitter | ||
{ | ||
public: | ||
static void init(); | ||
static void destroy(); | ||
static Autosplitter *get(); | ||
bool isActive() { return mActive; } | ||
void sendData(const char *data); | ||
private: | ||
Autosplitter(); | ||
~Autosplitter(); | ||
static Autosplitter *smInstance; | ||
bool mActive; | ||
std::string mFilename; | ||
std::fstream mFile; | ||
}; | ||
|
||
#endif // _AUTOSPLITTER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters