From 3338175675ce099bf55d64bbfd72a75c6a16cd2f Mon Sep 17 00:00:00 2001 From: Thor Arne Gald Semb Date: Fri, 19 Oct 2012 17:29:32 +0200 Subject: [PATCH] editor: support loading from argv It's sometimes useful to be able to load a rocket-file by dragging it onto the editor executable, or even registering the editor as an open-handler for the rocket-filetype Support this by accepting an optional argument that specifies the file to load. --- editor/editor.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/editor/editor.cpp b/editor/editor.cpp index 7adbc0c..0f8def8 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -673,7 +674,17 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, if (NULL == hwnd) die("Window Creation Failed!"); - fileNew(); + LPWSTR *argv; + int argc; + if ((argv = CommandLineToArgvW(GetCommandLineW(), &argc)) && argc > 1) { + if (argc > 2) { + char prog[MAX_PATH]; + GetModuleFileNameA(NULL, prog, sizeof(prog)); + die("usage: %s [filename.rocket]", prog); + } + loadDocument(argv[1]); + } else + fileNew(); HACCEL accel = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR));