• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #include "stdafx.h"
19 #include "WinLauncher2App.h"
20 
21 #include "utils.h"
22 #include "JavaFinder.h"
23 #include "FindJava2Dlg.h"
24 
25 #ifdef _DEBUG
26 #define new DEBUG_NEW
27 #endif
28 
29 
30 // CWinLauncher2App
31 
32 BEGIN_MESSAGE_MAP(CWinLauncher2App, CWinApp)
33     ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
34 END_MESSAGE_MAP()
35 
36 
37 // The one and only CWinLauncher2App object
38 CWinLauncher2App theApp;
39 
40 class CLauncherCmdLineInfo : public CCommandLineInfo {
41 public:
42     bool mDoHelp;
43     bool mDoForceUi;
44     bool mDoJava1_7;
45     CString mFilename;
46 
CLauncherCmdLineInfo()47     CLauncherCmdLineInfo() : mDoHelp(false), mDoForceUi(false), mDoJava1_7(false) {}
48 
ParseParam(const TCHAR * pszParam,BOOL bFlag,BOOL bLast)49     virtual void ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast) {
50         // Expected command line:
51         // /h | help  : msg box with command line arguments
52         // /f | force : force UI selection
53         // /7         : require java 1.7
54         // path-to-launch
55 
56         if (!bFlag) {
57             mFilename = pszParam;
58         } else if (_tcsnccmp(pszParam, _T("h"), 2) == 0) {
59             mDoHelp = true;
60         } else if (_tcsnccmp(pszParam, _T("f"), 2) == 0) {
61             mDoForceUi = true;
62         } else if (_tcsnccmp(pszParam, _T("7"), 2) == 0) {
63             mDoJava1_7 = true;
64         }
65     }
66 };
67 
68 
CWinLauncher2App()69 CWinLauncher2App::CWinLauncher2App() {
70     // support Restart Manager
71     m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
72 
73     // TODO: add construction code here,
74     // Place all significant initialization in InitInstance
75 }
76 
InitInstance()77 BOOL CWinLauncher2App::InitInstance() {
78     // InitCommonControlsEx() is required on Windows XP if an application
79     // manifest specifies use of ComCtl32.dll version 6 or later to enable
80     // visual styles.  Otherwise, any window creation will fail.
81     INITCOMMONCONTROLSEX InitCtrls;
82     InitCtrls.dwSize = sizeof(InitCtrls);
83     // Set this to include all the common control classes you want to use
84     // in your application.
85     InitCtrls.dwICC = ICC_WIN95_CLASSES;
86     InitCommonControlsEx(&InitCtrls);
87 
88     CWinApp::InitInstance();
89     AfxEnableControlContainer();
90 
91     // Create the shell manager, in case the dialog contains
92     // any shell tree view or shell list view controls.
93     CShellManager *pShellManager = new CShellManager;
94 
95     // Activate "Windows Native" visual manager for enabling themes in MFC controls
96     CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
97 
98     // Set CWinApp default registry key. Must be consistent with all apps using findjava2.
99     SetRegistryKey(_T("Android-FindJava2"));
100 
101     // Use VERSIONINFO.FileDescription as the canonical app name
102     initUtils(NULL);
103 
104     CLauncherCmdLineInfo cmdLine;
105     ParseCommandLine(cmdLine);
106 
107     if (cmdLine.mDoHelp) {
108         const TCHAR *msg =
109             _T("WinLauncher2 [/7|/f|/h]\r\n")
110             _T("/7 : Requires Java 1.7 instead of 1.6\r\n")
111             _T("/f : Force UI\r\n")
112             _T("/h : Help\r\n");
113             AfxMessageBox(msg);
114         return FALSE; // quit without starting MFC app msg loop
115     }
116 
117     CJavaFinder javaFinder(JAVA_VERS_TO_INT(1, cmdLine.mDoJava1_7 ? 7 : 6));
118     CJavaPath javaPath = javaFinder.getRegistryPath();
119     if (cmdLine.mDoForceUi || javaPath.isEmpty()) {
120         javaPath.clear();
121 
122         CFindJava2Dlg dlg;
123         dlg.setJavaFinder(&javaFinder);
124         m_pMainWnd = &dlg;
125         INT_PTR nResponse = dlg.DoModal();
126 
127         if (nResponse == IDOK) {
128             // Use choice selected by user and save in registry.
129             javaPath = dlg.getSelectedPath();
130             javaFinder.setRegistryPath(javaPath);
131         } else if (nResponse == IDCANCEL) {
132             // Canceled by user, exit silently.
133         } else if (nResponse == -1) {
134             TRACE(traceAppMsg, 0, "Warning: dialog creation failed, so application is terminating unexpectedly.\n");
135         }
136     }
137 
138     if (!javaPath.isEmpty()) {
139         // TODO actually launch configured app instead of just printing path.
140         CString msg(_T("PLACEHOLDER TODO run app using "));
141         msg.Append(javaPath.mPath);
142         AfxMessageBox(msg);
143     }
144 
145     // Delete the shell manager created above.
146     if (pShellManager != NULL) {
147         delete pShellManager;
148     }
149 
150     // Since the dialog has been closed, return FALSE so that we exit the
151     // application, rather than start the application's message pump.
152     return FALSE;
153 }
154 
155