int ChooseItemFromArchive(ArchiveFile& archive, bool autoChooseIfOnly1, const char** ignoreExtensions, int numIgnoreExtensions) { int prevNumIgnoreExtensions = numIgnoreExtensions; // prepare a list of files to choose from the archive ArchiveFileChooserInfo info (archive, ignoreExtensions, numIgnoreExtensions); // based on our list, decide which item in the archive to choose // check if there's nothing if(info.files.size() < 1) { // DialogsOpen++; MessageBox(GetArchiveParentHWND(), "The archive is either empty or encrypted.", "Nothing to load!", MB_OK | MB_ICONWARNING); // DialogsOpen--; return -1; } // if there's only 1 item, choose it if(info.files.size() == 1 && autoChooseIfOnly1 && numIgnoreExtensions == prevNumIgnoreExtensions) return info.files[0].itemIndex; // bring up a dialog to choose the index if there's more than 1 DialogBoxParam(hAppInst, MAKEINTRESOURCE(IDD_ARCHIVEFILECHOOSER), GetArchiveParentHWND(), (DLGPROC) ArchiveFileChooser,(LPARAM) &info); return s_archiveFileChooserResult; }
int ChooseItemFromArchive(ArchiveFile& archive, bool autoChooseIfOnly1, const char** ignoreExtensions, int numIgnoreExtensions) { int prevNumIgnoreExtensions = numIgnoreExtensions; archive.m_userMadeSelection = false; // prepare a list of files to choose from the archive ArchiveFileChooserInfo info (archive, ignoreExtensions, numIgnoreExtensions); // based on our list, decide which item in the archive to choose // check if there's nothing if(info.files.size() < 1) { MessageBox(GetArchiveParentHWND(), "The archive is either empty or encrypted.", "Nothing to load!", MB_OK | MB_ICONWARNING); return -1; } // warn if all the files in the archive have extensions we should ignore if(numIgnoreExtensions != prevNumIgnoreExtensions) { CString msg; msg.Format("The archive appears to only contain the wrong type of files.\n\n(in \"%s\")", archive.GetArchiveFileName()); int answer = MessageBox(GetArchiveParentHWND(), msg, "Warning", MB_OKCANCEL | MB_ICONWARNING | MB_DEFBUTTON2); if(answer == IDCANCEL) return -1; } // if there's only 1 item, choose it if(info.files.size() == 1 && autoChooseIfOnly1 && numIgnoreExtensions == prevNumIgnoreExtensions) return info.files[0].itemIndex; // bring up a dialog to choose the index if there's more than 1 DialogBoxParam(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDD_ARCHIVEFILECHOOSER), GetArchiveParentHWND(), (DLGPROC) ArchiveFileChooser,(LPARAM) &info); archive.m_userMadeSelection = (s_archiveFileChooserResult != -1); return s_archiveFileChooserResult; }