| 228 | |
| 229 | |
| 230 | BOOL CcppcryptfsApp::InitInstance() |
| 231 | { |
| 232 | |
| 233 | const WCHAR *szUniqueNamedMutex = L"cppcryptfs-A7DDB0CF-A856-4E8A-A4E9-722473FB5E49"; |
| 234 | |
| 235 | HANDLE hAppMutex = CreateMutex(NULL, TRUE, szUniqueNamedMutex); |
| 236 | if (GetLastError() == ERROR_ALREADY_EXISTS) |
| 237 | { |
| 238 | // Program already running - but hAppMutex is NOT NULL. |
| 239 | // Aparently it is not necessary to close it in this case. |
| 240 | |
| 241 | // Do something and then return FALSE to exit the app. |
| 242 | |
| 243 | // we can't use classname because our main window is a PropertySheet and has |
| 244 | // class name "DIALOG". I've seen info about how to change the class |
| 245 | // name of a dialog-based app, but not for one based on a PropertySheet |
| 246 | // TODO - it may be possible to use a custom class name |
| 247 | |
| 248 | // currently use "#32770" for the class (which is the class string for generic dialog boxes) |
| 249 | |
| 250 | HWND hWnd = FindWindow(L"#32770", L"cppcryptfs"); |
| 251 | |
| 252 | if (hWnd) { |
| 253 | if (have_args()) { |
| 254 | |
| 255 | bool have_console = OpenConsole(0); |
| 256 | |
| 257 | wstring err_mes; |
| 258 | wstring result; |
| 259 | |
| 260 | if (SendArgsToRunningInstance(GetCommandLine(), result, err_mes)) { |
| 261 | if (err_mes.length() > 0) |
| 262 | err_mes += L"\n"; |
| 263 | else |
| 264 | err_mes = L"cppcryptfsctl: Unable to send command. Is cppcryptfs really already running?\n"; |
| 265 | } else { |
| 266 | if (result.length() >= CMD_PIPE_RESPONSE_LENGTH) { |
| 267 | if (wcsncmp(result.c_str(), CMD_PIPE_SUCCESS_STR, CMD_PIPE_RESPONSE_LENGTH) == 0) { |
| 268 | wstring mes = result.c_str() + CMD_PIPE_RESPONSE_LENGTH; |
| 269 | if (mes.length() > 0) { |
| 270 | if (have_console) |
| 271 | wcout << mes << endl; |
| 272 | else |
| 273 | ::MessageBox(NULL, mes.c_str(), L"cppcryptfs", MB_OK); |
| 274 | } |
| 275 | } else { |
| 276 | err_mes = wstring(result.c_str() + CMD_PIPE_RESPONSE_LENGTH); |
| 277 | } |
| 278 | } else { |
| 279 | err_mes = L"cppcryptfs: got a mal-formed response from running instance of cppcryptfs\n"; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | if (err_mes.length() > 0) { |
| 284 | if (have_console) { |
| 285 | wcerr << err_mes; |
| 286 | } else { |
| 287 | ::MessageBox(NULL, err_mes.c_str(), L"cppcryptfs", MB_ICONERROR | MB_OK); |
nothing calls this directly
no test coverage detected