Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenFlipper-Free
OpenFlipper
Commits
f9708661
Commit
f9708661
authored
May 27, 2020
by
Jan
Browse files
Moved Windows specific functions to separate file
parent
7048b62e
Changes
2
Hide whitespace changes
Inline
Side-by-side
OpenFlipper.cc
View file @
f9708661
...
...
@@ -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
/* ==========================================================
*
...
...
Windows/windows-startup.hh
0 → 100644
View file @
f9708661
#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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment