Commit f9708661 authored by Jan's avatar Jan

Moved Windows specific functions to separate file

parent 7048b62e
......@@ -73,101 +73,12 @@
#ifdef USE_OPENMP
#endif
#ifdef _WIN32
# include <windows.h>
# include <errhandlingapi.h>
#endif
/* ==========================================================
*
* Stackwalker code. Used to get a backtrace if OpenFlipper
* crashes under windows
*
* ==========================================================*/
#ifdef WIN32
#include "StackWalker/StackWalker.hh"
#include <fstream>
class StackWalkerToConsole : public StackWalker
{
protected:
virtual void OnOutput(LPCSTR szText) override
{
// Writes crash dump to .OpenFlipper config directory
std::ofstream crashFile;
QString crashName = OpenFlipper::Options::configDirStr() + QDir::separator() + "CrashDump.txt";
crashFile.open(crashName.toLatin1(),std::ios::out | std::ios::app);
crashFile << szText;
crashFile.close();
// Write crash dump to console as well
StackWalker::OnOutput(szText);
}
};
#include <Windows/windows-startup.hh>
#endif
/* ==========================================================
*
* Console for Windows to get additional output written via
* cerr, cout, ... that is not forwarded to log window
*
* ==========================================================*/
#ifdef WIN32
void connect_console()
{
FILE* check = freopen("CONIN$", "r", stdin);
if (check) {
std::cerr << "Error reopening stdin" << std::endl;
}
check = freopen("CONOUT$", "w", stdout);
if (check) {
std::cerr << "Error reopening stdout" << std::endl;
}
check = freopen("CONOUT$", "w", stderr);
if (check) {
std::cerr << "Error reopening stderr" << std::endl;
}
std::cout.clear();
std::cerr.clear();
std::cin.clear();
std::wcout.clear();
std::wcerr.clear();
std::wcin.clear();
}
void attachConsole()
{
//try to attach the console of the parent process
if (AttachConsole(-1))
{
//if the console was attached change stdinput and output
connect_console();
}
else
{
//create and attach a new console if needed
#ifndef NDEBUG
//always open a console in debug mode
AllocConsole();
connect_console();
return;
#endif
if (OpenFlipper::Options::logToConsole())
{
AllocConsole();
connect_console();
}
}
}
#endif
/* ==========================================================
*
......
#ifdef WIN32
# include <windows.h>
# include <errhandlingapi.h>
/* ==========================================================
*
* Stackwalker code. Used to get a backtrace if OpenFlipper
* crashes under windows
*
* ==========================================================*/
#include "StackWalker/StackWalker.hh"
#include <fstream>
class StackWalkerToConsole : public StackWalker
{
protected:
virtual void OnOutput(LPCSTR szText) override
{
// Writes crash dump to .OpenFlipper config directory
std::ofstream crashFile;
QString crashName = OpenFlipper::Options::configDirStr() + QDir::separator() + "CrashDump.txt";
crashFile.open(crashName.toLatin1(),std::ios::out | std::ios::app);
crashFile << szText;
crashFile.close();
// Write crash dump to console as well
StackWalker::OnOutput(szText);
}
};
/* ==========================================================
*
* Console for Windows to get additional output written via
* cerr, cout, ... that is not forwarded to log window
*
* ==========================================================*/
void connect_console()
{
FILE* check = freopen("CONIN$", "r", stdin);
if (check) {
std::cerr << "Error reopening stdin" << std::endl;
}
check = freopen("CONOUT$", "w", stdout);
if (check) {
std::cerr << "Error reopening stdout" << std::endl;
}
check = freopen("CONOUT$", "w", stderr);
if (check) {
std::cerr << "Error reopening stderr" << std::endl;
}
std::cout.clear();
std::cerr.clear();
std::cin.clear();
std::wcout.clear();
std::wcerr.clear();
std::wcin.clear();
}
void attachConsole()
{
//try to attach the console of the parent process
if (AttachConsole(-1))
{
//if the console was attached change stdinput and output
connect_console();
}
else
{
//create and attach a new console if needed
#ifndef NDEBUG
//always open a console in debug mode
AllocConsole();
connect_console();
return;
#endif
if (OpenFlipper::Options::logToConsole())
{
AllocConsole();
connect_console();
}
}
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment