Skip to content

Commit

Permalink
move log file of dsn_plugin to <MyDocument>/DragonbornSpeaksNaturally
Browse files Browse the repository at this point in the history
  • Loading branch information
SwimmingTiger committed Jun 30, 2019
1 parent 8acf019 commit d53d336
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
35 changes: 30 additions & 5 deletions dsn_plugin/dsn_plugin/Log.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
#include "Log.h"
#include <sstream>
#include <fstream>
#include <windows.h>
#include <ShlObj.h>

static bool LOG_ENABLED = true;
Log* Log::instance = NULL;

Log::Log()
{
std::string baseDir = "";

{
CHAR myDocuments[MAX_PATH];
HRESULT result = SHGetFolderPathA(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, myDocuments);

if (result == S_OK) {
baseDir = std::string(myDocuments) + "/DragonbornSpeaksNaturally/";
// create dir
SHCreateDirectoryEx(NULL, baseDir.c_str(), NULL);
}
}

logFile.open(baseDir + "dragonborn_speaks.log", std::ios_base::out | std::ios_base::app);
if (!logFile) {
logEnabled = false;
}
}

Log::~Log()
{
logFile.close();
}

Log* Log::instance = NULL;
void Log::writeLine(std::string message)
{
if (!logEnabled) {
return;
}
logFile << message << std::endl;
logFile.flush();
}

Log* Log::get() {
if (!instance)
Expand All @@ -21,9 +48,7 @@ Log* Log::get() {
}

void Log::info(std::string message) {
std::ofstream log_file(
"dragonborn_speaks.log", std::ios_base::out | std::ios_base::app);
log_file << message << std::endl;
get()->writeLine(message);
}

void Log::address(std::string message, uintptr_t addr) {
Expand Down
13 changes: 10 additions & 3 deletions dsn_plugin/dsn_plugin/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
#include "common/IPrefix.h"
#include <cstdlib>
#include <string>
#include <fstream>

class Log
{
public:
static Log* get();
static Log* instance;

bool logEnabled = true;
std::ofstream logFile;

Log();
~Log();
static Log* instance;
void writeLine(std::string message);

public:
static Log* get();

static void info(std::string message);
static void address(std::string message, uintptr_t addr);
Expand Down

0 comments on commit d53d336

Please sign in to comment.