OSDN Git Service

Linux用ビルド設定
[coroid/inqubus.git] / launcher / Launcher.c
1 /*\r
2  * Windows\97p\83v\83\8d\83O\83\89\83\80\83\89\83\93\83`\83\83\r
3  * copyright (c) 2008 \83Õ\81i\83v\83T\83C\81j\r
4  *\r
5  * \81u\82³\82«\82ã\82Î\82·\81v\96{\91Ì\82ðexe\8co\97R\82Å\93®\82©\82·\82½\82ß\82Ì\83\89\83\93\83`\83\83\82Å\82·\81B\r
6  *\r
7  * \82±\82Ì\83t\83@\83C\83\8b\82Í\81u\82³\82«\82ã\82Î\82·\81v\82Ì\88ê\95\94\82Å\82 \82è\81A\r
8  * \82±\82Ì\83\\81[\83X\83R\81[\83h\82ÍGPL\83\89\83C\83Z\83\93\83X\82Å\94z\95z\82³\82ê\82Ü\82·\82Å\82·\81B\r
9  */\r
10 #include <stdlib.h>\r
11 #include <windows.h>\r
12 \r
13 int doCmd(char* command,int show_msg);\r
14         STARTUPINFO startup_info;\r
15         PROCESS_INFORMATION process_info;\r
16 \r
17 int WINAPI WinMain (HINSTANCE hInstance, \r
18                         HINSTANCE hPrevInstance, \r
19                         PSTR szCmdLine, \r
20                         int iCmdShow){\r
21                         if(doCmd("java.exe",FALSE) == 0){\r
22                                 doCmd("java.exe -jar Saccubus.jar",TRUE);\r
23                         }else{\r
24                                 MessageBox(NULL,"Java\82ª\83C\83\93\83X\83g\81[\83\8b\82³\82ê\82Ä\82¢\82È\82¢\82æ\82¤\82Å\82·\81B","\83G\83\89\81[",MB_OK | MB_ICONERROR);\r
25                         }\r
26                         return 0;\r
27 }\r
28 \r
29 int doCmd(char* command,int show_msg){\r
30         int ret = 0;\r
31         int code = CreateProcessA(\r
32             NULL,                                               // \8eÀ\8ds\83t\83@\83C\83\8b\96¼\r
33             command,                                    // \83R\83}\83\93\83h\83\89\83C\83\93\83p\83\89\83\81\81[\83^\r
34             NULL,                                               // \83v\83\8d\83Z\83X\82Ì\95Û\8cì\91®\90«\r
35             NULL,                                               // \83X\83\8c\83b\83h\82Ì\95Û\8cì\91®\90«\r
36             FALSE,                                              // \83I\83u\83W\83F\83N\83g\83n\83\93\83h\83\8b\8cp\8f³\82Ì\83t\83\89\83O\r
37             DETACHED_PROCESS | \r
38                 CREATE_NEW_PROCESS_GROUP | \r
39                 NORMAL_PRIORITY_CLASS,          // \91®\90«\83t\83\89\83O\r
40             NULL,                                               // \8aÂ\8b«\95Ï\90\94\8fî\95ñ\82Ö\82Ì\83|\83C\83\93\83^\r
41             NULL,                                               // \8bN\93®\8e\9e\83J\83\8c\83\93\83g\83f\83B\83\8c\83N\83g\83\8a\r
42             &startup_info,                              // \83E\83B\83\93\83h\83E\95\\8e¦\90Ý\92è\r
43             &process_info                               // \83v\83\8d\83Z\83X\81E\83X\83\8c\83b\83h\82Ì\8fî\95ñ\r
44         );\r
45         if(code == 0){\r
46                 ret = -1;\r
47                 if(show_msg){\r
48                         char* msg;\r
49                         int error_code = FormatMessageA(\r
50                                 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,    // \93®\8dì\83t\83\89\83O\r
51                                 0,                                                                                                                              // \83\81\83b\83Z\81[\83W\92è\8b`\88Ê\92u\r
52                                 GetLastError(),                                                                                                 // \83\81\83b\83Z\81[\83WID\r
53                                 LANG_USER_DEFAULT,                                                                                              // \8c¾\8cêID\r
54                                 (LPTSTR)&msg,                                                                                                   // \83o\83b\83t\83@\82Ì\83A\83h\83\8c\83X\r
55                                 0,                                                                                                                              // \83o\83b\83t\83@\82Ì\83T\83C\83Y\r
56                                 0                                                                                                                               // \91}\93ü\8bå\82Ì\94z\97ñ\82Ì\83A\83h\83\8c\83X\r
57                         );\r
58                         if(error_code == 0){\r
59                                 MessageBox(NULL,"\89½\82ç\82©\82Ì\83G\83\89\81[\82ª\94­\90\82µ\82Ü\82µ\82½\81B","\83G\83\89\81[",MB_OK | MB_ICONERROR);\r
60                         }else{\r
61                                 MessageBox(NULL,msg, "\83G\83\89\81[", MB_ICONERROR|MB_OK);\r
62                         }\r
63                         LocalFree(msg);\r
64                 }\r
65         }\r
66         CloseHandle(process_info.hProcess);\r
67         CloseHandle(process_info.hThread);\r
68         return ret;\r
69 }\r