1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <atlpath.h> // ATL CPath 20 21 // Global flag indicating whether this is running in debug mode (more printfs) 22 extern bool gIsDebug; 23 // Global flag indicating whether this is running in console mode or GUI. 24 // In console mode, errors are written on the console; in GUI they use a MsgBox. 25 extern bool gIsConsole; 26 27 // Must be called by the application to initialize the app name used in error dialog boxes. 28 // If NULL is used, fetches VERSIONINFO.FileDescription from resources if available. 29 void initUtils(const TCHAR *appName); 30 31 // Returns the app name set in initUtils 32 CString getAppName(); 33 34 // Displays a message in an ok+info dialog box. Useful in console mode. 35 void msgBox(const TCHAR* text, ...); 36 37 // Displays GetLastError prefixed with a description in an error dialog box. Useful in console mode. 38 void displayLastError(const TCHAR *description, ...); 39 40 // Executes the command line. Does not wait for the program to finish. 41 // The return code is from CreateProcess (0 means failure), not the running app. 42 int execNoWait(const TCHAR *app, const TCHAR *params, const TCHAR *workDir); 43 44 // Executes command, waits for completion and returns exit code. 45 // As indicated in MSDN for CreateProcess, callers should double-quote the program name 46 // e.g. cmd="\"c:\program files\myapp.exe\" arg1 arg2"; 47 int execWait(const TCHAR *cmd); 48 49 bool getModuleDir(CPath *outDir); 50 51 // Disables the FS redirection done by WOW64. 52 // Because this runs as a 32-bit app, Windows automagically remaps some 53 // folder under the hood (e.g. "Programs Files(x86)" is mapped as "Program Files"). 54 // This prevents the app from correctly searching for java.exe in these folders. 55 // The registry is also remapped. 56 PVOID disableWow64FsRedirection(); 57 58 // Reverts the redirection disabled in disableWow64FsRedirection. 59 void revertWow64FsRedirection(PVOID oldWow64Value); 60