void CUpdateDlg::StartDownload() { m_info1.Format(_T("%s\n\n%s"), str_downloading, m_filename.c_str()); m_avgbps = 0; m_avgnumber = 0; m_filesize = 0; m_DownSize = 0; m_LastTimer = 0; m_LastTimerSize = 0; if(!FileExist(m_path.c_str())) CreateDirectory(m_path.c_str(), NULL); else if(!FileIsDirectory(m_path.c_str())) { DeleteFile(m_path.c_str()); CreateDirectory(m_path.c_str(), NULL); } m_progress.ShowWindow(SW_SHOW); DoDataExchange(); m_failtime = 0; m_down_index = StartDownloaderW(m_url.c_str(), m_path.c_str(), m_filename.c_str(), (FUNC_CallBack)Callback_Download, DOWNLOAD_WPARAM); }
std::string NormalizePath(std::string sPath) { std::string sFolder=sPath; std::string sFileName=GetFileName(sPath); std::deque<std::string> sFolders; std::string sFolderName; int nToSkip=0; while((sFolderName=GetFileName(sFolder))!="") { if(sFolder=="."){break;} if(sFolderName==".."){nToSkip++;} else if(sFolderName!="."){if(nToSkip){nToSkip--;}else{sFolders.push_back(sFolderName);}} sFolder=GetFileFolder(sFolder); } // Aqui sFolder contiene / en Linux y C:\ en windows std::string sNormalized=sFolder; std::deque<std::string>::reverse_iterator i; for(i=sFolders.rbegin();i!=sFolders.rend();i++) { sNormalized=AppendPathSeparator(sNormalized); sNormalized+=(*i); } if(FileIsDirectory(sNormalized.c_str())){sNormalized=AppendPathSeparator(sNormalized);} return sNormalized; }
void CGameGUIFileDialog::ProcessSelect() { std::string sFile=m_sFile; if(m_piEDPath){sFile=m_piEDPath->GetText();} if(FileIsDirectory(sFile.c_str())) { UpdateFiles(); return; } if(m_bOpenMode) { if(!FileExists(sFile.c_str())) { MessageDialog((std::string)"The file '"+sFile+"' does not exist.","Error",eMessageDialogType_Error); if(m_piEDPath){m_piGUIManager->SetFocus(m_piEDPath);} return; } } else { if(FileExists(sFile.c_str()) && m_bOverWriteWarn) { if(ConfirmDialog((std::string)"Overwrite '"+sFile+"' ?.","Warning!",eMessageDialogType_Warning)!=DIALOG_OK) { if(m_piEDPath){m_piGUIManager->SetFocus(m_piEDPath);} return; } } } m_sFile=sFile; EndDialog(DIALOG_OK); }
void DeleteFolder(CString dir) { if(FileIsDirectory(dir)) { //SHFILEOPSTRUCT Op; //ZeroMemory(&Op, sizeof(Op)); //删除文件夹 //Op.hwnd = NULL; //Op.wFunc = FO_DELETE; //Op.pFrom = dir; //Op.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION; //SHFileOperation(&Op); CFindFile tempFind; CString tempFileFind; tempFileFind.Format(_T("%s\\*.*"),dir); BOOL IsFinded = tempFind.FindFile(tempFileFind); while (IsFinded) { IsFinded = tempFind.FindNextFile(); if(!tempFind.IsDots()) { if(tempFind.IsDirectory()) DeleteFolder(tempFind.GetFilePath()); else DeleteFile(tempFind.GetFilePath()); } } tempFind.Close(); RemoveDirectory(dir); } }
/** * Move file or directory structure. */ static int FileMove( const String& sourcePath, const String& destinationPath) { if (FileIsDirectory(sourcePath)) { return FileMoveDirectory(sourcePath, destinationPath); } else if (FileExistsHelper(sourcePath)) { return FileMoveFile(sourcePath, destinationPath); } else { return -1; } }
/** * Delete a file or directory. If the file is a * directory it must me empty. */ static int FileDeleteFile(const String& pathParam) { String path = pathParam; if (FileIsDirectory(path)) { FileMakeDirectoryPath(path); } MAHandle file = maFileOpen(path.c_str(), MA_ACCESS_READ_WRITE); if (file < 0) { return -1; } int result = maFileDelete(file); maFileClose(file); return result; }
void PhoneGapFile::actionResolveLocalFileSystemURI(JSONMessage& message) { String callbackID = message.getParam("PhoneGapCallBackId"); String uri = message.getArgsField("uri"); // Get path. const char* pURL = uri.c_str(); const char* pPath = strstr(pURL, "file://"); if (NULL == pPath) { callFileError(callbackID, "1000"); return; } if (pURL != pPath) { callFileError(callbackID, FILEERROR_SYNTAX_ERR); return; } // Move to after "file://" pPath += 7; // Check that this is an existing directory. if (!FileIsDirectory(pPath)) { callFileError(callbackID, FILEERROR_NOT_FOUND_ERR); return; } String entry = emitDirectoryEntry( FileGetName(pPath), pPath); callSuccess( callbackID, entry, "window.localFileSystem._castEntry"); }
//I/maWriteLog(20616): @@@ URL: mosync://PhoneGap?service=File&action=moveTo&args={"fullPath":"/mnt/sdcard/hello2.txt","pa //rent":{"isFile":false,"isDirectory":true,"name":"sdcard","fullPath":"/mnt/sdcard","filesystem":null},"newName":"hello3.t //xt"}&PhoneGapCallBackId=File19 void PhoneGapFile::actionCopyMoveHelper(JSONMessage& message, bool move) { String callbackID = message.getParam("PhoneGapCallBackId"); String sourcePath = message.getArgsField("fullPath"); String destinationName = message.getArgsField("newName"); // Get the destination path from the JSON tree. String destinationPath; bool success = message.getJSONParamParentFullPath(destinationPath); if (!success) { callFileError(callbackID, FILEERROR_NO_MODIFICATION_ALLOWED_ERR); return; } // Check that we have the required path names. if ((sourcePath.size() == 0) || (destinationName.size() == 0) || (destinationPath.size() == 0)) { callFileError(callbackID, FILEERROR_NO_MODIFICATION_ALLOWED_ERR); return; } bool isDirectory; // Check that sourcePath exists. if (FileIsDirectory(sourcePath)) { isDirectory = true; } else if (FileExistsHelper(sourcePath)) { isDirectory = false; } else { callFileError(callbackID, FILEERROR_NO_MODIFICATION_ALLOWED_ERR); return; } // Compose the full destination path. String fullDestinationPath = destinationPath + "/" + destinationName; int result; if (move) { result = FileMove(sourcePath, fullDestinationPath); } else { result = FileCopy(sourcePath, fullDestinationPath); } if (result < 0) { callFileError(callbackID, FILEERROR_NOT_FOUND_ERR); return; } // Send back entry data. String entry; if (isDirectory) { entry = emitDirectoryEntry( destinationName, fullDestinationPath); } else { entry = emitFileEntry( destinationName, fullDestinationPath); } callSuccess( callbackID, entry, "window.localFileSystem._castEntry"); }