/src/main.cpp
https://bitbucket.org/vivkin/gam3b00bs/ · C++ · 103 lines · 63 code · 31 blank · 9 comment · 2 complexity · 735b83c6043c4808303b9667ef3ab8c7 MD5 · raw file
- #include "common.h"
-
- #include <stdio.h>
- #include <io.h>
- #include <fcntl.h>
- #include <windows.h>
-
- #include "network/network.h"
- #include "bindings/bind_all.h"
- #include "shared/log.h"
-
-
- // first link from google: http://www.halcyon.com/~ast/dload/guicon.htm
-
- enum { MAX_CONSOLE_LINES = 500 };
-
- void create_console()
- {
- int hConHandle;
- long lStdHandle;
-
- CONSOLE_SCREEN_BUFFER_INFO coninfo;
- FILE *fp;
-
- AllocConsole();
-
- GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
- coninfo.dwSize.Y = MAX_CONSOLE_LINES;
- SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
-
- // redirect unbuffered STDOUT to the console
- lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
- hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
- fp = _fdopen( hConHandle, "w" );
-
- *stdout = *fp;
- setvbuf( stdout, NULL, _IONBF, 0 );
-
- // redirect unbuffered STDIN to the console
-
- lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
- hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
-
- fp = _fdopen( hConHandle, "r" );
- *stdin = *fp;
- setvbuf( stdin, NULL, _IONBF, 0 );
-
- // redirect unbuffered STDERR to the console
- lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
- hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
- fp = _fdopen( hConHandle, "w" );
- *stderr = *fp;
- setvbuf( stderr, NULL, _IONBF, 0 );
- }
-
-
-
- //
-
-
- //
- // makes sure the current working directoy is where the exe is located
- //
- void init_working_dir()
- {
- wchar_t path[512], drive[10], dir[MAX_PATH], name[MAX_PATH], ext[128];
- GetModuleFileNameW( 0, path, 512 );
- _wsplitpath( path, drive, dir, name, ext );
- swprintf( path, 512, L"%s%s", drive, dir );
- if( !SetCurrentDirectoryW( path ) )
- {
- ASSERT( !"Could not set exe directory!" );
- }
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////////////
-
-
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
- {
- #if ENABLE_CONSOLE
- create_console();
- #endif
-
- init_working_dir();
- log_open("log.txt");
-
- int ret = luab::start_scripts();
-
- #if ENABLE_CONSOLE
- if( !IsDebuggerPresent() )
- {
- system( "pause" );
- }
- #endif
-
- log_close();
-
- return ret;
-
-
- }