OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [standalone/] [win32/] [Configtool.cpp] - Blame information for rev 790

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
2
// -------------------------------------------                              
3
// This file is part of the eCos host tools.                                
4
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.            
5
//
6
// This program is free software; you can redistribute it and/or modify     
7
// it under the terms of the GNU General Public License as published by     
8
// the Free Software Foundation; either version 2 or (at your option) any   
9
// later version.                                                           
10
//
11
// This program is distributed in the hope that it will be useful, but      
12
// WITHOUT ANY WARRANTY; without even the implied warranty of               
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
14
// General Public License for more details.                                 
15
//
16
// You should have received a copy of the GNU General Public License        
17
// along with this program; if not, write to the                            
18
// Free Software Foundation, Inc., 51 Franklin Street,                      
19
// Fifth Floor, Boston, MA  02110-1301, USA.                                
20
// -------------------------------------------                              
21
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
22
// ConfigTool.cpp : Defines the class behaviors for the application.
23
//
24
//
25
//===========================================================================
26
//#####DESCRIPTIONBEGIN####
27
//
28
// Author(s):   sdf
29
// Contact(s):  sdf
30
// Date:                1998/08/11
31
// Version:             0.01
32
// Purpose:     
33
// Description: This is the implementation of the application class
34
// Requires:    
35
// Provides:    
36
// See also:    
37
// Known bugs:  
38
// Usage:       
39
//
40
//####DESCRIPTIONEND####
41
//
42
//===========================================================================
43
 
44
#include "stdafx.h"
45
 
46
#include "ConfigTool.h"
47
#include "ConfigToolDoc.h"
48
#include "ControlView.h"
49
#include "CSHDialog.h"
50
#include "CTUtils.h"
51
#include "eCosDialog.h"
52
#include "eCosTest.h"
53
#include "eCosSocket.h"
54
#include "FileName.h"
55
#include "MainFrm.h"
56
#include "OutputView.h"
57
#include "RegKeyEx.h"
58
#include "Splash.h"
59
 
60
#include <afxadv.h>
61
#include <afxdisp.h> // for AfxEnableControlContainer()
62
#ifdef _DEBUG
63
#define new DEBUG_NEW
64
#undef THIS_FILE
65
static char THIS_FILE[] = __FILE__;
66
#endif
67
 
68
CString CConfigTool::strHelpFile;
69
 
70
/////////////////////////////////////////////////////////////////////////////
71
// CConfigToolApp 
72
 
73
BEGIN_MESSAGE_MAP(CConfigToolApp, CWinApp)
74
//{{AFX_MSG_MAP(CConfigToolApp)
75
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
76
//}}AFX_MSG_MAP
77
// Standard file based document commands
78
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
79
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
80
// Standard print setup command
81
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
82
END_MESSAGE_MAP()
83
 
84
 
85
 
86
/////////////////////////////////////////////////////////////////////////////
87
// CConfigToolApp construction
88
CConfigToolApp::CConfigToolApp()
89
{
90
  m_GrayPen.CreatePen(PS_SOLID,1,RGB(192,192,192));
91
  m_VersionInfo.dwOSVersionInfoSize=sizeof OSVERSIONINFO;
92
  ::GetVersionEx(&m_VersionInfo);
93
}
94
 
95
/////////////////////////////////////////////////////////////////////////////
96
// The one and only CConfigToolApp object
97
 
98
CConfigToolApp theApp;
99
 
100
/////////////////////////////////////////////////////////////////////////////
101
// CConfigToolApp initialization
102
 
103
BOOL CConfigToolApp::InitInstance()
104
{
105
  CeCosSocket::Init();
106
  CeCosTestPlatform::Load();
107
  CFileName strCSHFile;
108
  ::GetModuleFileName(::GetModuleHandle(NULL),strCSHFile.GetBuffer(1+MAX_PATH),MAX_PATH);
109
  strCSHFile.ReleaseBuffer();
110
  strCSHFile.ReplaceExtension(_T(".chm"));
111
  CConfigTool::strHelpFile=strCSHFile;
112
  CCSHDialog::SetCSHFilePath(strCSHFile);
113
 
114
  extern UINT  arCommonDialogMap[];
115
  CeCosDialog::AddDialogMap(arCommonDialogMap);
116
 
117
  extern UINT  arStandaloneDialogMap[];
118
  CeCosDialog::AddDialogMap(arStandaloneDialogMap);
119
 
120
  extern UINT  arPkgAdminDialogMap[];
121
  CeCosDialog::AddDialogMap(arPkgAdminDialogMap);
122
 
123
  extern UINT  arTestToolDialogMap[];
124
  CeCosDialog::AddDialogMap(arTestToolDialogMap);
125
 
126
  // CG: The following block was added by the Splash Screen component.
127
  \
128
  {
129
    \
130
      CCommandLineInfo cmdInfo;
131
    \
132
      ParseCommandLine(cmdInfo);
133
    \
134
 
135
      \
136
      CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
137
    \
138
  }
139
  AfxEnableControlContainer();
140
  // Standard initialization
141
  // If you are not using these features and wish to reduce the size
142
  //  of your final executable, you should remove from the following
143
  //  the specific initialization routines you do not need.
144
 
145
        int nSize=GetEnvironmentVariable(_T("PATH"), NULL, 0);
146
        if(nSize>0){
147
    GetEnvironmentVariable(_T("PATH"),m_strOriginalPath.GetBuffer(1+nSize),nSize);
148
    m_strOriginalPath.ReleaseBuffer();
149
  }
150
 
151
#ifdef _AFXDLL
152
  Enable3dControls();                   // Call this when using MFC in a shared DLL
153
#else
154
  Enable3dControlsStatic();     // Call this when linking to MFC statically
155
#endif
156
  SetRegistryKey(IDS_REGKEY);
157
  LoadStdProfileSettings();  // Load standard INI file options (including MRU)
158
 
159
  // Register the application's document templates.  Document templates
160
  //  serve as the connection between documents, frame windows and views.
161
 
162
  CSingleDocTemplate* pDocTemplate;
163
  pDocTemplate = new CSingleDocTemplate(
164
    IDR_MAINFRAME,
165
    RUNTIME_CLASS(CConfigToolDoc),
166
    RUNTIME_CLASS(CMainFrame),       // main SDI frame window
167
    RUNTIME_CLASS(CControlView));
168
  AddDocTemplate(pDocTemplate);
169
 
170
  // Parse command line for standard shell commands, DDE, file open
171
  CCommandLineInfo cmdInfo;
172
  //ParseCommandLine(cmdInfo);
173
 
174
  CString strCmdLine(GetCommandLine());
175
  CStringArray arArgs;
176
  int nWords=CUtils::Chop(strCmdLine,arArgs,_TCHAR(' '),/*bObserveStrings=*/true,/*bBackslashQuotes=*/false);
177
  bool bBuild=false;
178
  bool bRun=false;
179
  CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
180
  for(int i=1;i<nWords;i++)
181
  {
182
    CString &str=arArgs[i];
183
    if(0==str.Compare(_T("-R")) && i<nWords-1){
184
      pDoc->SetRepository(arArgs[++i]);
185
    } else if (0==str.CompareNoCase(_T("-S")) && i<nWords-1){
186
      // Load settings file
187
    } else if (0==str.CompareNoCase(_T("-B"))){
188
      // Build
189
      bBuild=true;
190
    } else if (0==str.CompareNoCase(_T("-R"))){
191
      // run
192
      bRun=true;
193
    } else {
194
      cmdInfo.m_nShellCommand=CCommandLineInfo::FileOpen;
195
      cmdInfo.m_strFileName=str;
196
    }
197
  }
198
 
199
  // Dispatch commands specified on the command line
200
  if (!ProcessShellCommand(cmdInfo))
201
    return FALSE;
202
 
203
  CMenu* pMenu = m_pMainWnd->GetMenu();
204
  if (pMenu)pMenu->DestroyMenu();
205
  HMENU hMenu = ((CMainFrame*) m_pMainWnd)->NewMenu();
206
  pMenu = CMenu::FromHandle( hMenu );
207
  m_pMainWnd->SetMenu(pMenu);
208
  ((CMainFrame*)m_pMainWnd)->m_hMenuDefault = hMenu;
209
 
210
 
211
  // The one and only window has been initialized, so show and update it.
212
  m_pMainWnd->ShowWindow(SW_SHOW);
213
  m_pMainWnd->UpdateWindow();
214
 
215
  return TRUE;
216
}
217
 
218
/////////////////////////////////////////////////////////////////////////////
219
// CAboutDlg dialog used for App About
220
 
221
class CAboutDlg : public CDialog
222
{
223
public:
224
  CAboutDlg();
225
 
226
  // Dialog Data
227
  //{{AFX_DATA(CAboutDlg)
228
  enum { IDD = IDD_ABOUTBOX };
229
  CStatic       m_static;
230
  //}}AFX_DATA
231
 
232
  // ClassWizard generated virtual function overrides
233
  //{{AFX_VIRTUAL(CAboutDlg)
234
protected:
235
  virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
236
  //}}AFX_VIRTUAL
237
 
238
  // Implementation
239
protected:
240
  //{{AFX_MSG(CAboutDlg)
241
  virtual BOOL OnInitDialog();
242
  afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
243
  //}}AFX_MSG
244
  DECLARE_MESSAGE_MAP()
245
};
246
 
247
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
248
{
249
  //{{AFX_DATA_INIT(CAboutDlg)
250
  //}}AFX_DATA_INIT
251
}
252
 
253
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
254
{
255
  CDialog::DoDataExchange(pDX);
256
  //{{AFX_DATA_MAP(CAboutDlg)
257
  DDX_Control(pDX, IDC_STATIC_ABOUT, m_static);
258
  //}}AFX_DATA_MAP
259
}
260
 
261
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
262
//{{AFX_MSG_MAP(CAboutDlg)
263
ON_WM_LBUTTONDBLCLK()
264
//}}AFX_MSG_MAP
265
END_MESSAGE_MAP()
266
 
267
// App command to run the dialog
268
void CConfigToolApp::OnAppAbout()
269
{
270
  CAboutDlg aboutDlg;
271
  aboutDlg.DoModal();
272
}
273
 
274
/////////////////////////////////////////////////////////////////////////////
275
// CConfigToolApp commands
276
 
277
 
278
int CConfigToolApp::ExitInstance()
279
{
280
  // Save persistence info
281
  WriteProfileString(_T("Build"),        _T("MakeOptions"),m_strMakeOptions);
282
  WriteProfileString(CUtils::LoadString(IDS_KEY_USER_DIR), _T("Folder"), m_strUserToolsDir);
283
  // Write any target bindirs to the registry
284
  for(POSITION pos = m_arstrBinDirs.GetStartPosition(); pos != NULL; ){
285
    CString strPrefix,strBinDir;
286
    m_arstrBinDirs.GetNextAssoc(pos, strPrefix, strBinDir);
287
    WriteProfileString(CUtils::LoadString(IDS_KEY_TOOLS_DIR),strPrefix,strBinDir);
288
  }
289
  ::DeleteFile(CConfigToolDoc::HTMLHelpLinkFileName());
290
  CeCosSocket::Term();
291
  CeCosTestPlatform::RemoveAllPlatforms();
292
  return CWinApp::ExitInstance();
293
}
294
 
295
void CConfigToolApp::LoadStdProfileSettings()
296
{
297
  CWinApp::LoadStdProfileSettings(4);
298
 
299
  CString strNotepad;
300
  FindExecutable(_T("Notepad.exe"),_T(""),strNotepad.GetBuffer(MAX_PATH));
301
  strNotepad.ReleaseBuffer();
302
 
303
  m_strMakeOptions=                       GetProfileString(_T("Build"), _T("MakeOptions"),_T(""));
304
  if(m_strMakeOptions.IsEmpty()){
305
    SYSTEM_INFO SystemInfo;
306
    GetSystemInfo(&SystemInfo);
307
    m_strMakeOptions.Format(_T("-j%d"),SystemInfo.dwNumberOfProcessors);
308
  }
309
 
310
  CRegKeyEx InstallKey (HKEY_LOCAL_MACHINE, GetInstallVersionKey (), KEY_READ);
311
 
312
  m_strUserToolsDir=                    GetProfileString(CUtils::LoadString(IDS_KEY_USER_DIR), _T("Folder"), _T(""));
313
  if(!m_strUserToolsDir.IsDir()){ // if the user specified user tools dir does not exist
314
    InstallKey.QueryValue (_T("Default User Tools Path"), m_strUserToolsDir); // use the installer default
315
    if (!m_strUserToolsDir.IsDir()) { // if the default user tools dir does not exist
316
      m_strUserToolsDir=_T(""); // force prompting for the user tools dir
317
    }
318
  }
319
 
320
  // set default build tools binary directories as specified by the installer
321
  CFileName strDefaultBuildToolsPath;
322
  if (InstallKey.QueryValue (_T("Default Build Tools Path"), strDefaultBuildToolsPath)) {
323
    // look for *-gcc.exe in the default build tools directory
324
    CFileFind finder;
325
    BOOL bMore=finder.FindFile (strDefaultBuildToolsPath + _T("*-gcc.exe"));
326
    while (bMore) { // for each file matching the globbing pattern
327
      bMore = finder.FindNextFile ();
328
      CFileName strFile (finder.GetFileName ());
329
      m_arstrBinDirs.SetAt (strFile.Left (strFile.Find (_T("-gcc"))), strDefaultBuildToolsPath);
330
    }
331
  }
332
 
333
  CRegKeyEx k;
334
  k.Attach(GetSectionKey(CUtils::LoadString(IDS_KEY_TOOLS_DIR)));
335
  CFileName strDir;
336
  CString strPrefix;
337
  for(int i=0;k.QueryValue(i,strPrefix,strDir);i++){
338
    if(strDir.IsDir()){
339
      m_arstrBinDirs.SetAt(strPrefix,strDir);
340
    }
341
  }
342
 
343
  CStringArray arstrToolChainPaths;
344
  GetRepositoryRegistryClues(arstrToolChainPaths,_T("GNUPro eCos"));
345
  for(i=0;i<arstrToolChainPaths.GetSize();i++){
346
    CFileName strDir(arstrToolChainPaths[i]);
347
    strDir+="H-i686-cygwin32\\bin";
348
    if(strDir.IsDir()){
349
      // This is a potential toolchain location. Look for *-gcc.exe
350
      CFileFind finder;
351
      BOOL bMore=finder.FindFile(strDir+"*-gcc.exe");
352
      while (bMore) {
353
        bMore = finder.FindNextFile();
354
        CFileName strFile(finder.GetFileName());
355
        m_arstrBinDirs.SetAt(strFile.Left(strFile.Find(_T("-gcc"))),strDir);
356
      }
357
    }
358
  }
359
 
360
  // Look for GNUPro 00r1 first, since it's the latest and greatest user tools.   
361
  GetRepositoryRegistryClues(m_arstrUserToolPaths, _T("GNUPro 00r1"));
362
  if (m_arstrUserToolPaths.GetSize() == 0)
363
  {
364
      GetRepositoryRegistryClues(m_arstrUserToolPaths, _T("Cygwin 00r1"));
365
  }
366
  if (m_arstrUserToolPaths.GetSize() > 0)
367
  {
368
    for(i=0;i<m_arstrUserToolPaths.GetSize();i++){
369
        CFileName str(m_arstrUserToolPaths[i]);
370
        str+="H-i686-pc-cygwin\\bin";
371
        if(str.IsDir()){
372
        m_arstrUserToolPaths.SetAt(i,str);
373
        } else {
374
        m_arstrUserToolPaths.RemoveAt(i);
375
        i--;
376
        }
377
    }
378
  }
379
  else
380
  {
381
    GetRepositoryRegistryClues(m_arstrUserToolPaths, _T("GNUPro unsupported"));
382
    for(i=0;i<m_arstrUserToolPaths.GetSize();i++){
383
        CFileName str(m_arstrUserToolPaths[i]);
384
        str+="H-i686-cygwin32\\bin";
385
        if(str.IsDir()){
386
        m_arstrUserToolPaths.SetAt(i,str);
387
        } else {
388
        m_arstrUserToolPaths.RemoveAt(i);
389
        i--;
390
        }
391
    }
392
 }
393
 
394
  // Include the path in the set of potential user paths
395
  {
396
    CString strPath;
397
    int nSize=GetEnvironmentVariable(CUtils::LoadString(IDS_PATH), NULL, 0);
398
    if(nSize>0){
399
      GetEnvironmentVariable(CUtils::LoadString(IDS_PATH), strPath.GetBuffer(nSize), nSize);
400
      strPath.ReleaseBuffer();
401
      CStringArray arstrPath;
402
      CUtils::Chop(strPath,arstrPath,_TCHAR(';'));
403
      for(int i=arstrPath.GetSize()-1;i>=0;--i){ // Reverse order is important to treat path correctly
404
        const CFileName &strFolder=arstrPath[i];
405
        CFileName strFile(strFolder);
406
        strFile+=_T("ls.exe");
407
        if(strFile.Exists()){
408
          m_arstrUserToolPaths.Add(strFolder);
409
          if(m_strUserToolsDir.IsEmpty()){
410
            m_strUserToolsDir=strFolder;
411
          }
412
        }
413
      }
414
    }
415
  }
416
}
417
 
418
BOOL CConfigToolApp::OnIdle(LONG lCount)
419
{
420
  if(lCount==0)
421
  {
422
    CMainFrame *pMain=CConfigTool::GetMain();
423
    if(pMain){
424
      // During startup the main window will be the splash screen
425
      CDC *pDC=pMain->GetDC();
426
      CFont *pOldFont=pDC->SelectObject(pMain->m_wndStatusBar.GetFont());
427
      pDC->SelectObject(pOldFont);
428
      pMain->ReleaseDC(pDC);
429
 
430
    }
431
  }
432
  return CWinApp::OnIdle(lCount);
433
}
434
 
435
BOOL CConfigToolApp::PreTranslateMessage(MSG* pMsg)
436
{
437
  // CG: The following lines were added by the Splash Screen component.
438
  if (CSplashWnd::PreTranslateAppMessage(pMsg))
439
    return TRUE;
440
 
441
  return CWinApp::PreTranslateMessage(pMsg);
442
}
443
 
444
BOOL CAboutDlg::OnInitDialog()
445
{
446
  CString strVersion;
447
  strVersion.Format(_T("%s %s"),_T(__DATE__),_T(__TIME__));
448
  SetDlgItemText(IDC_STATIC_DATETIME,strVersion);
449
  CDialog::OnInitDialog();
450
  return TRUE;  // return TRUE unless you set the focus to a control
451
  // EXCEPTION: OCX Property Pages should return FALSE
452
}
453
 
454
bool CConfigToolApp::Launch(const CString & strFileName,const CString &strViewer)
455
{
456
  bool rc=false;
457
 
458
  if(!strViewer.IsEmpty())//use custom editor
459
  {
460
    CString strCmdline(strViewer);
461
 
462
    TCHAR *pszCmdLine=strCmdline.GetBuffer(strCmdline.GetLength());
463
    GetShortPathName(pszCmdLine,pszCmdLine,strCmdline.GetLength());
464
    strCmdline.ReleaseBuffer();
465
 
466
    strCmdline+=_TCHAR(' ');
467
    strCmdline+=strFileName;
468
    PROCESS_INFORMATION pi;
469
    STARTUPINFO si;
470
 
471
    si.cb = sizeof(STARTUPINFO);
472
    si.lpReserved = NULL;
473
    si.lpReserved2 = NULL;
474
    si.cbReserved2 = 0;
475
    si.lpDesktop = NULL;
476
    si.dwFlags = 0;
477
    si.lpTitle=NULL;
478
 
479
    if(CreateProcess(
480
      NULL, // app name
481
      //strCmdline.GetBuffer(strCmdline.GetLength()),    // command line
482
      strCmdline.GetBuffer(strCmdline.GetLength()),    // command line
483
      NULL, // process security
484
      NULL, // thread security
485
      TRUE, // inherit handles
486
      0,
487
      NULL, // environment
488
      NULL, // current dir
489
      &si, // startup info
490
      &pi)){
491
      CloseHandle(pi.hProcess);
492
      CloseHandle(pi.hThread);
493
      rc=true;
494
    } else {
495
      CUtils::MessageBoxF(_T("Failed to invoke %s.\n"),strCmdline);
496
    }
497
    strCmdline.ReleaseBuffer();
498
  } else {// Use association
499
    TCHAR szExe[MAX_PATH];
500
    HINSTANCE h=FindExecutable(strFileName,_T("."),szExe);
501
    if(int(h)<=32){
502
      CString str;
503
      switch(int(h)){
504
      case 0:  str=_T("The system is out of memory or resources.");break;
505
      case 31: str=_T("There is no association for the specified file type.");break;
506
      case ERROR_FILE_NOT_FOUND: str=_T("The specified file was not found.");break;
507
      case ERROR_PATH_NOT_FOUND: str=_T("The specified path was not found.");break;
508
      case ERROR_BAD_FORMAT:     str=_T("The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).");break;
509
      default: break;
510
      }
511
      CUtils::MessageBoxF(_T("Failed to open document %s.\r\n%s"),strFileName,str);
512
    } else {
513
 
514
      SHELLEXECUTEINFO sei = {sizeof(sei), 0, AfxGetMainWnd()->GetSafeHwnd(), _T("open"),
515
        strFileName, NULL, NULL, SW_SHOWNORMAL, AfxGetInstanceHandle( )};
516
 
517
      sei.hInstApp=0;
518
      HINSTANCE hInst=ShellExecute(AfxGetMainWnd()->GetSafeHwnd(),_T("open"), strFileName, NULL, _T("."), 0)/*ShellExecuteEx(&sei)*/;
519
      if(int(hInst)<=32/*sei.hInstApp==0*/)
520
      {
521
        CString str;
522
        switch(int(hInst))
523
        {
524
        case 0 : str=_T("The operating system is out of memory or resources. ");break;
525
        case ERROR_FILE_NOT_FOUND : str=_T("The specified file was not found. ");break;
526
        case ERROR_PATH_NOT_FOUND : str=_T("The specified path was not found. ");break;
527
        case ERROR_BAD_FORMAT : str=_T("The .EXE file is invalid (non-Win32 .EXE or error in .EXE image). ");break;
528
        case SE_ERR_ACCESSDENIED : str=_T("The operating system denied access to the specified file. ");break;
529
        case SE_ERR_ASSOCINCOMPLETE : str=_T("The filename association is incomplete or invalid. ");break;
530
        case SE_ERR_DDEBUSY : str=_T("The DDE transaction could not be completed because other DDE transactions were being processed. ");break;
531
        case SE_ERR_DDEFAIL : str=_T("The DDE transaction failed. ");break;
532
        case SE_ERR_DDETIMEOUT : str=_T("The DDE transaction could not be completed because the request timed out. ");break;
533
        case SE_ERR_DLLNOTFOUND : str=_T("The specified dynamic-link library was not found. ");break;
534
          //case SE_ERR_FNF : str=_T("The specified file was not found. ");break;
535
        case SE_ERR_NOASSOC : str=_T("There is no application associated with the given filename extension. ");break;
536
        case SE_ERR_OOM : str=_T("There was not enough memory to complete the operation. ");break;
537
          //case SE_ERR_PNF : str=_T("The specified path was not found. ");break;
538
        case SE_ERR_SHARE : str=_T("A sharing violation occurred. ");break;
539
        default: str=_T("An unexpected error occurred");break;
540
        }
541
        CUtils::MessageBoxF(_T("Failed to open document %s using %s.\r\n%s"),strFileName,szExe,str);
542
      } else {
543
        rc=true;
544
      }
545
    }
546
  }
547
  return rc;
548
}
549
 
550
/*
551
void CConfigToolApp::AddToRecentFileList(LPCTSTR lpszPathName)
552
{
553
const CFileName strDir=CFileName(lpszPathName).Head();
554
if(strDir.IsDir()){
555
CWinApp::AddToRecentFileList(strDir);
556
}
557
}
558
*/
559
 
560
int CConfigToolApp::GetRepositoryRegistryClues(CStringArray &arstr,LPCTSTR pszPrefix)
561
{
562
  // Go looking for potential candidates in SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
563
  arstr.RemoveAll();
564
  CRegKeyEx k1(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths"),KEY_READ);
565
  CString strKey;
566
  for(int i=0;k1.QueryKey(i,strKey);i++){
567
    if(0==strKey.Find(pszPrefix)){
568
      CRegKeyEx k2((HKEY)k1,strKey,KEY_READ);
569
      CFileName strDir;
570
      if(k2.QueryValue(_T("Path"),strDir) && strDir.IsDir()){
571
        arstr.Add(strDir);
572
      }
573
    }
574
  }
575
  return arstr.GetSize();
576
}
577
 
578
 
579
void CAboutDlg::OnLButtonDblClk(UINT nFlags, CPoint point)
580
{
581
  UNUSED_ALWAYS(point);
582
  UNUSED_ALWAYS(nFlags);
583
}
584
 
585
//const char CConfigToolApp::s_profileFlags[] = _T("flags");
586
LPCTSTR  CConfigToolApp::s_profileMax = _T("max");
587
LPCTSTR  CConfigToolApp::s_profileTool = _T("tool");
588
LPCTSTR  CConfigToolApp::s_profileStatus = _T("status");
589
LPCTSTR  CConfigToolApp::s_profileRect = _T("Rect");
590
 
591
void CConfigToolApp::SaveWindowPlacement(CWnd *pWnd, const CString &strKey)
592
{
593
  // Our position
594
  CString strText;
595
 
596
  WINDOWPLACEMENT wndpl;
597
  wndpl.length = sizeof(WINDOWPLACEMENT);
598
  // gets current window position and
599
  //  iconized/maximized status
600
  pWnd->GetWindowPlacement(&wndpl);
601
  strText.Format(_T("%04d %04d %04d %04d"),
602
    wndpl.rcNormalPosition.left,
603
    wndpl.rcNormalPosition.top,
604
    wndpl.rcNormalPosition.right,
605
    wndpl.rcNormalPosition.bottom);
606
  if(!pWnd->IsWindowVisible()){
607
    wndpl.showCmd=SW_HIDE;
608
  }
609
  WriteProfileInt   (strKey,_T("Show"), wndpl.showCmd);
610
  WriteProfileString(strKey,s_profileRect, strText);
611
}
612
 
613
BOOL CConfigToolApp::RestoreWindowPlacement(CWnd *pWnd,const CString &strKey,const CRect &rcDefault)
614
{
615
  // Set the windows according to registry settings
616
  CString strText;
617
  WINDOWPLACEMENT wndpl;
618
  CRect rect;
619
 
620
  strText = GetProfileString(strKey,s_profileRect);
621
  if (!strText.IsEmpty()) {
622
    rect.left = _ttoi((LPCTSTR ) strText);
623
    rect.top =  _ttoi((LPCTSTR ) strText + 5);
624
    rect.right = _ttoi((LPCTSTR ) strText + 10);
625
    rect.bottom = _ttoi((LPCTSTR ) strText + 15);
626
  } else {
627
    rect = rcDefault;
628
  }
629
 
630
  CRect rcMax;
631
  SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID)(RECT *)rcMax, 0);
632
 
633
  if(rect.Width()<100 || rect.Height()<100 || rect.Width()>rcMax.Width() || rect.Height()>rcMax.Height()){
634
    rect=rcDefault;
635
  }
636
 
637
  wndpl.length = sizeof(WINDOWPLACEMENT);
638
  wndpl.showCmd = GetProfileInt(strKey,_T("Show"),SW_SHOWNA);
639
  wndpl.flags = 0;
640
 
641
  wndpl.ptMinPosition = CPoint(0, 0);
642
  wndpl.ptMaxPosition =CPoint(-::GetSystemMetrics(SM_CXBORDER),-::GetSystemMetrics(SM_CYBORDER));
643
  wndpl.rcNormalPosition = rect;
644
 
645
  // sets window's position and iconized/maximized status
646
  return pWnd->SetWindowPlacement(&wndpl);
647
}
648
 
649
void CConfigToolApp::LoadFont(const CString & strKey, LOGFONT & lf)
650
{
651
  lf.lfHeight                   =(LONG)GetProfileInt(strKey,_T("Height"),0);
652
  if(0==lf.lfHeight){
653
    CFont font;
654
    font.Attach(HFONT(GetStockObject(DEFAULT_GUI_FONT)));
655
    font.GetLogFont(&lf);
656
  } else {
657
    lf.lfWidth                  =(LONG)GetProfileInt(strKey,_T("Width"),0);
658
    lf.lfEscapement             =(LONG)GetProfileInt(strKey,_T("Escapement"),0);
659
    lf.lfOrientation    =(LONG)GetProfileInt(strKey,_T("Orientation"),0);
660
    lf.lfWeight                 =(LONG)GetProfileInt(strKey,_T("Weight"),0);
661
    lf.lfItalic                 =(BYTE)GetProfileInt(strKey,_T("Italic"),0);
662
    lf.lfUnderline              =(BYTE)GetProfileInt(strKey,_T("Underline"),0);
663
    lf.lfStrikeOut              =(BYTE)GetProfileInt(strKey,_T("StrikeOut"),0);
664
    lf.lfCharSet                =(BYTE)GetProfileInt(strKey,_T("CharSet"),0);
665
    lf.lfOutPrecision   =(BYTE)GetProfileInt(strKey,_T("OutPrecision"),0);
666
    lf.lfClipPrecision  =(BYTE)GetProfileInt(strKey,_T("ClipPrecision"),0);
667
    lf.lfQuality                =(BYTE)GetProfileInt(strKey,_T("Quality"),0);
668
    lf.lfPitchAndFamily =(BYTE)GetProfileInt(strKey,_T("PitchAndFamily"),0);
669
    CString strFaceName =GetProfileString(strKey,_T("FaceName"),_T(""));
670
    if(strFaceName.GetLength()<=31){
671
      _tcscpy(lf.lfFaceName,strFaceName);
672
    } else {
673
      lf.lfFaceName[0]=_TCHAR('\0');
674
    }
675
  }
676
}
677
 
678
void CConfigToolApp::SaveFont(const CString & strKey, const LOGFONT & lf)
679
{
680
  WriteProfileInt(strKey,_T("Height"),          (int)lf.lfHeight);
681
  WriteProfileInt(strKey,_T("Width"),                   (int)lf.lfWidth);
682
  WriteProfileInt(strKey,_T("Escapement"),      (int)lf.lfEscapement);
683
  WriteProfileInt(strKey,_T("Orientation"),     (int)lf.lfOrientation);
684
  WriteProfileInt(strKey,_T("Weight"),          (int)lf.lfWeight);
685
  WriteProfileInt(strKey,_T("Italic"),          (int)lf.lfItalic);
686
  WriteProfileInt(strKey,_T("Underline"),               (int)lf.lfUnderline);
687
  WriteProfileInt(strKey,_T("StrikeOut"),               (int)lf.lfStrikeOut);
688
  WriteProfileInt(strKey,_T("CharSet"),         (int)lf.lfCharSet);
689
  WriteProfileInt(strKey,_T("OutPrecision"),    (int)lf.lfOutPrecision);
690
  WriteProfileInt(strKey,_T("ClipPrecision"),   (int)lf.lfClipPrecision);
691
  WriteProfileInt(strKey,_T("Quality"),         (int)lf.lfQuality);
692
  WriteProfileInt(strKey,_T("PitchAndFamily"),(int)lf.lfPitchAndFamily);
693
  WriteProfileString(strKey,_T("FaceName"),   lf.lfFaceName);
694
}
695
 
696
CEditView             *CConfigTool::m_pEditView=NULL;
697
COutputView         *CConfigTool::m_pOutputView=NULL;
698
CControlView    *CConfigTool::m_pControlView=NULL;
699
CCellView       *CConfigTool::m_pCellView=NULL;
700
CDescView       *CConfigTool::m_pDescView=NULL;
701
CPropertiesView *CConfigTool::m_pPropertiesView=NULL;
702
CRulesView      *CConfigTool::m_pRulesView=NULL;
703
CConfigToolDoc  *CConfigTool::m_pConfigToolDoc=NULL;
704
CMainFrame      *CConfigTool::m_pMain=NULL;
705
CMLTView        *CConfigTool::m_pMLTView=NULL;
706
 
707
CControlView    *CConfigTool::GetControlView()      { return m_pControlView; }
708
COutputView     *CConfigTool::GetOutputView()       { return m_pOutputView; }
709
CCellView       *CConfigTool::GetCellView()         { return m_pCellView; }
710
CDescView       *CConfigTool::GetDescView()         { return m_pDescView; }
711
CPropertiesView *CConfigTool::GetPropertiesView()   { return m_pPropertiesView; }
712
CRulesView      *CConfigTool::GetRulesView()        { return m_pRulesView; }
713
CMLTView        *CConfigTool::GetMLTView()          { return m_pMLTView; }
714
 
715
void CConfigTool::SetDocument(CConfigToolDoc *pDoc) {m_pConfigToolDoc=pDoc; }
716
void CConfigTool::SetMain(CMainFrame * pMain) { m_pMain=pMain; }
717
void CConfigTool::SetControlView(CControlView *pControlView) {m_pControlView=pControlView; }
718
void CConfigTool::SetOutputView(COutputView *pOutputView) {m_pOutputView=pOutputView; }
719
void CConfigTool::SetCellView(CCellView *pCellView) {m_pCellView=pCellView; }
720
void CConfigTool::SetDescView(CDescView *pDescView) {m_pDescView=pDescView; }
721
void CConfigTool::SetMLTView(CMLTView *pMLTView) {m_pMLTView=pMLTView; }
722
void CConfigTool::SetPropertiesView(CPropertiesView *pPropertiesView) {m_pPropertiesView=pPropertiesView; }
723
void CConfigTool::SetRulesView(CRulesView *pRulesView) {m_pRulesView=pRulesView; }
724
CMainFrame *CConfigTool::GetMain()
725
{
726
  CWnd *pWnd=AfxGetMainWnd();
727
  return (pWnd && pWnd->IsKindOf(RUNTIME_CLASS(CMainFrame)))?(CMainFrame*)pWnd:NULL;
728
}
729
 
730
int CConfigTool::Log(LPCTSTR pszFormat, ...)
731
{
732
  va_list marker;
733
  va_start (marker, pszFormat);
734
 
735
  for(int nLength=100;nLength;) {
736
    TCHAR *buf=new TCHAR[1+nLength];
737
    int n=_vsntprintf(buf, nLength, pszFormat, marker );
738
    if(-1==n){
739
      nLength*=2;  // NT behavior
740
    } else if (n<nLength){
741
      CWnd *pMain=CConfigTool::GetMain();
742
      if(pMain){
743
        // During startup the main window will be the splash screen
744
        COutputView *pView=CConfigTool::GetOutputView();
745
        if(pView){
746
          pView->AddText(buf);
747
          pView->AddText(_T("\r\n"));
748
        }
749
      }
750
      ((CConfigToolApp *)AfxGetApp())->m_strBufferedLogMessages+=buf;
751
      ((CConfigToolApp *)AfxGetApp())->m_strBufferedLogMessages+=_T("\r\n");
752
      nLength=0;   // trigger exit from loop
753
    } else {
754
      nLength=n+1; // UNIX behavior generally, or NT behavior when buffer size exactly matches required length
755
    }
756
    delete [] buf;
757
  }
758
 
759
  va_end (marker);
760
 
761
  return 0;
762
}
763
 
764
void CConfigTool::DismissSplash()
765
{
766
  CSplashWnd::EnableSplashScreen(FALSE);
767
}
768
 
769
CString CConfigToolApp::GetInstallVersionKey ()
770
{
771
  CString strKey = _T("SOFTWARE\\Red Hat\\eCos");
772
  CString strVersionKey = _T("");
773
  CString rc = _T("");
774
  TCHAR pszBuffer [MAX_PATH + 1];
775
  HKEY hKey;
776
 
777
  // get the greatest eCos version subkey
778
  if (ERROR_SUCCESS == RegOpenKeyEx (HKEY_LOCAL_MACHINE, strKey, 0L, KEY_READ, &hKey)) {
779
    DWORD dwIndex = 0;
780
    while (ERROR_SUCCESS == RegEnumKey (hKey, dwIndex++, (LPTSTR) pszBuffer, sizeof (pszBuffer))) {
781
      if (strVersionKey.Compare (pszBuffer) < 0) {
782
        strVersionKey = pszBuffer;
783
      }
784
    }
785
    RegCloseKey (hKey);
786
  }
787
  return strKey + _T("\\") + strVersionKey;
788
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.