📄 page2.cpp
字号:
//Leading or ending spaces? (fix SB Audigy bug).
CString spaceTest = value;
spaceTest.TrimLeft();
spaceTest.TrimRight();
if(spaceTest != value)
{
newValue = spaceTest;
return false;
}
//SB Audigy bug?
/*
if( name.CompareNoCase(_T("SB Audigy 2 Startup Menu")) == 0 &&
value.CompareNoCase(_T(" /L:ENG")) == 0)
{
//Remove space
newValue = _T("/L:ENG");
return false;
}*/
//This is a legal value if no \ is found, or it begins with "
if(value.Find("\\") == -1 || value[0] == '\"')
return true;
CString filename; //String where the real filename exist
CString lowerdata; //lowcase-data
lowerdata = value;
lowerdata.MakeLower();
//Filename should end with: .EXE or .BAT or .COM or .DLL
int fileend = lowerdata.Find(".exe");
if(fileend == -1) fileend = lowerdata.Find(".bat");
if(fileend == -1) fileend = lowerdata.Find(".dll");
if(fileend == -1) fileend = lowerdata.Find(".com");
//If still no filending was found, ignore this
if(fileend == -1)
return true;
//Copy to real filename:
filename = value.Left(fileend + 4);
//If a space was found, fix this
if(filename.Find(' ') != -1)
{
//New in version 1.11
/*
Problems that wasn't problems then a with command like this:
notepad c:\autoexec.exe
notepad \\server\autoexec.exe
notepad %windir%\autoexec.exe
Very common in XP (with i rundll in beginning).
Solution: If a backslash is found _after_ the first space,
then this is probably ok.
*/
//Is the first backslash after the first space?
if( filename.Find('\\') > filename.Find(' ') )
return true;
//Do the file exist?
if(pek::mfcFileExist(filename))
//Make a new value... save the parameters
newValue = "\"" + filename + "\""
+ value.Right(value.GetLength() - filename.GetLength());
else
newValue = ""; //Delete this value
//This is not a legal value
return false;
}
//This is a legal value
return true;
}
void CPage2::DoUpdateList()
{
//Update listview
m_joblist.DeleteAllItems();
CString delvalue; //String "delete value"
delvalue.LoadString(IDS_LIST_DELETE);
for(UINT i = 0; i < joblist.size(); i++)
{
m_joblist.InsertItem(i, joblist[i].variable);
if(joblist[i].newvalue != "")
m_joblist.SetItem(i, 1, LVIF_TEXT, joblist[i].newvalue, NULL, NULL, NULL, i);
else
m_joblist.SetItem(i, 1, LVIF_TEXT, delvalue, NULL, NULL, NULL, i);
m_joblist.SetItem(i, 2, LVIF_TEXT, joblist[i].originalvalue, NULL, NULL, NULL, i);
m_joblist.SetItem(i, 3, LVIF_TEXT, CString(joblist[i].root + "\\...\\" + joblist[i].path), NULL, NULL, NULL, i);
m_joblist.SetCheck(i);
}
}
int CPage2::FixRegErrors()
{
//Stop if empty joblist
if(joblist.size() == 0)
return 0;
//Save number of errors...
int nErrors = m_joblist.GetItemCount();
//Stop if none is selected
for(int i = 0; i < m_joblist.GetItemCount(); i++)
if(m_joblist.GetCheck(i)) //found a selection
{
i=-1;
break;
}
//If a selection was found, i = -1
//If no selection, we doesn't have anything to do...
if(i != -1)
{
//We doesn't have anything to do... warn user and stop
CString mess;
mess.LoadString(IDS_MSG_NOERRORSSELECTED);
MessageBox(mess, NULL, MB_OK | MB_ICONWARNING);
return -1;
//return;
}
UpdateData();
//See if backupfile exist!!!!!!!!!!!
if(pek::mfcFileExist(m_backupfile))
{
//File already exist, stop
CString msg;
msg.LoadString(IDS_MGS_FILEEXIST);
MessageBox(msg, NULL, MB_OK | MB_ICONWARNING);
return -2;
}
//First, make a backup-file
CFile backup;
CFileException e;
CString latestKey, currentKey, line;
if(backup.Open(m_backupfile, CFile::modeCreate | CFile::modeWrite, &e) == 0)
{
//Couldn't create file, stop
CString msg;
msg.LoadString(IDS_MSG_CANTDOBACKUP);
MessageBox(msg, NULL, MB_OK + MB_ICONWARNING);
return -3;
}
//Write header
backup.Write("REGEDIT4", 8);
CString couldntWrite, //Values that couldn't be written
couldntErase; //Values that couldn't be erased.
//Write joblist
for(i = joblist.size() - 1; i >= 0 ; i--)
{
//Check if this value should be changed
if(m_joblist.GetCheck(i))
{
//Try to open registry key
HKEY hKey;
HKEY m_hRootKey = HKEY_LOCAL_MACHINE;
if(joblist[i].root == "HKEY_CURRENT_USER")
m_hRootKey = HKEY_CURRENT_USER;
ASSERT(joblist[i].path.GetLength() > 0);
//Open registry in current path
if (::RegOpenKeyEx( m_hRootKey,
LPCTSTR("Software\\Microsoft\\Windows\\CurrentVersion\\" + joblist[i].path),
0,
KEY_WRITE, &hKey)
!= ERROR_SUCCESS)
{
//If not possible to write, save that information
TRACE("Couldn't write value: %s to %s\n", joblist[i].root + joblist[i].path, joblist[i].newvalue);
if(joblist[i].newvalue != "")
{
couldntWrite += joblist[i].root + "\\Software\\Microsoft\\Windows\\CurrentVersion\\";
couldntWrite += joblist[i].path + "\\";
couldntWrite += joblist[i].variable + "\r\n";
}
else
{
TRACE("Couldn't delete value: %s to %s\n", joblist[i].root + joblist[i].path, joblist[i].newvalue);
couldntErase += joblist[i].root + "\\Software\\Microsoft\\Windows\\CurrentVersion\\";
couldntErase += joblist[i].path + "\\";
couldntErase += joblist[i].variable + "\r\n";
}
//Go to next job
continue;
}
//Before change in registry, write backupfile
currentKey = joblist[i].root + "\\Software\\Microsoft\\Windows\\CurrentVersion\\" + joblist[i].path;
//See if latest key was the same, if it was no [BLAHA] will be written
if(latestKey != currentKey)
{
//Whole path...
latestKey = currentKey;
backup.Write((CString)("\n\n[" + latestKey + "]"), latestKey.GetLength() +4 );
}
//Write variable and value
//line = "\n\"" + joblist[i].variable + "\"=\"" + joblist[i].originalvalue + "\"";
line = "\n\"" + joblist[i].variable + "\"=\"";
{
//line.Replace("\\", "\\\\");
CString temp = joblist[i].originalvalue;
//Change '\' to '\\'
temp.Replace(_T("\\"), _T("\\\\"));
//Change " to \"
temp.Replace(_T("\""), _T("\\\""));
line += temp;
}
line += "\"";
backup.Write(line, line.GetLength());
//Value in registry will now be changed....
if(joblist[i].newvalue != "")
{
::RegSetValueEx( hKey,
LPCTSTR(joblist[i].variable),
0,
REG_SZ,
(LPBYTE) ( (const TCHAR*) joblist[i].newvalue),
(joblist[i].newvalue.GetLength()+1)*sizeof(TCHAR)
);
}
else
//Delete variable
::RegDeleteValue(hKey, LPCTSTR(joblist[i].variable));
//Close registry
::RegCloseKey(hKey);
//Delete this from joblist
joblist.erase(joblist.begin() + i);
}
}
backup.Write("\n", 1); //Write new line at end
backup.Close(); //Close file
DoUpdateList();
//Link to message to the final window
CString& finalmessage = ((CPmfix*) GetParent())->finalmessage;
//Update status
if( couldntWrite != "" || couldntErase != "")
{
TRACE("Error was found, show error message to user.\n");
CString lastMessage;
if( couldntWrite != "")
{
//If variables couldnt be written
CString format;
format.Format(IDS_MSG_COULDNTWRITE, couldntWrite);
lastMessage += format;
}
if( couldntErase != "")
{
//If variables couldnt be erased
CString format;
format.Format(IDS_MSG_COULDNTERASE, couldntErase);
lastMessage += format;
}
CString message;
message.LoadString(IDS_MSG_COULDNTFIX);
message += lastMessage;
//Add backupfilename note
CString bufile;
bufile.Format(IDS_MSG_BUFILENAME, m_backupfile);
message += bufile;
finalmessage = message;
}
else
{
//Make status message...
//First, first line...
CString line1;
//All errors fixed?
if( joblist.size() == 0)
{
line1.LoadString(IDS_STATUS_FIXED_ALL);
}
else
line1.Format( IDS_STATUS_FIXED_SOME,
nErrors -joblist.size(),
nErrors
);
//Create text with backup info...
finalmessage .Format(IDS_STATUS_FIXED, m_backupfile);
//Insert first line first
finalmessage = line1 + finalmessage;
}
// TRACE("Final message: \r\n%s\r\n", finalmessage);
return joblist.size();
}
void CPage2::OnButtonBrowse()
{
UpdateData();
CString file, filefilter, extdefault;
filefilter.LoadString(IDS_MAIN_FILEFILTERSAVE);
extdefault.LoadString(IDS_MAIN_EXTENSIONDEFAULT);
if( pek::mfcOpenSave( file, false, this->GetSafeHwnd(), m_backupfile, m_backupfile,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, filefilter, extdefault ) )
m_backupfile = file;
UpdateData(false);
}
LRESULT CPage2::OnWizardNext()
{
TRACE("On next on page 2...\n");
//Any errors...?
if( FixRegErrors() < 0)
return -1;
return CPropertyPage::OnWizardNext();
}
void CPage2::OnButtonViewlog()
{
((CPmfix*) GetParent())->ViewLog();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -