// Vance Thrift and Biller File Utility 2 // // Douglas Thrift // // $Id: VTBFileUtil2.cxx,v 1.2 2003/08/16 04:56:17 douglas Exp $ #include "VTBFileUtil2.h" #include #include #include "resource.h" bool debug = false; string program; string programName = "Vance Thrift and Biller File Utility 2"; string programVersion = "2.0alpha"; HICON icon; enum Mode { none, disc, scan }; INT_PTR CALLBACK usage(HWND dialog, UINT msg, WPARAM w, LPARAM l); INT_PTR CALLBACK version(HWND dialog, UINT msg, WPARAM w, LPARAM l); inline void arguments(vector& args, const string& command) { istringstream line(command); string arg; do { if (line.peek() == '\"') { line.get(); getline(line, arg, '\"'); } else { line >> arg; line.get(); } args.push_back(arg); } while (line.good()); } inline void munge(void) { AllocConsole(); SetConsoleTitle("Renegade Map Selector"); int hin = _open_osfhandle(long(GetStdHandle(STD_INPUT_HANDLE)), _O_TEXT); int hout = _open_osfhandle(long(GetStdHandle(STD_OUTPUT_HANDLE)), _O_TEXT); int herr = _open_osfhandle(long(GetStdHandle(STD_ERROR_HANDLE)), _O_TEXT); FILE* fin = _fdopen(hin, "r"); FILE* fout = _fdopen(hout, "w"); FILE* ferr = _fdopen(herr, "w"); *stdin = *fin; *stdout = *fout; *stderr = *ferr; setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); cin.sync_with_stdio(); cout.sync_with_stdio(); cerr.sync_with_stdio(); } inline void usage(HINSTANCE instance, HWND parent) { DialogBox(instance, MAKEINTRESOURCE(IDD_USAGE), parent, usage); } inline void version(HINSTANCE instance, HWND parent) { DialogBox(instance, MAKEINTRESOURCE(IDD_VERSION), parent, version); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { vector args; arguments(args, GetCommandLine()); program = args[0]; Mode mode = none; icon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_VTB_ICON)); for (unsigned index = 1; index < args.size(); index++) { if (args[index] == "-help") { usage(hInstance); return 0; } else if (args[index] == "-version") { version(hInstance); return 0; } else if (args[index] == "-disc") { mode = disc; } else if (args[index] == "-scan") { mode = scan; } else if (args[index] == "-D") { if (!debug) { debug = true; munge(); } } } if (debug) { cerr << "mode = "; switch (mode) { case none: cerr << "none"; break; case disc: cerr << "disc"; break; case scan: cerr << "scan"; break; default: cerr << mode; break; } cerr << "\n"; } if (mode == none) { // } if (mode == disc) { // } else if (mode == scan) { // } if (debug) { cout << "Press enter key to exit . . ."; cin.get(); } return 0; } INT_PTR CALLBACK usage(HWND dialog, UINT msg, WPARAM w, LPARAM l) { switch (msg) { case WM_INITDIALOG: center(dialog); SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(icon)); SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str())); { ostringstream usage; usage << "Usage: VTBFileUtil [-help | -version | -disc | -scan]\n" << "\nOptions:\n" << " -help\t\tDisplay this information\n" << " -version\tDisplay version information\n" << " -disc\t\tStart in Disc Browse mode\n" << " -scan\t\tStart in Scan Utility mode\n"; SendMessage(GetDlgItem(dialog, IDC_USAGE_TEXT), WM_SETTEXT, 0, LPARAM(usage.str().c_str())); } break; case WM_COMMAND: switch (LOWORD(w)) { case IDOK: case IDCANCEL: EndDialog(dialog, w); return TRUE; default: break; } break; } return FALSE; } INT_PTR CALLBACK version(HWND dialog, UINT msg, WPARAM w, LPARAM l) { switch (msg) { case WM_INITDIALOG: center(dialog); SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(icon)); SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str())); { ostringstream version; version << programName << " ( " << programVersion << " )\n\n" << "Copyright © 2003, Douglas Thrift.\n"; SendMessage(GetDlgItem(dialog, IDC_VERSION_TEXT), WM_SETTEXT, 0, LPARAM(version.str().c_str())); } break; case WM_COMMAND: switch (LOWORD(w)) { case IDOK: case IDCANCEL: EndDialog(dialog, w); return TRUE; default: break; } break; } return FALSE; }