📄 flashupgrader.cpp
字号:
//---------------------------------------------------------------------------
// Pixelworks Inc. Company Confidential Strictly Private
//
// $Archive: $
// $Revision: 1.2 $
// $Author: Mikeh $
// $Date: 2005/05/24 19:51:22 $
//
// --------------------------------------------------------------------------
// >>>>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// --------------------------------------------------------------------------
// Copyright 1997-2003 (c) Pixelworks Inc.
//
// Pixelworks owns the sole copyright to this software. Under international
// copyright laws you (1) may not make a copy of this software except for
// the purposes of maintaining a single archive copy, (2) may not derive
// works herefrom, (3) may not distribute this work to others. These rights
// are provided for information clarification, other restrictions of rights
// may apply as well.
//
// This is an unpublished work.
// --------------------------------------------------------------------------
// >>>>>>>>>>>>>>>>>>>>>>>>>>>> WARRANTEE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// --------------------------------------------------------------------------
// Pixelworks Inc. MAKES NO WARRANTY OF ANY KIND WITH REGARD TO THE USE OF
// THIS SOFTWARE, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
// PURPOSE.
// --------------------------------------------------------------------------
//
// FlashUpgrader.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "FlashUpgrader.h"
#include "FlashUpgraderDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString g_strAppPath;
/////////////////////////////////////////////////////////////////////////////
// CFlashUpgraderApp
BEGIN_MESSAGE_MAP(CFlashUpgraderApp, CWinApp)
//{{AFX_MSG_MAP(CFlashUpgraderApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
//ON_COMMAND(ID_HELP, CWinApp::OnHelp)
ON_COMMAND(ID_HELP, OnF1Help)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFlashUpgraderApp construction
CFlashUpgraderApp::CFlashUpgraderApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
CString strTmp;
char tmpbuf[_MAX_PATH];
GetCurrentDirectory(_MAX_PATH, tmpbuf);
GetModuleFileName(NULL, tmpbuf,_MAX_PATH);
strTmp = tmpbuf;
strTmp = strTmp.Left(strTmp.ReverseFind('\\'));
// strTmp.MakeUpper(); // MIKEH 05/24/2005- Don't case. Doesn't work with Linux shared files
g_strAppPath = strTmp;
g_strAppPath += "\\";
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CFlashUpgraderApp object
CFlashUpgraderApp theApp;
CFlashUpgraderApp *pTheApp = &theApp;
int CFlashUpgraderApp::ExitInstance()
{
int nResult;
nResult = CWinApp::ExitInstance();
if( nResult == 0 )
{
nResult = m_nReturnValue;
}
return nResult;
}
/////////////////////////////////////////////////////////////////////////////
// CFlashUpgraderApp initialization
BOOL CFlashUpgraderApp::InitInstance()
{
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
//
// Default to sucess return, this gets set to -1 when
// an error occurs.
//
m_nReturnValue = 0;
m_strCmdLineOptions = m_lpCmdLine;
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Parse the command line to see if launched as OLE server
if (RunEmbedded() || RunAutomated())
{
// Register all OLE server (factories) as running. This enables the
// OLE libraries to create objects from other applications.
COleTemplateServer::RegisterAll();
}
else
{
// When a server application is launched stand-alone, it is a good idea
// to update the system registry in case it has been damaged.
COleObjectFactory::UpdateRegistryAll();
}
// Grab the current directory (the one where the app was launched)
LPTSTR dirbuf = m_strLaunchDir.GetBuffer(_MAX_PATH);
::GetCurrentDirectory(_MAX_PATH, dirbuf);
m_strLaunchDir.ReleaseBuffer();
if (CheckCmdLineOptions("-W"))
{
CString strWorkingDir = GetCmdLineOptions("-W");
if (!strWorkingDir.IsEmpty())
{
m_strLaunchDir = strWorkingDir;
}
}
m_strLaunchDir.TrimRight("\\");
m_strLaunchDir += "\\";
::SetCurrentDirectory(m_strLaunchDir);
::GetCurrentDirectory(1024, m_strLaunchDir.GetBuffer(1024));
m_strLaunchDir.ReleaseBuffer();
m_strLaunchDir.TrimRight("\\");
m_strLaunchDir+="\\";
if (CheckCmdLineOptions("-y") || CheckCmdLineOptions("-g"))
{
CString strDelay = GetCmdLineOptions("-y");
if (strDelay.IsEmpty())
{
//
// Default 1.5s delay for -g option alone. Use -w to
// specify a different delay.
//
strDelay = "2000";
}
int nDelay = atoi(strDelay);
Sleep(nDelay);
}
CFlashUpgraderDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
CString CFlashUpgraderApp::GetCmdLineOptions(CString strOptionPrefix)
{
int nPos;
CString strResult;
nPos = m_strCmdLineOptions.Find(strOptionPrefix);
if (nPos == -1)
return CString("");
strResult = m_strCmdLineOptions.Mid(nPos + strOptionPrefix.GetLength());
strResult.TrimLeft();
if (strResult[0] == '\"')
{
strResult = strResult.Mid(1);
nPos = strResult.Find('\"');
}
else
{
nPos = strResult.Find(' ');
}
if (nPos != -1)
strResult = strResult.Left(nPos);
return strResult;
}
// return true if command line option exists
BOOL CFlashUpgraderApp::CheckCmdLineOptions(CString strOptionPrefix)
{
return (m_strCmdLineOptions.Find(strOptionPrefix) != -1);
}
CString CFlashUpgraderApp::GetPath(LPCSTR lpszFullPath)
{
char lpszDrive[_MAX_DRIVE];
char lpszDir[_MAX_DIR];
char lpszFilename[_MAX_FNAME];
char lpszExt[_MAX_EXT];
_splitpath(lpszFullPath, lpszDrive, lpszDir, lpszFilename, lpszExt);
CString cStrPath;
cStrPath.Format("%s%s", lpszDrive, lpszDir);
return cStrPath;
}
CString CFlashUpgraderApp::GetFilename(LPCSTR lpszFullPath)
{
char lpszDrive[_MAX_DRIVE];
char lpszDir[_MAX_DIR];
char lpszFilename[_MAX_FNAME];
char lpszExt[_MAX_EXT];
_splitpath(lpszFullPath, lpszDrive, lpszDir, lpszFilename, lpszExt);
CString cStrFilename;
cStrFilename.Format("%s%s", lpszFilename, lpszExt);
return cStrFilename;
}
BOOL FileExists( const CString& strFile )
{
CFileFind find;
return find.FindFile( strFile );
}
CString HelpDirectories[] = {
"..\\..\\common\\Help\\",
"..\\Help\\",
""
};
BOOL DirExists( const CString& strDir )
{
CFileFind find;
CString strMask = strDir+"\\*.*";
BOOL bWorking = find.FindFile( strMask );
if (bWorking)
{
// Found files, our target must be a directory.
return TRUE;
}
return FALSE;
}
void CFlashUpgraderApp::OnF1Help()
{
CString strDir;
int i=0;
while (!HelpDirectories[i].IsEmpty())
{
strDir = g_strAppPath + HelpDirectories[i];
if (DirExists(strDir))
{
// Found a help directory...
break;
}
// Try next directory...
i++;
}
CString strPath = strDir + _T("FlashUpgraderUtilityHelp.hlp");
CStdioFile File;
if (!FileExists(strPath))
{
strPath = _T("..\\..\\bin\\FlashUpgraderUtilityHelp.hlp");
if (!FileExists(strPath))
{
strPath = _T("FlashUpgraderUtilityHelp.hlp");
}
}
::WinHelp(m_pMainWnd->m_hWnd, strPath,HELP_FINDER,0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -