mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-31 02:26:29 +03:00
More refactor.
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
namespace EE { namespace System {
|
||||
namespace eterm { namespace System {
|
||||
|
||||
// This class is designed to automatically free a resource handle when destructed
|
||||
class AutoHandle final {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace EE { namespace System {
|
||||
namespace eterm { namespace System {
|
||||
|
||||
class IPipe {
|
||||
public:
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
namespace EE { namespace System {
|
||||
namespace eterm { namespace System {
|
||||
|
||||
enum class ProcessStatus { RUNNING = 0, EXITED };
|
||||
|
||||
|
||||
@@ -28,9 +28,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace EE::Terminal;
|
||||
using namespace eterm::System;
|
||||
using namespace eterm::Terminal;
|
||||
|
||||
namespace EE { namespace System {
|
||||
namespace eterm { namespace System {
|
||||
|
||||
class IProcessFactory {
|
||||
public:
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <eterm/system/ipipe.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace EE { namespace System {
|
||||
namespace eterm { namespace System {
|
||||
|
||||
class Process;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <eterm/system/iprocess.hpp>
|
||||
#include <eterm/terminal/pseudoterminal.hpp>
|
||||
|
||||
namespace EE { namespace System {
|
||||
namespace eterm { namespace System {
|
||||
|
||||
class Process final : public IProcess {
|
||||
public:
|
||||
@@ -70,8 +70,9 @@ class Process final : public IProcess {
|
||||
bool mLeaveRunning{ false };
|
||||
AutoHandle mProcessHandle;
|
||||
void* mLpAttributeList;
|
||||
int mPID;
|
||||
|
||||
Process( AutoHandle&& processHandle, void* lpAttributeList );
|
||||
Process( AutoHandle&& processHandle, void* lpAttributeList, int pid );
|
||||
#else
|
||||
int mPID;
|
||||
|
||||
|
||||
@@ -23,9 +23,10 @@
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
#include <eterm/system/iprocessfactory.hpp>
|
||||
|
||||
using namespace EE::Terminal;
|
||||
using namespace eterm::System;
|
||||
using namespace eterm::Terminal;
|
||||
|
||||
namespace EE { namespace System {
|
||||
namespace eterm { namespace System {
|
||||
|
||||
class ProcessFactory : public IProcessFactory {
|
||||
public:
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
#include <eterm/system/ipipe.hpp>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace EE { namespace Terminal {
|
||||
namespace eterm { namespace Terminal {
|
||||
|
||||
class IPseudoTerminal : public EE::System::IPipe {
|
||||
class IPseudoTerminal : public eterm::System::IPipe {
|
||||
public:
|
||||
IPseudoTerminal() = default;
|
||||
|
||||
@@ -47,6 +47,6 @@ class IPseudoTerminal : public EE::System::IPipe {
|
||||
virtual bool resize( int columns, int rows ) = 0;
|
||||
};
|
||||
|
||||
}} // namespace EE::Terminal
|
||||
}} // namespace eterm::Terminal
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,7 +24,9 @@
|
||||
#include <eepp/config.hpp>
|
||||
#include <eterm/terminal/terminaltypes.hpp>
|
||||
|
||||
namespace EE { namespace Terminal {
|
||||
using namespace EE;
|
||||
|
||||
namespace eterm { namespace Terminal {
|
||||
|
||||
class TerminalEmulator;
|
||||
|
||||
@@ -87,6 +89,6 @@ class ITerminalDisplay {
|
||||
virtual void onProcessExit( int exitCode );
|
||||
};
|
||||
|
||||
}} // namespace EE::Terminal
|
||||
}} // namespace eterm::Terminal
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,15 +27,14 @@
|
||||
#include <memory>
|
||||
|
||||
using namespace EE::Math;
|
||||
using namespace eterm::System;
|
||||
|
||||
namespace EE {
|
||||
namespace eterm {
|
||||
|
||||
namespace System {
|
||||
class Process;
|
||||
}
|
||||
|
||||
using namespace EE::System;
|
||||
|
||||
namespace Terminal {
|
||||
|
||||
class PseudoTerminal final : public IPseudoTerminal {
|
||||
@@ -62,7 +61,7 @@ class PseudoTerminal final : public IPseudoTerminal {
|
||||
static std::unique_ptr<PseudoTerminal> create( int columns, int rows );
|
||||
|
||||
private:
|
||||
friend class ::EE::System::Process;
|
||||
friend class ::eterm::System::Process;
|
||||
#ifdef _WIN32
|
||||
Vector2i mSize;
|
||||
|
||||
@@ -84,6 +83,6 @@ class PseudoTerminal final : public IPseudoTerminal {
|
||||
#endif
|
||||
};
|
||||
} // namespace Terminal
|
||||
} // namespace EE
|
||||
} // namespace eterm
|
||||
|
||||
#endif
|
||||
|
||||
@@ -18,9 +18,12 @@
|
||||
#include <vector>
|
||||
|
||||
using namespace EE;
|
||||
using namespace EE::Terminal;
|
||||
using namespace EE::Window;
|
||||
using namespace EE::System;
|
||||
using namespace eterm::System;
|
||||
using namespace eterm::Terminal;
|
||||
|
||||
namespace eterm { namespace Terminal {
|
||||
|
||||
enum class TerminalShortcutAction {
|
||||
PASTE,
|
||||
@@ -286,4 +289,6 @@ class TerminalDisplay : public ITerminalDisplay {
|
||||
void drawFrameBuffer();
|
||||
};
|
||||
|
||||
}} // namespace eterm::Terminal
|
||||
|
||||
#endif // ETERM_TERMINALDISPLAY_HPP
|
||||
|
||||
@@ -46,11 +46,11 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
using namespace EE;
|
||||
using namespace EE::System;
|
||||
using namespace EE::Math;
|
||||
using namespace EE::Window;
|
||||
using namespace eterm::System;
|
||||
|
||||
namespace EE { namespace Terminal {
|
||||
namespace eterm { namespace Terminal {
|
||||
|
||||
constexpr int ESC_BUF_SIZ = 512;
|
||||
constexpr int ESC_ARG_SIZ = 16;
|
||||
@@ -324,6 +324,6 @@ class TerminalEmulator final {
|
||||
const size_t& historySize = 1000 );
|
||||
};
|
||||
|
||||
}} // namespace EE::Terminal
|
||||
}} // namespace eterm::Terminal
|
||||
|
||||
#endif
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace EE { namespace Terminal {
|
||||
namespace eterm { namespace Terminal {
|
||||
|
||||
enum TerminalCursorMode {
|
||||
BlinkingBlock = 0,
|
||||
@@ -174,6 +174,6 @@ struct TerminalSelection {
|
||||
int alt;
|
||||
};
|
||||
|
||||
}} // namespace EE::Terminal
|
||||
}} // namespace eterm::Terminal
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace EE { namespace System {
|
||||
namespace eterm { namespace System {
|
||||
|
||||
AutoHandle::AutoHandle() : mHandle( invalid_value() ) {}
|
||||
AutoHandle::AutoHandle( AutoHandle&& other ) : mHandle( other.mHandle ) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <eterm/terminal/windowserrors.hpp>
|
||||
#include <windows.h>
|
||||
|
||||
using namespace EE::System;
|
||||
namespace eterm { namespace System {
|
||||
|
||||
Pipe::Pipe( AutoHandle&& readHandle, AutoHandle&& writeHandle ) :
|
||||
mInputHandle( std::move( readHandle ) ), mOutputHandle( std::move( writeHandle ) ) {}
|
||||
@@ -49,4 +49,6 @@ int Pipe::read( char* buf, size_t n, bool block ) {
|
||||
return (int)read;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <eepp/system/filesystem.hpp>
|
||||
#include <eepp/system/log.hpp>
|
||||
#include <eterm/system/process.hpp>
|
||||
#include <poll.h>
|
||||
#include <pwd.h>
|
||||
@@ -44,6 +45,8 @@
|
||||
|
||||
using namespace EE::System;
|
||||
|
||||
namespace eterm { namespace System {
|
||||
|
||||
Process::~Process() {
|
||||
if ( mPID != -1 ) {
|
||||
kill( mPID, SIGHUP );
|
||||
@@ -92,7 +95,7 @@ void Process::waitForExit() {
|
||||
}
|
||||
|
||||
bool Process::hasExited() const {
|
||||
return mStatus == EE::System::ProcessStatus::EXITED;
|
||||
return mStatus == ProcessStatus::EXITED;
|
||||
}
|
||||
|
||||
int Process::getExitCode() const {
|
||||
@@ -197,6 +200,8 @@ Process::createWithPseudoTerminal( const std::string& program, const std::vector
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}} // namespace eterm::System
|
||||
|
||||
#else
|
||||
|
||||
#include <assert.h>
|
||||
@@ -208,9 +213,10 @@ Process::createWithPseudoTerminal( const std::string& program, const std::vector
|
||||
#define NTDDI_VERSION NTDDI_WIN10_RS5
|
||||
#include <windows.h>
|
||||
|
||||
using namespace EE::System;
|
||||
using namespace EE;
|
||||
|
||||
namespace eterm { namespace System {
|
||||
|
||||
static std::wstring stringToWideString( const std::string& str ) {
|
||||
if ( str.empty() )
|
||||
return std::wstring();
|
||||
@@ -223,46 +229,48 @@ static std::wstring stringToWideString( const std::string& str ) {
|
||||
#define HANDLE_WIN_ERR( err ) HRESULT_FROM_WIN32( err ), PrintWinApiError( err )
|
||||
|
||||
static HRESULT InitializeStartupInfoAttachedToPseudoConsole( STARTUPINFOEXW* pStartupInfo,
|
||||
HPCON hPC ) {
|
||||
HRESULT hr{ E_UNEXPECTED };
|
||||
HPCON hpc ) {
|
||||
// Prepare Startup Information structure
|
||||
STARTUPINFOEXW si;
|
||||
ZeroMemory( &si, sizeof( si ) );
|
||||
si.StartupInfo.cb = sizeof( STARTUPINFOEXW );
|
||||
|
||||
if ( pStartupInfo ) {
|
||||
SIZE_T attrListSize{};
|
||||
// Discover the size required for the list
|
||||
SIZE_T bytesRequired;
|
||||
InitializeProcThreadAttributeList( NULL, 1, 0, &bytesRequired );
|
||||
|
||||
pStartupInfo->StartupInfo.cb = sizeof( STARTUPINFOEXW );
|
||||
// pStartupInfo->StartupInfo.dwFlags = STARTF_USESTDHANDLES;
|
||||
|
||||
// Get the size of the thread attribute list.
|
||||
InitializeProcThreadAttributeList( NULL, 1, 0, &attrListSize );
|
||||
|
||||
// Allocate a thread attribute list of the correct size
|
||||
pStartupInfo->lpAttributeList = reinterpret_cast<LPPROC_THREAD_ATTRIBUTE_LIST>(
|
||||
HeapAlloc( GetProcessHeap(), 0, attrListSize ) );
|
||||
|
||||
// Initialize thread attribute list
|
||||
if ( pStartupInfo->lpAttributeList &&
|
||||
InitializeProcThreadAttributeList( pStartupInfo->lpAttributeList, 1, 0,
|
||||
&attrListSize ) ) {
|
||||
// Set Pseudo Console attribute
|
||||
hr = UpdateProcThreadAttribute( pStartupInfo->lpAttributeList, 0,
|
||||
PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, hPC, sizeof( hPC ),
|
||||
NULL, NULL )
|
||||
? S_OK
|
||||
: HANDLE_WIN_ERR( GetLastError() );
|
||||
printf( "errrr1: %ld", hr );
|
||||
} else {
|
||||
hr = HANDLE_WIN_ERR( GetLastError() );
|
||||
}
|
||||
// Allocate memory to represent the list
|
||||
si.lpAttributeList =
|
||||
(PPROC_THREAD_ATTRIBUTE_LIST)HeapAlloc( GetProcessHeap(), 0, bytesRequired );
|
||||
if ( !si.lpAttributeList ) {
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
return hr;
|
||||
|
||||
// Initialize the list memory location
|
||||
if ( !InitializeProcThreadAttributeList( si.lpAttributeList, 1, 0, &bytesRequired ) ) {
|
||||
HeapFree( GetProcessHeap(), 0, si.lpAttributeList );
|
||||
return HRESULT_FROM_WIN32( GetLastError() );
|
||||
}
|
||||
|
||||
// Set the pseudoconsole information into the list
|
||||
if ( !UpdateProcThreadAttribute( si.lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE,
|
||||
hpc, sizeof( hpc ), NULL, NULL ) ) {
|
||||
HeapFree( GetProcessHeap(), 0, si.lpAttributeList );
|
||||
return HRESULT_FROM_WIN32( GetLastError() );
|
||||
}
|
||||
|
||||
*pStartupInfo = si;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
Process::Process( AutoHandle&& hProcess, void* lpAttributeList ) :
|
||||
Process::Process( AutoHandle&& hProcess, void* lpAttributeList, int pid ) :
|
||||
mStatus( ProcessStatus::RUNNING ),
|
||||
mLeaveRunning( false ),
|
||||
mExitCode( 1 ),
|
||||
mLeaveRunning( false ),
|
||||
mProcessHandle( std::move( hProcess ) ),
|
||||
mLpAttributeList( lpAttributeList ) {}
|
||||
mLpAttributeList( lpAttributeList ),
|
||||
mPID( pid ) {}
|
||||
|
||||
Process::~Process() {
|
||||
if ( mLpAttributeList ) {
|
||||
@@ -379,10 +387,11 @@ std::unique_ptr<Process> Process::createWithPipe( const std::string& program,
|
||||
AutoHandle hProcess{ piProcInfo.hProcess };
|
||||
AutoHandle hThread{ piProcInfo.hThread };
|
||||
|
||||
return std::unique_ptr<Process>( new Process( std::move( hProcess ), NULL ) );
|
||||
return std::unique_ptr<Process>(
|
||||
new Process( std::move( hProcess ), NULL, piProcInfo.dwProcessId ) );
|
||||
}
|
||||
|
||||
// PrintWinApiError( GetLastError() );
|
||||
PrintWinApiError( GetLastError() );
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@@ -414,7 +423,7 @@ Process::createWithPseudoTerminal( const std::string& program, const std::vector
|
||||
|
||||
if ( ( hr = InitializeStartupInfoAttachedToPseudoConsole( &startupInfo,
|
||||
pseudoTerminal.mPHPC ) ) != S_OK ) {
|
||||
printf( "InitializeStartupInfoAttachedToPseudoConsole failed\n" );
|
||||
Log::error( "InitializeStartupInfoAttachedToPseudoConsole failed." );
|
||||
PrintErrorResult( hr );
|
||||
goto fail;
|
||||
}
|
||||
@@ -434,7 +443,7 @@ Process::createWithPseudoTerminal( const std::string& program, const std::vector
|
||||
: HANDLE_WIN_ERR( GetLastError() );
|
||||
|
||||
if ( hr != S_OK ) {
|
||||
printf( "CreateProcessW failed\n" );
|
||||
Log::error( "CreateProcessW failed\n" );
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -444,9 +453,11 @@ Process::createWithPseudoTerminal( const std::string& program, const std::vector
|
||||
pseudoTerminal.mAttached = true;
|
||||
|
||||
return std::unique_ptr<Process>(
|
||||
new Process( std::move( hProcess ), startupInfo.lpAttributeList ) );
|
||||
new Process( std::move( hProcess ), startupInfo.lpAttributeList, piClient.dwProcessId ) );
|
||||
fail:
|
||||
return std::unique_ptr<Process>();
|
||||
}
|
||||
|
||||
}} // namespace eterm::System
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
#include <eterm/system/processfactory.hpp>
|
||||
#include <eterm/terminal/pseudoterminal.hpp>
|
||||
|
||||
using namespace EE::System;
|
||||
using namespace eterm::System;
|
||||
|
||||
namespace eterm { namespace System {
|
||||
|
||||
std::unique_ptr<IProcess> ProcessFactory::createWithStdioPipe( const std::string& program,
|
||||
const std::vector<std::string>& args,
|
||||
@@ -35,3 +37,5 @@ std::unique_ptr<IProcess> ProcessFactory::createWithPseudoTerminal(
|
||||
outPseudoTerminal = std::move( pseudoTerminal );
|
||||
return process;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#define MODBIT( x, set, bit ) ( ( set ) ? ( ( x ) |= ( bit ) ) : ( ( x ) &= ~( bit ) ) )
|
||||
|
||||
using namespace EE::Terminal;
|
||||
namespace eterm { namespace Terminal {
|
||||
|
||||
ITerminalDisplay::ITerminalDisplay() :
|
||||
mMode( MODE_VISIBLE ), mCursorMode( SteadyBar ), mEmulator( nullptr ) {}
|
||||
@@ -75,3 +75,5 @@ const char* ITerminalDisplay::getClipboard() const {
|
||||
}
|
||||
|
||||
void ITerminalDisplay::onProcessExit( int /*exitCode*/ ) {}
|
||||
|
||||
}}
|
||||
|
||||
@@ -42,6 +42,8 @@
|
||||
#include <unistd.h>
|
||||
using namespace EE::System;
|
||||
|
||||
namespace eterm { namespace Terminal {
|
||||
|
||||
#if EE_PLATFORM == EE_PLATFORM_ANDROID
|
||||
#include <fcntl.h>
|
||||
|
||||
@@ -90,8 +92,6 @@ fail:
|
||||
}
|
||||
#endif
|
||||
|
||||
using namespace EE::Terminal;
|
||||
|
||||
PseudoTerminal::~PseudoTerminal() {}
|
||||
|
||||
PseudoTerminal::PseudoTerminal( int columns, int rows, AutoHandle&& master, AutoHandle&& slave ) :
|
||||
@@ -186,6 +186,8 @@ std::unique_ptr<PseudoTerminal> PseudoTerminal::create( int columns, int rows )
|
||||
#endif
|
||||
}
|
||||
|
||||
}} // namespace eterm::Terminal
|
||||
|
||||
#else
|
||||
#include <assert.h>
|
||||
#include <eterm/terminal/pseudoterminal.hpp>
|
||||
@@ -193,7 +195,7 @@ std::unique_ptr<PseudoTerminal> PseudoTerminal::create( int columns, int rows )
|
||||
#define NTDDI_VERSION NTDDI_WIN10_RS5
|
||||
#include <windows.h>
|
||||
|
||||
using namespace EE::Terminal;
|
||||
namespace eterm { namespace Terminal {
|
||||
|
||||
PseudoTerminal::~PseudoTerminal() {
|
||||
ClosePseudoConsole( mPHPC );
|
||||
@@ -250,8 +252,9 @@ int PseudoTerminal::read( char* buf, size_t n, bool block ) {
|
||||
PrintLastWinApiError();
|
||||
return -1;
|
||||
}
|
||||
if ( available == 0 )
|
||||
if ( available == 0 ) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !ReadFile( mInputHandle.handle(), buf, available, &read, nullptr ) ) {
|
||||
@@ -300,4 +303,7 @@ std::unique_ptr<PseudoTerminal> PseudoTerminal::create( int columns, int rows )
|
||||
return Pointer(
|
||||
new PseudoTerminal( columns, rows, std::move( hPipeIn ), std::move( hPipeOut ), hPC ) );
|
||||
}
|
||||
|
||||
}} // namespace eterm::Terminal
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <eterm/terminal/boxdrawdata.hpp>
|
||||
#include <eterm/terminal/terminaldisplay.hpp>
|
||||
|
||||
namespace eterm { namespace Terminal {
|
||||
|
||||
#define BETWEEN( x, a, b ) ( ( a ) <= ( x ) && ( x ) <= ( b ) )
|
||||
#define IS_SET( flag ) ( ( mMode & ( flag ) ) != 0 )
|
||||
#define DIV( n, d ) ( ( ( n ) + ( d ) / 2.0f ) / ( d ) )
|
||||
@@ -1402,7 +1404,7 @@ void TerminalDisplay::invalidateCursor() {
|
||||
}
|
||||
|
||||
void TerminalDisplay::invalidateLine( const int& line ) {
|
||||
if ( line >= mDirtyLines.size() ) {
|
||||
if ( line >= (int)mDirtyLines.size() ) {
|
||||
mDirtyLines.resize( line + 1 );
|
||||
}
|
||||
mDirtyLines[line] = true;
|
||||
@@ -1458,3 +1460,5 @@ void TerminalDisplay::drawFrameBuffer() {
|
||||
textureRegion.draw( mPosition.floor().x, mPosition.floor().y );
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace eterm::Terminal
|
||||
|
||||
@@ -50,6 +50,8 @@
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace eterm { namespace Terminal {
|
||||
|
||||
/* identification sequence returned in DA and DECID */
|
||||
static const char* vtiden = "\033[?6c";
|
||||
|
||||
@@ -111,8 +113,6 @@ static const unsigned int tabspaces = 4;
|
||||
? mTerm.hist[( ( y ) + mTerm.histi - mTerm.scr + mTerm.histsize + 1 ) % mTerm.histsize] \
|
||||
: mTerm.line[(y)-mTerm.scr] )
|
||||
|
||||
using namespace EE::Terminal;
|
||||
|
||||
typedef struct emoji_range {
|
||||
int32_t min_code;
|
||||
int32_t max_code;
|
||||
@@ -2632,3 +2632,5 @@ void TerminalEmulator::update() {
|
||||
onProcessExit( mExitCode );
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace eterm::Terminal
|
||||
|
||||
@@ -22,16 +22,20 @@
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
#ifdef _WIN32
|
||||
#include <eepp/system/log.hpp>
|
||||
using namespace EE::System;
|
||||
|
||||
#define NTDDI_VERSION NTDDI_WIN10_RS5
|
||||
#include <comdef.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <windows.h>
|
||||
|
||||
static void PrintErrorResult( HRESULT hr ) {
|
||||
inline void PrintErrorResult( HRESULT hr ) {
|
||||
_com_error err( hr );
|
||||
LPCTSTR errMsg = err.ErrorMessage();
|
||||
std::cerr << "ERROR: " << errMsg << std::endl;
|
||||
Log::error( "ERROR: %s", errMsg );
|
||||
}
|
||||
|
||||
static void PrintWinApiError( DWORD error ) {
|
||||
@@ -48,9 +52,10 @@ static void PrintWinApiError( DWORD error ) {
|
||||
LocalFree( messageBuffer );
|
||||
|
||||
std::cerr << "ERROR WinAPI: " << message << std::endl;
|
||||
Log::error( "ERROR WinAPI: %s", message );
|
||||
}
|
||||
|
||||
static void PrintLastWinApiError( void ) {
|
||||
inline void PrintLastWinApiError( void ) {
|
||||
PrintWinApiError( GetLastError() );
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,24 @@ EE_MAIN_FUNC int main( int, char*[] ) {
|
||||
#endif
|
||||
DisplayManager* displayManager = Engine::instance()->getDisplayManager();
|
||||
Display* currentDisplay = displayManager->getDisplayIndex( 0 );
|
||||
FileSystem::changeWorkingDirectory( Sys::getProcessPath() );
|
||||
|
||||
std::string resPath = Sys::getProcessPath();
|
||||
#if EE_PLATFORM == EE_PLATFORM_MACOSX
|
||||
if ( String::contains( resPath, "ecode.app" ) ) {
|
||||
resPath = FileSystem::getCurrentWorkingDirectory();
|
||||
FileSystem::dirAddSlashAtEnd( resPath );
|
||||
mIsBundledApp = true;
|
||||
}
|
||||
#elif EE_PLATFORM == EE_PLATFORM_LINUX
|
||||
if ( String::contains( resPath, ".mount_" ) ) {
|
||||
resPath = FileSystem::getCurrentWorkingDirectory();
|
||||
FileSystem::dirAddSlashAtEnd( resPath );
|
||||
}
|
||||
#elif EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN
|
||||
resPath += "eterm/";
|
||||
#endif
|
||||
resPath += "assets";
|
||||
FileSystem::dirAddSlashAtEnd( resPath );
|
||||
|
||||
displayManager->enableScreenSaver();
|
||||
displayManager->enableMouseFocusClickThrough();
|
||||
@@ -104,7 +121,7 @@ EE_MAIN_FUNC int main( int, char*[] ) {
|
||||
Sizei winSize( 1280, 720 );
|
||||
win = Engine::instance()->createWindow(
|
||||
WindowSettings( winSize.getWidth(), winSize.getHeight(), "eterm", WindowStyle::Default,
|
||||
WindowBackend::Default, 32, "assets/icon/ee.png",
|
||||
WindowBackend::Default, 32, resPath + "icon/ee.png",
|
||||
currentDisplay->getPixelDensity() ),
|
||||
ContextSettings( true ) );
|
||||
|
||||
@@ -112,13 +129,15 @@ EE_MAIN_FUNC int main( int, char*[] ) {
|
||||
win->setClearColor( RGB( 0, 0, 0 ) );
|
||||
|
||||
FontTrueType* fontMono = FontTrueType::New( "monospace" );
|
||||
fontMono->loadFromFile( "assets/fonts/DejaVuSansMonoNerdFontComplete.ttf" );
|
||||
fontMono->loadFromFile( resPath + "fonts/DejaVuSansMonoNerdFontComplete.ttf" );
|
||||
fontMono->setEnableEmojiFallback( false );
|
||||
|
||||
if ( FileSystem::fileExists( "assets/fonts/NotoColorEmoji.ttf" ) ) {
|
||||
FontTrueType::New( "emoji-color" )->loadFromFile( "assets/fonts/NotoColorEmoji.ttf" );
|
||||
} else if ( FileSystem::fileExists( "assets/fonts/NotoEmoji-Regular.ttf" ) ) {
|
||||
FontTrueType::New( "emoji-font" )->loadFromFile( "assets/fonts/NotoEmoji-Regular.ttf" );
|
||||
if ( FileSystem::fileExists( resPath + "fonts/NotoColorEmoji.ttf" ) ) {
|
||||
FontTrueType::New( "emoji-color" )
|
||||
->loadFromFile( resPath + "fonts/NotoColorEmoji.ttf" );
|
||||
} else if ( FileSystem::fileExists( resPath + "fonts/NotoEmoji-Regular.ttf" ) ) {
|
||||
FontTrueType::New( "emoji-font" )
|
||||
->loadFromFile( resPath + "fonts/NotoEmoji-Regular.ttf" );
|
||||
}
|
||||
|
||||
if ( !terminal || terminal->hasTerminated() ) {
|
||||
|
||||
Reference in New Issue
Block a user