Skip to content

Commit

Permalink
[#37] Introductory guidepost for new users (Part 11: Improved determi…
Browse files Browse the repository at this point in the history
…nation of whether to auto-recognize a container or offer to user manual recognition)
  • Loading branch information
tomas-nestorovic committed Oct 3, 2019
1 parent 2a1f0a3 commit d51bc20
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
1 change: 0 additions & 1 deletion Main/src/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@
BY_SIDES =2
};

typedef DWORD TStdWinError; // Windows standard i/o error



Expand Down
4 changes: 2 additions & 2 deletions Main/src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@

afx_msg void CMainWindow::OnDropFiles(HDROP hDrop){
// a File from Windows Explorer dropped on the client area
extern bool recognizeDosAutomatically;
recognizeDosAutomatically=true;
extern CDos::PCProperties manuallyForceDos;
manuallyForceDos=nullptr; // Null = use automatic recognition
__super::OnDropFiles(hDrop);
}

Expand Down
16 changes: 14 additions & 2 deletions Main/src/TdiView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,21 @@
rcCurrContent.top=55*Utils::LogicalUnitScaleFactor, rcCurrContent.left=70*Utils::LogicalUnitScaleFactor, rcCurrContent.right-=16*Utils::LogicalUnitScaleFactor;
__addCategory__( _T("Recently accessed locations"), 0xf0cd );
BYTE i=0;
for( CRecentFileList *const pMru=app.GetRecentFileList(); i<4 && i<pMru->GetSize(); i++ ){ // 4 = max # of MRU files displayed in the GuidePost
for( CRideApp::CRecentFileListEx *const pMru=app.GetRecentFileList(); i<4 && i<pMru->GetSize(); i++ ){ // 4 = max # of MRU files displayed in the GuidePost
const CString &fileName=pMru->operator[](i);
if (fileName.IsEmpty())
break;
TCHAR dosName[80];
const CDos::PCProperties dosProps=pMru->GetDosMruFileOpenWith(i);
if (dosProps==&CUnknownDos::Properties)
::lstrcpy( dosName, _T("Auto") );
else if (const LPCTSTR space=::strchr(dosProps->name,' '))
::strncpy( dosName, dosProps->name, space-dosProps->name )[space-dosProps->name]='\0';
else
::lstrcpy( dosName, dosProps->name );
TCHAR buf[MAX_PATH];
::PathCompactPath( CClientDC(this), ::lstrcpy(buf,fileName), rcCurrContent.Width() );
::wsprintf( buf, _T("(%s) %s"), dosName, fileName );
::PathCompactPath( CClientDC(this), buf, rcCurrContent.Width() );
__addButton__( buf, ID_FILE_MRU_FILE1+i, 0xf030, 0x47bbbb );
}
if (!i)
Expand Down Expand Up @@ -229,6 +238,9 @@
afx_msg BOOL CRideApp::OnOpenRecentFile(UINT nID){
// opens document from the MRU files list under the given index
// - base
extern CDos::PCProperties manuallyForceDos;
const CDos::PCProperties dosProps=app.GetRecentFileList()->GetDosMruFileOpenWith(nID-ID_FILE_MRU_FIRST);
manuallyForceDos= dosProps==&CUnknownDos::Properties ? nullptr : dosProps;
if (!__super::OnOpenRecentFile(nID))
return FALSE;
// - if no Image opened, it wasn't found in which case it was removed from the MRU files list - projecting the updated MRU files list to the just shown introductory GuidePost
Expand Down
20 changes: 11 additions & 9 deletions Main/src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
struct TTmp sealed{ TCHAR profile[MAX_PATH]; }; // encapsulating the array into a structure - because MFC4.2 doesn't know the "new TCHAR[MAX_PATH]" operator!
PTCHAR pIniFileName=(new TTmp)->profile;
::GetModuleFileName(0,pIniFileName,MAX_PATH);
::lstrcpy( _tcsrchr(pIniFileName,'\\'), _T("\\RIDE.INI") );
::lstrcpy( _tcsrchr(pIniFileName,'\\'), _T("\\") APP_ABBREVIATION _T(".INI") );
m_pszProfileName=pIniFileName;
}else // for Windows Vista and newer ...
SetRegistryKey(_T("Real and Imaginary Disk Editor")); // ... list is stored to and read from system register (as INI files need explicit administrator rights)
SetRegistryKey(APP_FULLNAME); // ... list is stored to and read from system register (as INI files need explicit administrator rights)
LoadStdProfileSettings();
// - registering the only document template available in this application
AddDocTemplate(
Expand Down Expand Up @@ -161,7 +161,7 @@



bool recognizeDosAutomatically=true;
CDos::PCProperties manuallyForceDos=nullptr; // Null = use automatic recognition

#define ENTERING_LIMITED_MODE _T("\n\nContinuing to view the image in limited mode.")

Expand Down Expand Up @@ -228,7 +228,7 @@ openImage: if (image->OnOpenDocument(lpszFileName)){ // if opened successfully .
// - determining the DOS
CDos::PCProperties dosProps=nullptr;
TFormat formatBoot; // information on Format (# of Cylinders, etc.) obtained from Image's Boot record
if (recognizeDosAutomatically){
if (!manuallyForceDos){
// automatic recognition of suitable DOS by sequentially testing each of them
::SetLastError(ERROR_SUCCESS); // assumption (no errors)
dosProps=CDos::CRecognition().__perform__( image.get(), &formatBoot );
Expand Down Expand Up @@ -274,9 +274,11 @@ openImage: if (image->OnOpenDocument(lpszFileName)){ // if opened successfully .
// . showing the Dialog and processing its result
if (d.DoModal()!=IDOK)
return nullptr;
else{
formatBoot=( dosProps=d.dosProps )->stdFormats->params.format;
formatBoot.nCylinders++;
formatBoot=( dosProps=d.dosProps )->stdFormats->params.format;
formatBoot.nCylinders++;
if (const TStdWinError err=image->SetMediumTypeAndGeometry( &formatBoot, CDos::StdSidesMap, d.dosProps->firstSectorNumber )){
Utils::FatalError( _T("Can't change the medium geometry"), err, _T("The container can't be open.") );
return nullptr;
}
// . informing
Utils::InformationWithCheckableShowNoMore( _T("The image will be opened using the default format of the selected DOS (see the \"") BOOT_SECTOR_TAB_LABEL _T("\" tab if available).\n\nRISK OF DATA CORRUPTION if the selected DOS and/or format is not suitable!"), INI_GENERAL, INI_MSG_OPEN_AS );
Expand Down Expand Up @@ -304,13 +306,13 @@ openImage: if (image->OnOpenDocument(lpszFileName)){ // if opened successfully .

afx_msg void CRideApp::__openImage__(){
// opens Image and recognizes suitable DOS automatically
recognizeDosAutomatically=true;
manuallyForceDos=nullptr; // use automatic recognition
OnFileOpen();
}

afx_msg void CRideApp::__openImageAs__(){
// opens Image and lets user to determine suitable DOS
recognizeDosAutomatically=false;
manuallyForceDos=&CUnknownDos::Properties; // show dialog to manually pick a DOS
if (CMainWindow::CTdiTemplate::pSingleInstance->__closeDocument__()) // to close any previous Image
OnFileOpen();
}
Expand Down

0 comments on commit d51bc20

Please sign in to comment.