//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPrefabsDlg::OnAddlibrary() { Again: CEditPrefabDlg dlg; if(dlg.DoModal() == IDCANCEL) return; // check name if(!IsValidFilename(dlg.m_strName)) { if(AskAboutInvalidFilename() == IDOK) goto Again; return; // nevermind. } CPrefabLibraryRMF *pLibrary = new CPrefabLibraryRMF; pLibrary->SetName(dlg.m_strName); pLibrary->SetNotes(dlg.m_strDescript); // add to list int iIndex = m_Libraries.AddString(pLibrary->GetName()); m_Libraries.SetItemData(iIndex, pLibrary->GetID()); m_Libraries.SetCurSel(iIndex); OnSelchangeLibraries(); // to redraw description window bCurLibraryModified = TRUE; }
ZipArchiveEntry::Ptr ZipArchiveEntry::CreateNew(ZipArchive* zipArchive, const std::string& fullPath) { ZipArchiveEntry::Ptr result; assert(zipArchive != nullptr); if (IsValidFilename(fullPath)) { result.reset(new ZipArchiveEntry()); result->_archive = zipArchive; result->_isNewOrChanged = true; result->SetAttributes(Attributes::Archive); result->SetVersionToExtract(VERSION_NEEDED_DEFAULT); result->SetVersionMadeBy(VERSION_MADEBY_DEFAULT); result->SetLastWriteTime(time(nullptr)); result->SetFullName(fullPath); result->SetCompressionMethod(StoreMethod::CompressionMethod); result->SetGeneralPurposeBitFlag(BitFlag::None); } return result; }
ZipArchiveEntry::Ptr ZipArchiveEntry::CreateExisting(ZipArchive* zipArchive, detail::ZipCentralDirectoryFileHeader& cd) { ZipArchiveEntry::Ptr result; assert(zipArchive != nullptr); if (IsValidFilename(cd.Filename)) { result.reset(new ZipArchiveEntry()); result->_archive = zipArchive; result->_centralDirectoryFileHeader = cd; result->_originallyInArchive = true; result->CheckFilenameCorrection(); // determining folder by path has more priority // than attributes. however, if attributes // does not correspond with path, they will be fixed. result->SetAttributes(IsDirectoryPath(result->GetFullName()) ? Attributes::Directory : Attributes::Archive); } return result; }
VSIVirtualHandle* VSIPluginFilesystemHandler::Open( const char *pszFilename, const char *pszAccess, bool bSetError ) { if( !IsValidFilename(pszFilename) ) return nullptr; void *cbData = m_cb->open(m_cb->pUserData, GetCallbackFilename(pszFilename), pszAccess); if (cbData == nullptr) { if (bSetError) { VSIError(VSIE_FileError, "%s: %s", pszFilename, strerror(errno)); } return nullptr; } return new VSIPluginHandle(this, cbData); }
int VSIPluginFilesystemHandler::Stat( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags ) { if( !IsValidFilename(pszFilename) ) { errno = EBADF; return -1; } memset(pStatBuf, 0, sizeof(VSIStatBufL)); int nRet = 0; if ( m_cb->stat != nullptr ) { nRet = m_cb->stat(m_cb->pUserData, GetCallbackFilename(pszFilename), pStatBuf, nFlags); } else { nRet = -1; } return nRet; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPrefabsDlg::OnEditlibrary() { // get selection int iSel; CPrefabLibrary *pLibrary = GetCurrentLibrary(&iSel); if(!pLibrary) return; CEditPrefabDlg dlg; dlg.m_strName = pLibrary->GetName(); dlg.m_strDescript = pLibrary->GetNotes(); Again: if(dlg.DoModal() == IDCANCEL) return; // check name if(!IsValidFilename(dlg.m_strName)) { if(AskAboutInvalidFilename() == IDOK) goto Again; return; // nevermind. } pLibrary->SetName(dlg.m_strName); pLibrary->SetNotes(dlg.m_strDescript); // set in list m_Libraries.SetRedraw(FALSE); m_Libraries.DeleteString(iSel); int iIndex = m_Libraries.InsertString(iSel, pLibrary->GetName()); m_Libraries.SetItemData(iIndex, pLibrary->GetID()); m_Libraries.SetRedraw(TRUE); m_Libraries.Invalidate(); m_Libraries.SetCurSel(iSel); OnSelchangeLibraries(); // to redraw description window bCurLibraryModified = TRUE; }
// // See help text within for an explanation of the expected parameters. // void CGalileoCmdLine::ParseParam(const char *pszParam, BOOL bFlag, BOOL bLast) { static int param_count = 0; static char last_switch = 0; char temp_switch; param_count++; if (m_bFail) { // If command line parsing has failed before, don't // try to interpret the command line further. return; } if (bFlag && strlen(pszParam) != 1) { Fail("Exactly one letter must follow a switch character. " "Switch characters are \"/\" and \"-\"."); return; } if (pszParam[0] == '?') { // get Syntax display string from resource file CString version; CString syntax; version.Format(IDS_VERSION_OUTPUT, (LPCTSTR) theApp.GetVersionString(TRUE)); VERIFY(syntax.LoadString(IDS_CMDLINE_SYNTAX)); AfxMessageBox(version + "\n\n" + syntax); m_bFail = TRUE; return; } if (last_switch) { temp_switch = last_switch; last_switch = 0; // Previous switch expects another parameter. switch (temp_switch) { // Expecting the config file. case 'C': if (!m_sConfigFile.IsEmpty()) // has it already been set? { Fail("Config file parameter was specified more than once."); } else if (IsValidFilename(pszParam)) { if (VerifyReadable(pszParam)) m_sConfigFile = pszParam; else m_bFail = TRUE; } else { Fail("C switch should be followed by the name of a configuration file."); } return; // Expecting the result file. case 'R': if (!m_sResultFile.IsEmpty()) // has it already been set? { Fail("Result file parameter was specified more than once."); } else if (IsValidFilename(pszParam)) { if (VerifyWritable(pszParam)) m_sResultFile = pszParam; else m_bFail = TRUE; } else { Fail("R switch should be followed by the name of the desired result file."); } return; // Expecting the timeout value. case 'T': if (m_iTimeout >= 0) // has it already been set? { Fail("Timeout parameter was specified more than once."); } else if (IsValidInteger(pszParam)) { m_iTimeout = atoi(pszParam); } else { Fail("T switch should be followed by an integer timeout value."); } return; // Expecting the port number case 'P': if (m_iLoginportnumber > 0) // has it already been set? { Fail("Login port number parameter was specified more than once."); } else if (IsValidInteger(pszParam)) { m_iLoginportnumber = atoi(pszParam); if (m_iLoginportnumber < 1 || m_iLoginportnumber > 65535) Fail("P switch should be followed by a valid port value (1-65535)."); } else { Fail("P switch should be followed by a valid port value (1-65535)."); } return; // Check if need to show Bigmeter automatically case 'M': if (m_bShowBigmeter == TRUE) // has it already been set? { Fail("Show Bigmeter parameter was specified more than once."); } else { int i = atoi(pszParam); if (i == 1) m_bShowBigmeter = TRUE; } return; default: { char tmpary[2] = { last_switch, 0 }; Fail("Unrecognized switch: " + (CString) tmpary + "."); } return; } } if (bFlag) { m_bSwitches = TRUE; last_switch = toupper(pszParam[0]); ////////////////////////////////////////////////////////////////////// // This is an example of how to allow switches that have meaning on // their own, without any additional parameters. // // if ( last_switch == 'V' ) // spit out version number and exit // { // // Set BOOL member indicating that this switch was specified // // Make sure it's initialized in the constructor // m_bVersion = TRUE; // // last_switch = 0; // don't look for more parameters related to this switch // return; // don't allow it to reach the bLast checking // } ////////////////////////////////////////////////////////////////////// if (bLast) { Fail("An additional parameter was expected after the last switch."); return; } return; } // If switches haven't been used (so far)... if (!m_bSwitches) { switch (param_count) { // Expecting the config file. case 1: if (IsValidFilename(pszParam)) { if (VerifyReadable(pszParam)) m_sConfigFile = pszParam; else m_bFail = TRUE; } else { Fail("First parameter should be the name of a valid config file."); } return; // Expecting the result file. case 2: if (IsValidFilename(pszParam)) { if (VerifyWritable(pszParam)) m_sResultFile = pszParam; else m_bFail = TRUE; } else { Fail("Second parameter should be the name of the result file."); } return; // Expecting the timeout value. case 3: if (IsValidInteger(pszParam)) { m_iTimeout = atoi(pszParam); } else { Fail("Third parameter should be an integer timeout value."); } return; default: Fail("Too many parameters."); return; } } Fail("Didn't know what to do with this parameter:\n" + (CString) pszParam + "\nPlease report this as an Iometer bug."); }
BOOL OnNotify(HWND hDlg, LPNMHDR lpNMHdr) { //DEBUGMESSAGE(("OnNotify")); UINT uiCode = lpNMHdr->code; switch (uiCode) { case PSN_APPLY: { DEBUGMESSAGE(("OnNotify - PSN_APPLY")); DocumentPropDialogData *data = (DocumentPropDialogData *) GetWindowLongPtr(hDlg, DWL_USER); if (data == NULL) { DEBUGMESSAGE(("DocPropDlgProc - invalid internal data pointer")); return FALSE; } // which format combo should we use? LPTSTR format = NULL; if (IsDlgButtonChecked(hDlg, IDC_VECTOR_FORMAT_RADIOBOX) == BST_CHECKED) { INT sel = GetComboCurSel(GetDlgItem(hDlg, IDC_COMBO_VECTOR_FORMAT)); format = strDuplicate(g_vectorFormats[sel].strName); } else if (IsDlgButtonChecked(hDlg, IDC_RASTER_FORMAT_RADIOBOX) == BST_CHECKED) { INT sel = GetComboCurSel(GetDlgItem(hDlg, IDC_COMBO_RASTER_FORMAT)); format = strDuplicate(g_rasterFormats[sel].strName); } else { DEBUGMESSAGE(("DocPropDlgProc - unexpected condition")); return FALSE; } // get the output folder & validate it LPTSTR folder = NULL; if (!GetEditControlText(&folder, GetDlgItem(hDlg, IDC_OUTPUT_FOLDER))) { DEBUGMESSAGE(("DocPropDlgProc - could not get output folder text")); return FALSE; } if (!FolderExists(folder)) { ErrorMessage(hDlg, TEXT("Warning"), TEXT("The given output directory does not exist!")); return FALSE; } // get the output filename & validate it LPTSTR filename = NULL; if (!GetEditControlText(&filename, GetDlgItem(hDlg, IDC_OUTPUT_FILENAME))) { DEBUGMESSAGE(("DocPropDlgProc - could not get output filename text")); return FALSE; } if (!IsValidFilename(filename)) { LPTSTR temp = strCat(TEXT("The given output filename is not valid!\n"), TEXT("It should not contain any of the '"), g_strFileNameForbiddenChars, TEXT("' characters."), NULL); ErrorMessage(hDlg, TEXT("Warning"), temp); strFree(temp); return FALSE; } // get the raster conv options LPTSTR rasteropt = NULL; if (!GetEditControlText(&rasteropt, GetDlgItem(hDlg, IDC_IMAGEMAGICK_OPTIONS))) { DEBUGMESSAGE(("DocPropDlgProc - could not get raster conv opt text")); return FALSE; } // get the postgen cmd LPTSTR postgen = NULL; if (!GetEditControlText(&postgen, GetDlgItem(hDlg, IDC_POSTGEN_CMD))) { DEBUGMESSAGE(("DocPropDlgProc - could not get postgen cmd text")); return FALSE; } // get override checkbox status BOOL override = IsDlgButtonChecked(hDlg, IDC_OVERRIDE_CHECKBOX) == BST_CHECKED; // get crop checkbox BOOL crop = IsDlgButtonChecked(hDlg, IDC_CROP_CHECKBOX) == BST_CHECKED; // get open-output checkbox BOOL openout = IsDlgButtonChecked(hDlg, IDC_OPEN_VIEWER_CHECKBOX) == BST_CHECKED; // save all data in the EXTDEVMODE extdmSetPrivateData(data->m_pExtdmCurrent, format, filename, folder, rasteropt, postgen, override, openout, crop); // cleanup strFree(format); strFree(filename); strFree(folder); strFree(postgen); strFree(rasteropt); // call the _SET_RESULT callback PFNCOMPROPSHEET pfnComPropSheet = data->m_pfnComPropSheet; LONG lTemp = pfnComPropSheet( data->m_hComPropSheet, CPSFUNC_SET_RESULT, (LPARAM) data->m_hPropSheetAdded, CPSUI_OK ); return TRUE; } break; case PSN_RESET: break; case PSN_SETACTIVE: break; default: break; } return FALSE; }
int VSIPluginFilesystemHandler::Rmdir(const char *pszDirname) { if( m_cb->rmdir == nullptr || !IsValidFilename(pszDirname) ) return -1; return m_cb->rmdir(m_cb->pUserData, GetCallbackFilename(pszDirname)); }
int VSIPluginFilesystemHandler::Rename(const char *oldpath, const char *newpath) { if( m_cb->rename == nullptr || !IsValidFilename(oldpath) || !IsValidFilename(newpath) ) return -1; return m_cb->rename(m_cb->pUserData, GetCallbackFilename(oldpath), GetCallbackFilename(newpath)); }
int VSIPluginFilesystemHandler::Unlink(const char *pszFilename) { if( m_cb->unlink == nullptr || !IsValidFilename(pszFilename) ) return -1; return unlink(GetCallbackFilename(pszFilename)); }