static int UpgradeNSIS(void) { std::string installPath = GetNSISInstallPath(); if (installPath.empty()) return 0; std::string uninstallerPath = installPath + "\\uninstall.exe"; if (!PathExists(uninstallerPath)) return 0; std::string dataPath = GetIcingaDataPath(); if (dataPath.empty()) return 1; bool moveUserData = !PathExists(dataPath); /* perform open heart surgery on the user's data dirs - yay */ if (moveUserData) { MkDir(dataPath.c_str()); std::string oldNameEtc = installPath + "\\etc"; std::string newNameEtc = dataPath + "\\etc"; if (!CopyDirectory(oldNameEtc, newNameEtc)) return 1; std::string oldNameVar = installPath + "\\var"; std::string newNameVar = dataPath + "\\var"; if (!CopyDirectory(oldNameVar, newNameVar)) return 1; } ExecuteCommand(uninstallerPath, "/S _?=" + installPath); _unlink(uninstallerPath.c_str()); if (moveUserData) { std::string oldNameEtc = installPath + "\\etc"; if (!DeleteDirectory(oldNameEtc)) return 1; std::string oldNameVar = installPath + "\\var"; if (!DeleteDirectory(oldNameVar)) return 1; _rmdir(installPath.c_str()); } return 0; }
bool CopyDirectory( const wxString& from, const wxString& to ) { wxDir src( from ); if ( !src.IsOpened() ) { return false; } wxMkdir( to ); wxDir dst( to ); if ( !dst.IsOpened() ) { return false; } wxString filename; // copy directories if ( src.GetFirst( &filename, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN ) ) { do { if ( !CopyDirectory( wxFileName( from, filename ).GetFullPath(), wxFileName( to, filename ).GetFullPath() ) ) { return false; } } while ( src.GetNext( &filename ) ); } // copy files if ( src.GetFirst( &filename, wxEmptyString, wxDIR_FILES | wxDIR_HIDDEN ) ) { do { if ( !wxCopyFile( wxFileName( from, filename ).GetFullPath(), wxFileName( to, filename ).GetFullPath() ) ) { return false; } } while ( src.GetNext( &filename ) ); } return true; }
BOOL WINAPI CopyProfileDirectoryW(LPCWSTR lpSourcePath, LPCWSTR lpDestinationPath, DWORD dwFlags) { /* FIXME: dwFlags are ignored! */ return CopyDirectory(lpDestinationPath, lpSourcePath); }
//--------------------------------------------------------------------- // CopyObjectToFileSystem(): //--------------------------------------------------------------------- BOOL WPDIRECTORY::CopyObjectToFileSystem(char *pszDestPath) { char szDestPath[_MAX_PATH+1]; // Create destination directory name fully qualified. sprintf(szDestPath,"%s\\%s",pszDestPath,MakeFATName((char *)GetTitleNoCRLF())); // Copy directory recursively. return (CopyDirectory(GetPath(),szDestPath)); }
void GenesisCopyWindow::Copy(const char *filename, const char *destination, const char *destfilename) //////////////////////////////////////////////////////////////////////// { BEntry sourcefile(filename); BString text; if (sourcefile.InitCheck()==B_OK) { /* BString text; text.SetTo(""); text << filename << "\n" << destination; BAlert *myAlert = new BAlert("Copy debug",text.String(),"OK", NULL, NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT); myAlert->Go(); */ if (sourcefile.IsDirectory()) { if (IsRecursiveCopy(filename, destination)) { BString text; text << "Recursive copy not allowed.\nPlease check the destination folder."; BAlert *myAlert = new BAlert("Copy",text.String(),"OK", NULL, NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT); myAlert->Go(); Close(); kill_thread(m_CopyThread); } CopyDirectory(filename, destination, destfilename); } else if (sourcefile.IsSymLink()) CopyLink(filename,destination, destfilename); else CopyFile(filename, destination, destfilename); } else if (!m_SkipAllCopyError) { text << "Error while initializing file:\n\n" << filename; BAlert *myAlert = new BAlert("Copy",text.String(),"Abort","Skip all","Skip",B_WIDTH_AS_USUAL,B_OFFSET_SPACING,B_WARNING_ALERT); myAlert->SetShortcut(0, B_ESCAPE); switch (myAlert->Go()) { case 0: Close(); kill_thread(m_CopyThread); break; case 1: m_SkipAllCopyError = true; break; } } }
/** * @brief 拷贝目录 * @param[in] szSrcDir 源目录 * @param[in] szDstDir 目标目录 * @param[in] bCoverFile 是否覆盖已存在的文件 * @return 返回拷贝文件的数目 * @see */ static int CopyDirectory(LPCTSTR lpSrcDir, LPCTSTR lpDstDir, BOOL bCoverFile = TRUE) { if (!lpSrcDir || !lpDstDir) return 0; int nReturn = 0; CString strFind; CString strSubFile; CString strSubDstFile; CString strSrcDir(lpSrcDir); CString strDstDir(lpDstDir); WIN32_FIND_DATA FindFileData; HANDLE hFind = INVALID_HANDLE_VALUE; ZLPath::PathAddBackslash(strSrcDir); ZLPath::PathAddBackslash(strDstDir); CreateDeepDirectory(strDstDir); strFind.Format(_T("%s*.*"), strSrcDir); hFind = ::FindFirstFile(strFind, &FindFileData); if (hFind == INVALID_HANDLE_VALUE) goto Exit0; do { if (_tcscmp(FindFileData.cFileName, _T(".")) == 0 || _tcscmp(FindFileData.cFileName, _T("..")) == 0) continue; if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { strSubFile.Format(_T("%s%s\\"), strSrcDir, FindFileData.cFileName); strSubDstFile.Format(_T("%s%s\\"), strDstDir, FindFileData.cFileName); CreateDeepDirectory(strSubDstFile); nReturn += CopyDirectory(strSubFile, strSubDstFile, !bCoverFile); } else { strSubFile.Format(_T("%s%s"), strSrcDir, FindFileData.cFileName); strSubDstFile.Format(_T("%s%s"), strDstDir, FindFileData.cFileName); if (!::CopyFile(strSubFile, strSubDstFile, !bCoverFile)) nReturn++; } } while (::FindNextFile(hFind, &FindFileData) != 0); Exit0: if (hFind != INVALID_HANDLE_VALUE) ::FindClose(hFind); return nReturn; }
//***************************************************************************** // You can use this function to create backups in the way that you copy all // files recursive into a folder under the installation folder. So the whole tree // of the previous installation in lDir can be copied into lSubdir. //***************************************************************************** long WINAPI RecursiveCopyIntoSubdir(long lDir,long lSubdir) { TCHAR DirToCopy[MAX_PATH+1]; TCHAR SubDir[MAX_PATH+1]; TCHAR SupressSubDir[MAX_PATH+1]; // Verzeichnis ist notwendig! if(lDir==0) return 1; memset(DirToCopy,0,sizeof(DirToCopy)); memset(SubDir,0,sizeof(SubDir)); memset(SupressSubDir,0,sizeof(SupressSubDir)); _tcsncpy(DirToCopy,(TCHAR*)lDir,MAX_PATH); if(DirToCopy[_tcslen(DirToCopy)-1] != '\\') _tcsncat(DirToCopy,"\\",MAX_PATH); // Übertragen in Unterverzeichnis SubDir[0] = '\0'; _tcsncat(SubDir,DirToCopy,MAX_PATH); if(lSubdir==0) _tcsncat(SubDir,"bak",MAX_PATH); else _tcsncat(SubDir,(TCHAR*)lSubdir,MAX_PATH); if(SubDir[_tcslen(SubDir)-1] != '\\') _tcsncat(SubDir,"\\",MAX_PATH); // Erzeugen des Unterverzeichnisses CreateDirectory(SubDir,NULL); // Übertragen in Supress-Verzeichnis _tcscpy(SupressSubDir,SubDir); return CopyDirectory(DirToCopy,SubDir,SupressSubDir); return 0; };
bool GalleryUtil::Copy(const QFileInfo &src, QFileInfo &dst) { if (src.isDir()) return CopyDirectory(src, dst); dst = MakeUnique(dst); if (!FileCopy(src, dst)) return false; MSqlQuery query(MSqlQuery::InitCon()); query.prepare("INSERT INTO gallerymetadata (image, angle) " "SELECT :IMAGENEW , angle " "FROM gallerymetadata " "WHERE image = :IMAGEOLD"); query.bindValue(":IMAGENEW", dst.absoluteFilePath()); query.bindValue(":IMAGEOLD", src.absoluteFilePath()); if (query.exec()) return true; // try to undo copy on DB failure FileDelete(dst); return false; }
int CopyDirectory(const char *src_path, const char *dest_path, int verbose) { file_t fd = fs_open(src_path, O_RDONLY | O_DIR); if(fd != FILEHND_INVALID) { char Path[MAX_FN_LEN], *EndPtr = Path; char PathDest[MAX_FN_LEN], *EndDestPtr = PathDest; dirent_t *e; strcpy(Path, src_path); Path[strlen(src_path)] = '/'; EndPtr += (strlen(src_path)+1); strcpy(PathDest, dest_path); if(!DirExists(PathDest)) { if(verbose) { ds_printf("DS_PROCESS: Making directory: %s\n", PathDest); } if(fs_mkdir(PathDest)) { ds_printf("DS_ERROR: Can't make directory %s\n", PathDest); fs_close(fd); return 0; } } PathDest[strlen(dest_path)] = '/'; EndDestPtr += (strlen(dest_path)+1); while((e = fs_readdir(fd)) != NULL) { strcpy(EndPtr, e->name); strcpy(EndDestPtr, e->name); if(e->attr == O_DIR) { if(verbose) { ds_printf("DS_PROCESS: Making directory: %s\n", PathDest); } if(!fs_mkdir(PathDest)) { CopyDirectory(Path, PathDest, verbose); } else { ds_printf("DS_ERROR: Can't make directory %s\n", PathDest); fs_close(fd); return 0; } } else { if(!CopyFile(Path, PathDest, verbose)) { fs_close(fd); return 0; } } } fs_close(fd); return 1; } return 0; }
bool FileUtilities::CopyDirectory(String sFrom, String sTo, String &errorMessage) { if (!FileUtilities::Exists(sTo)) { if( !CreateDirectory(sTo)) { errorMessage = Formatter::Format(_T("CreateDirectory {0} failed. See previous error."), sTo); ErrorManager::Instance()->ReportError(ErrorManager::Medium, 4234, "File::CopyDirectory", errorMessage); return false; } } if (sFrom.Right(1) != _T("\\")) sFrom += "\\"; if (sTo.Right(1) != _T("\\")) sTo += "\\"; String sWildCard = sFrom + "*.*"; // Locate first match WIN32_FIND_DATA ffData; HANDLE hFileFound = FindFirstFile(sWildCard, &ffData); if (hFileFound == INVALID_HANDLE_VALUE) { errorMessage.Format(_T("Find first file with wildcard %s failed. Error: %d."), sWildCard, GetLastError()); ErrorManager::Instance()->ReportError(ErrorManager::Medium, 4233, "File::CopyDirectory", errorMessage); return false; } while (hFileFound && FindNextFile(hFileFound, &ffData)) { String sOldFullPath = sFrom + ffData.cFileName; String sNewFullPath = sTo + ffData.cFileName; if (ffData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { if( (_tcscmp(ffData.cFileName, _T(".")) != 0) && (_tcscmp(ffData.cFileName, _T("..")) != 0) ) { if( !CopyDirectory(sOldFullPath, sNewFullPath, errorMessage) ) return false; } } else { if (FileUtilities::Exists(sNewFullPath)) { // File already exists continue; } if (CopyFile(sOldFullPath, sNewFullPath, TRUE)) { // We have copied the file successfully continue; } // We failed to copy the file. Check if the file no // longer exists if (!FileUtilities::Exists(sOldFullPath)) continue; // The file exists , but we were not able to copy it. errorMessage.Format(_T("Copy of file from %s to %s failed. Error: %d"), sOldFullPath, sNewFullPath, GetLastError()); ErrorManager::Instance()->ReportError(ErrorManager::Medium, 4232, "File::CopyDirectory", errorMessage); return false; } } FindClose(hFileFound); return true; }
BOOL CopyDirectory (LPCWSTR lpDestinationPath, LPCWSTR lpSourcePath) { WCHAR szFileName[MAX_PATH]; WCHAR szFullSrcName[MAX_PATH]; WCHAR szFullDstName[MAX_PATH]; WIN32_FIND_DATAW FindFileData; LPWSTR lpSrcPtr; LPWSTR lpDstPtr; HANDLE hFind; DPRINT ("CopyDirectory (%S, %S) called\n", lpDestinationPath, lpSourcePath); wcscpy (szFileName, lpSourcePath); wcscat (szFileName, L"\\*.*"); hFind = FindFirstFileW (szFileName, &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { DPRINT1 ("Error: %lu\n", GetLastError()); return FALSE; } wcscpy (szFullSrcName, lpSourcePath); lpSrcPtr = AppendBackslash (szFullSrcName); wcscpy (szFullDstName, lpDestinationPath); lpDstPtr = AppendBackslash (szFullDstName); for (;;) { if (wcscmp (FindFileData.cFileName, L".") && wcscmp (FindFileData.cFileName, L"..")) { wcscpy (lpSrcPtr, FindFileData.cFileName); wcscpy (lpDstPtr, FindFileData.cFileName); if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { DPRINT ("Create directory: %S\n", szFullDstName); if (!CreateDirectoryExW (szFullSrcName, szFullDstName, NULL)) { if (GetLastError () != ERROR_ALREADY_EXISTS) { DPRINT1 ("Error: %lu\n", GetLastError()); FindClose (hFind); return FALSE; } } if (!CopyDirectory (szFullDstName, szFullSrcName)) { DPRINT1 ("Error: %lu\n", GetLastError()); FindClose (hFind); return FALSE; } } else { DPRINT ("Copy file: %S -> %S\n", szFullSrcName, szFullDstName); if (!CopyFileW (szFullSrcName, szFullDstName, FALSE)) { DPRINT1 ("Error: %lu\n", GetLastError()); FindClose (hFind); return FALSE; } } } if (!FindNextFileW (hFind, &FindFileData)) { if (GetLastError () != ERROR_NO_MORE_FILES) { DPRINT1 ("Error: %lu\n", GetLastError()); } break; } } FindClose (hFind); DPRINT ("CopyDirectory() done\n"); return TRUE; }
DWORD CopyDirectory(TCHAR* sourcepath, TCHAR* destpath, TCHAR* supresspath) { WIN32_FIND_DATA FindData; TCHAR SearchName[MAX_PATH+1]; HANDLE SearchHandle = INVALID_HANDLE_VALUE; typedef queue<FILENAME_PAIR*> FILENAME_QUEUE; FILENAME_QUEUE CopyfileQueue; memset(&FindData,0,sizeof(FindData)); memset(SearchName,0,sizeof(SearchName)); // Testen: ist das Verzeichnis identisch oder "länger" als supresspath? // Wenn ja kann an dieser Stelle aufgegeben werden. if((supresspath)&&(_tcsnicmp(sourcepath,supresspath,_tcslen(supresspath))==0)) return 0; _tcsncat(SearchName,sourcepath,MAX_PATH); _tcsncat(SearchName,"*.*",MAX_PATH); SearchHandle = FindFirstFile(SearchName,&FindData); // Nicht erfolgreich? if(SearchHandle==INVALID_HANDLE_VALUE) return 0; BOOLEAN bFileFound = TRUE; while(bFileFound) { // Stelle fest: Ist es eine Datei oder ein Verzeichnis? if(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // Ausfiltern von "." und ".." Verzeichnissen if(!((_tcsicmp(FindData.cFileName,".")==0)||(_tcsicmp(FindData.cFileName,"..")==0))) { // Es ist ein Verzeichnis. Dieses muß rekursiv bearbeitet werden. TCHAR SubdirSourceName[MAX_PATH+1]; TCHAR SubdirDestName[MAX_PATH+1]; _snprintf(SubdirSourceName,MAX_PATH,"%s%s\\",sourcepath,FindData.cFileName); _snprintf(SubdirDestName,MAX_PATH,"%s%s\\",destpath,FindData.cFileName); // Erzeugen des Unterverzeichnisses CreateDirectory(SubdirDestName,NULL); CopyDirectory(SubdirSourceName,SubdirDestName,supresspath); }; } else { // Kopieren der Datei // TCHAR SourceFileName[MAX_PATH+1]; // TCHAR DestFileName[MAX_PATH+1]; // _snprintf(SourceFileName,MAX_PATH,"%s%s",sourcepath,FindData.cFileName); // _snprintf(DestFileName,MAX_PATH,"%s%s",destpath,FindData.cFileName); FILENAME_PAIR* fp = new FILENAME_PAIR; _snprintf(fp->Source,MAX_PATH,"%s%s",sourcepath,FindData.cFileName); _snprintf(fp->Dest,MAX_PATH,"%s%s",destpath,FindData.cFileName); CopyfileQueue.push(fp); // DWORD dwErg = CopyFile(SourceFileName,DestFileName,FALSE); // if(dwErg==0) // DWORD dwError = GetLastError(); }; // Nächste Datei suchen bFileFound = FindNextFile(SearchHandle,&FindData); }; // Aufräumen if(SearchHandle!=INVALID_HANDLE_VALUE) FindClose(SearchHandle); while(!CopyfileQueue.empty()) { FILENAME_PAIR* fp = CopyfileQueue.front(); CopyfileQueue.pop(); if(fp) { DWORD dwErg = CopyFile(fp->Source,fp->Dest,FALSE); if(dwErg==0) DWORD dwError = GetLastError(); delete fp; }; }; return 0; };
bool ProjectGenerator::Make() { NGL_OUT(_T("nui project generator\n")); // create target directory nglPath targetpath = nglPath(mProjectTargetPath); if (!targetpath.Create()) { nglString msg; msg.Format(_T("creating target directory '%ls'"), targetpath.GetChars()); return MsgError(msg); } NGL_OUT(_T("nui project generator : target directory created '%ls'\n"), targetpath.GetChars()); //copy the src folder if (!CopyDirectory(targetpath + nglPath(_T("src")), mNuiTemplatePath + nglPath(_T("src")))) return false; //copy the resources folders if (!CopyDirectory(targetpath + nglPath(_T("resources")), mNuiTemplatePath + nglPath(_T("resources")))) return false; if (!CopyDirectory(targetpath + nglPath(_T("resources/css")), mNuiTemplatePath + nglPath(_T("resources/css")))) return false; if (!CopyDirectory(targetpath + nglPath(_T("resources/decorations")), mNuiTemplatePath + nglPath(_T("resources/decorations")))) return false; nglPath projpath; nglPath projectfile; nglString filename; // create xcodeproj folder if (mpCheckXcode->IsPressed()) { projpath = targetpath; nglString projfolder = mProjectName + nglString(_T(".xcodeproj")); projpath += nglPath(projfolder); if (!projpath.Create()) { nglString msg; msg.Format(_T("creating xcodeproj folder '%ls'"), projpath.GetChars()); return MsgError(msg); } NGL_OUT(_T("nui project generator : project folder created '%ls'\n"), projpath.GetChars()); // generate xcode project file projectfile = targetpath; projectfile += nglPath(projfolder); projectfile += nglPath(_T("project.pbxproj")); if (!GenerateFile(mNuiTemplatePath + nglPath(_T("TemplateApp.xcodeproj/project.pbxproj")), projectfile)) return false; } // generate visual studio 2008 project file if (mpCheckVisualStudio2008->IsPressed()) { filename = mProjectName + nglString(_T(".2008.vcproj")); projectfile = targetpath; projectfile += nglPath(filename); if (!GenerateFile(mNuiTemplatePath + nglPath(_T("TemplateApp.2008.vcproj")), projectfile)) return false; } // generate visual studio 2008 solution file if (mpCheckVisualStudio2008->IsPressed()) { filename = mProjectName + nglString(_T(".2008.sln")); projectfile = targetpath; projectfile += nglPath(filename); if (!GenerateFile(mNuiTemplatePath + nglPath(_T("TemplateApp.2008.sln")), projectfile)) return false; } // generate Info.plist if (mpCheckXcode->IsPressed()) { filename = mProjectName + nglString(_T(".plist")); projectfile = targetpath; projectfile += nglPath(filename); if (!GenerateFile(mNuiTemplatePath + nglPath(_T("TemplateApp.plist")), projectfile)) return false; } // generate iPhone Info.plist if (mpCheckXcode->IsPressed()) { filename = mProjectName + nglString(_T("-iPhone.plist")); projectfile = targetpath; projectfile += nglPath(filename); if (!GenerateFile(mNuiTemplatePath + nglPath(_T("TemplateApp-iPhone.plist")), projectfile)) return false; } // generate resource.rc filename = _T("resource.rc"); projectfile = targetpath; projectfile += nglPath(filename); if (!GenerateFile(mNuiTemplatePath + nglPath(_T("resource.rc")), projectfile)) return false; nglString msg; msg.Format(_T("nui project '%ls' successfully generated!"), mProjectName.GetChars()); nuiMessageBox* pMessageBox = new nuiMessageBox(GetMainWindow(), nglString(_T("Project Creator")), msg, eMB_OK); pMessageBox->QueryUser(); return true; }
int WiiSave::Download(std::string ID) { if(ID.empty()) return -1; //! Check Network if (!IsNetworkInit()) { ManageProgressStop(); ManageButtons * connect = new ManageButtons(tr("No network connection"), tr("Do you want to connect?"), tr("Yes"), tr("Cancel")); connect->SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); connect->SetPosition(-6, 75); connect->SetEffect(EFFECT_FADE, 20); mainWindow->Append(connect); ResumeGui(); while (connect->GetEffect()) usleep(50); while(!connect->GetChoice()) usleep(50); connect->SetEffect(EFFECT_FADE, -20); while (connect->GetEffect()) usleep(50); HaltGui(); mainWindow->Remove(connect); ResumeGui(); if(connect->GetChoice() == 1) { StartManageProgress(tr("Initializing Network")); Initialize_Network(); ManageProgressStop(); } delete connect; if (!IsNetworkInit()) return -2; StartManageProgress(tr("Downloading saveslist:"), "www.wiisave.com"); } //! Generate gameUrl std:: string WiiSaveListURL("http://wiisave.com/savegamecode_xml.php?gamecode="); WiiSaveListURL += ID.substr(0, 3); //! Check Connection if(!CheckConnection(WiiSaveListURL.c_str())) { ManageProgressStop(); return -3; } //! Check Region std::string Region; switch (ID[3]) { case 'E': Region = "E - USA / Canada"; break; case 'J': Region = "J - Japanese"; break; case 'W': Region = "J - Japanese";//Region = "NTSC T"; break; case 'K': Region = "J - Japanese";//Region = "NTSC K"; break; default: case 'P': case 'D': case 'F': case 'I': case 'S': case 'H': case 'U': case 'X': case 'Y': case 'Z': Region = "P - European / Other / PAL"; break; } //! Get list WiiSave_List * SaveList = new WiiSave_List(WiiSaveListURL.c_str()); ManageProgressStop(); if (!SaveList->GetCount()) { delete SaveList; return -4; } if (!SaveList->FilterList(Region)) { delete SaveList; return -5; } //! open browser & select save WiiSaveBrowser * SaveBrowser = new WiiSaveBrowser(SaveList); mainWindow->Append(SaveBrowser); SaveBrowser->Show(); int selected = SaveBrowser->GetSelectedSave(); delete SaveBrowser; if (selected < 0) { delete SaveList; return -10; } //! select download destination ManageButtons * path = new ManageButtons(tr("Select a target path."), tr("Be carrefull, present files can be overwritten"), tr("OK")); path->SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); path->SetPosition(-6, 75); path->SetEffect(EFFECT_FADE, 20); mainWindow->Append(path); ResumeGui(); while (path->GetEffect()) usleep(50); while(!path->GetChoice()) usleep(50); path->SetEffect(EFFECT_FADE, -20); while (path->GetEffect()) usleep(50); HaltGui(); mainWindow->Remove(path); delete path; ResumeGui(); if( selectBrowser(Settings.BrowserPath.c_str(), PATH) != 2 ) { delete SaveList; return -10; } //! download file std::string filepath = Settings.TmpPath; filepath += "/"; filepath += SaveList->GetFilteredFilename(selected); if( WiiSave::InternalDownload(SaveList->GetFilteredDownloadLink(selected), filepath) < 0) { delete SaveList; return -6; } delete SaveList; //! check file type char destID[5]; std::string srcfilepath; bool isSgmgxSave = false; bool isDataBin = false; std::string tmpDest = filepath.substr(0, filepath.rfind("/")+1); tmpDest += "tmpExtract"; std::string fileext = filepath.substr(filepath.rfind(".")); if( !Settings.FileExtensions.CompareArchive(fileext.c_str()) ) //! Archive { StartManageProgress(tr("Extracting files...")); //! extract files ArchiveHandle * Archive = new ArchiveHandle(filepath.c_str()); Archive->ExtractAll(tmpDest.c_str()); delete Archive; RemoveFile(filepath.c_str()); //! check save type DirList * dirList = new DirList(tmpDest.c_str(), ".bin" , DirList::Files | DirList::Dirs | DirList::CheckSubfolders); for(int i = 0; i < dirList->GetFilecount(); i++) { if(!strcmp(dirList->GetFilename(i), "banner.bin")) { isSgmgxSave = true; srcfilepath = dirList->GetFilepath(i); break; } std::string name(dirList->GetFilename(i)); fileext = name.substr(name.rfind(".")); if( !Settings.FileExtensions.CompareBinaryFiles(fileext.c_str()) ) { SaveInfos * infos = GetSaveInfos(dirList->GetFilepath(i)); if(infos) { isDataBin = true; srcfilepath = dirList->GetFilepath(i); memcpy(destID, infos->ID, 5); delete infos; break; } } } delete dirList; ManageProgressStop(); } else //! check for data.bin file { StartManageProgress(tr("Verifying file...")); SaveInfos * infos = GetSaveInfos(filepath); if(infos) { isDataBin = true; srcfilepath = filepath; memcpy(destID, infos->ID, 5); delete infos; } ManageProgressStop(); } if(!isDataBin && !isSgmgxSave) //! supported files not found { RemoveFile(filepath.c_str()); RemoveDirectory(tmpDest.c_str()); return -7; } //! write files StartManageProgress(tr("Writing files...")); if(isSgmgxSave) { std::string srcfolder = srcfilepath.substr(0, srcfilepath.rfind("/")); DirList * dirList = new DirList(srcfolder.c_str(), NULL , DirList::Files | DirList::Dirs); srcfolder = srcfolder.substr(srcfolder.rfind("/")); std::string finaldest = Settings.TmpPath; finaldest += srcfolder; CreateSubfolder(finaldest.c_str()); for(int i = 0; i < dirList->GetFilecount(); i++) { if(IsDir(i)) CopyDirectory(dirList->GetFilepath(i), finaldest.c_str()); else CopyFile(dirList->GetFilepath(i), fmt("%s/%s", finaldest.c_str(), dirList->GetFilename(i))); } delete dirList; } else if(isDataBin) { std::string finaldest = Settings.TmpPath; finaldest += "/"; finaldest += destID; CreateSubfolder(finaldest.c_str()); finaldest += "/data.bin"; CopyFile(srcfilepath.c_str(), finaldest.c_str()); } RemoveFile(filepath.c_str()); RemoveDirectory(tmpDest.c_str()); ManageProgressStop(); return 1; }
BOOL WINAPI CreateUserProfileW(PSID Sid, LPCWSTR lpUserName) { WCHAR szRawProfilesPath[MAX_PATH]; WCHAR szProfilesPath[MAX_PATH]; WCHAR szUserProfilePath[MAX_PATH]; WCHAR szDefaultUserPath[MAX_PATH]; WCHAR szUserProfileName[MAX_PATH]; WCHAR szBuffer[MAX_PATH]; LPWSTR SidString; DWORD dwLength; DWORD dwDisposition; UINT i; HKEY hKey; BOOL bRet = TRUE; LONG Error; DPRINT("CreateUserProfileW() called\n"); Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList", 0, KEY_QUERY_VALUE, &hKey); if (Error != ERROR_SUCCESS) { DPRINT1("Error: %lu\n", Error); SetLastError((DWORD)Error); return FALSE; } /* Get profiles path */ dwLength = MAX_PATH * sizeof(WCHAR); Error = RegQueryValueExW(hKey, L"ProfilesDirectory", NULL, NULL, (LPBYTE)szRawProfilesPath, &dwLength); if (Error != ERROR_SUCCESS) { DPRINT1("Error: %lu\n", Error); RegCloseKey(hKey); SetLastError((DWORD)Error); return FALSE; } /* Expand it */ if (!ExpandEnvironmentStringsW(szRawProfilesPath, szProfilesPath, MAX_PATH)) { DPRINT1("Error: %lu\n", GetLastError()); RegCloseKey(hKey); return FALSE; } /* create the profiles directory if it does not yet exist */ if (!CreateDirectoryW(szProfilesPath, NULL)) { if (GetLastError() != ERROR_ALREADY_EXISTS) { DPRINT1("Error: %lu\n", GetLastError()); return FALSE; } } /* Get default user path */ dwLength = MAX_PATH * sizeof(WCHAR); Error = RegQueryValueExW(hKey, L"DefaultUserProfile", NULL, NULL, (LPBYTE)szBuffer, &dwLength); if (Error != ERROR_SUCCESS) { DPRINT1("Error: %lu\n", Error); RegCloseKey(hKey); SetLastError((DWORD)Error); return FALSE; } RegCloseKey (hKey); wcscpy(szUserProfileName, lpUserName); wcscpy(szUserProfilePath, szProfilesPath); wcscat(szUserProfilePath, L"\\"); wcscat(szUserProfilePath, szUserProfileName); wcscpy(szDefaultUserPath, szProfilesPath); wcscat(szDefaultUserPath, L"\\"); wcscat(szDefaultUserPath, szBuffer); /* Create user profile directory */ if (!CreateDirectoryW(szUserProfilePath, NULL)) { if (GetLastError() != ERROR_ALREADY_EXISTS) { DPRINT1("Error: %lu\n", GetLastError()); return FALSE; } for (i = 0; i < 1000; i++) { swprintf(szUserProfileName, L"%s.%03u", lpUserName, i); wcscpy(szUserProfilePath, szProfilesPath); wcscat(szUserProfilePath, L"\\"); wcscat(szUserProfilePath, szUserProfileName); if (CreateDirectoryW(szUserProfilePath, NULL)) break; if (GetLastError() != ERROR_ALREADY_EXISTS) { DPRINT1("Error: %lu\n", GetLastError()); return FALSE; } } } /* Copy default user directory */ if (!CopyDirectory(szUserProfilePath, szDefaultUserPath)) { DPRINT1("Error: %lu\n", GetLastError()); return FALSE; } /* Add profile to profile list */ if (!ConvertSidToStringSidW(Sid, &SidString)) { DPRINT1("Error: %lu\n", GetLastError()); return FALSE; } wcscpy(szBuffer, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\"); wcscat(szBuffer, SidString); /* Create user profile key */ Error = RegCreateKeyExW(HKEY_LOCAL_MACHINE, szBuffer, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition); if (Error != ERROR_SUCCESS) { DPRINT1("Error: %lu\n", Error); bRet = FALSE; goto Done; } /* Create non-expanded user profile path */ wcscpy(szBuffer, szRawProfilesPath); wcscat(szBuffer, L"\\"); wcscat(szBuffer, szUserProfileName); /* Set 'ProfileImagePath' value (non-expanded) */ Error = RegSetValueExW(hKey, L"ProfileImagePath", 0, REG_EXPAND_SZ, (LPBYTE)szBuffer, (wcslen (szBuffer) + 1) * sizeof(WCHAR)); if (Error != ERROR_SUCCESS) { DPRINT1("Error: %lu\n", Error); RegCloseKey(hKey); bRet = FALSE; goto Done; } /* Set 'Sid' value */ Error = RegSetValueExW(hKey, L"Sid", 0, REG_BINARY, Sid, GetLengthSid(Sid)); if (Error != ERROR_SUCCESS) { DPRINT1("Error: %lu\n", Error); RegCloseKey(hKey); bRet = FALSE; goto Done; } RegCloseKey(hKey); /* Create user hive name */ wcscpy(szBuffer, szUserProfilePath); wcscat(szBuffer, L"\\ntuser.dat"); /* Acquire restore privilege */ if (!AcquireRemoveRestorePrivilege(TRUE)) { Error = GetLastError(); DPRINT1("Error: %lu\n", Error); bRet = FALSE; goto Done; } /* Create new user hive */ Error = RegLoadKeyW(HKEY_USERS, SidString, szBuffer); AcquireRemoveRestorePrivilege(FALSE); if (Error != ERROR_SUCCESS) { DPRINT1("Error: %lu\n", Error); bRet = FALSE; goto Done; } /* Initialize user hive */ if (!CreateUserHive(SidString, szUserProfilePath)) { Error = GetLastError(); DPRINT1("Error: %lu\n", Error); bRet = FALSE; } /* Unload the hive */ AcquireRemoveRestorePrivilege(TRUE); RegUnLoadKeyW(HKEY_USERS, SidString); AcquireRemoveRestorePrivilege(FALSE); Done: LocalFree((HLOCAL)SidString); SetLastError((DWORD)Error); DPRINT("CreateUserProfileW() done\n"); return bRet; }
// 27-Aug-2004 SFK Created void CopyLogsMenuOption() { static char szDfltRootPath[PATH_LEN+1] = ""; static char szDfltCurrentDbPath[PATH_LEN+1] = ""; static BOOL bFirst = TRUE; char szCurrentDbPath[PATH_LEN+1] = ""; char szMainCurrentDbPath[PATH_LEN+1] = ""; char szRootBackupPath[PATH_LEN+1] = ""; char szMainBackupPath[PATH_LEN+1] = ""; unsigned long ulDirSize, ulDiskSize, ulDiskAvailable; BOOL bRoom; int status; char *pStr; GUI_ACTION DlgReturn; CGFmtStr msg; SetCurrentDrive(); GetDbName(szCurrentDbPath); /* ------------------------------------------------------------------ * First time or when change databases, get the default values * from the .ini file else use the last successful values. * ------------------------------------------------------------------*/ if ((bFirst == TRUE) || (!SameDb(szDfltCurrentDbPath))) { pStr = pRAD_Init->Get_LogCopy_To_Path(); MyStrnCpy(szDfltRootPath, pStr, PATH_LEN); bFirst = FALSE; strcpy(szDfltCurrentDbPath, szCurrentDbPath); } strcpy(szRootBackupPath, szDfltRootPath); /* ------------------------------------------------------------------ * Define the buttons and actions in the dialog box * ----------------------------------------------------------------*/ CGUI_Dlg BackupDbDlg(IDD_FILE_COPY_LOGS, NULL, DLG_POSN_NO_SAVE); if (BackupDbDlg.IsValid()) { BackupDbDlg.DefinePushBtn(IDCANCEL, GUI_CANCEL); BackupDbDlg.DefinePushBtn(IDOK, GUI_OK); BackupDbDlg.DefinePushBtn(IDUPDATE, GUI_NONE, UpdateINI_Parms); BackupDbDlg.DefineFldTxt(IDC_CLOG_EDIT_NEW_PATH, szRootBackupPath, PATH_LEN); BackupDbDlg.SetFocus(IDOK); DlgReturn = BackupDbDlg.Go(); if (DlgReturn == GUI_OK) { BackupDbDlg.RetrieveAllControlValues(); /* ------------------------------------------------------------------ * Remove spaces, check length * ----------------------------------------------------------------*/ if (PathCopy(szMainBackupPath, szRootBackupPath) != TRUE) return; strcat(szMainBackupPath, "logs\\rad\\"); if (PathCopy(szMainCurrentDbPath, szCurrentDbPath) != TRUE) return; strcat(szMainCurrentDbPath, "logs\\rad\\"); /* ------------------------------------------------------------------ * See if the new path exists, if not make it. If can't make it give * reason why. * ----------------------------------------------------------------*/ status = PathExists(szMainBackupPath); // returns TRUE, uiPATH_TOO_LONG_ERR, uiDRIVE_DOES_NOT_EXIST_ERR oruiPATH_DOES_NOT_EXIST_ERR if ( status == uiPATH_DOES_NOT_EXIST_ERR) { status = AskAndMakePath(szMainBackupPath); if (status != TRUE) return; } if ( status != TRUE) { RadReviewMsg(status, (const char *)szMainBackupPath); return; } /* ------------------------------------------------------------------ * See if a log file exists at the location specified. If yes, * see if they want to overwrite it. * ----------------------------------------------------------------*/ if (FileExists(szMainBackupPath, "RadReviewLog.txt") == TRUE) { status = AskOverwriteQuestion(szMainBackupPath); if (status == FALSE) return; } /* ------------------------------------------------------------------ * Figure out how many bytes will need to be copied and if there * is room on the destination drive. (Destination drive must have * directory size + 10000 to allow for directory entries, etc.) * ----------------------------------------------------------------*/ if (GetDirSize(szMainCurrentDbPath, "*.*", &ulDirSize) != TRUE) return; /* check number of bytes filled in szCurrentDbPath */ // Customize for COMs, if don't write to this log directory if (GetDriveSize(szMainBackupPath, &ulDiskSize, &ulDiskAvailable) != TRUE) return; /* check number of bytes available on drive */ bRoom = TRUE; if ((ulDirSize + 10000) > ulDiskAvailable) bRoom = FALSE; if (bRoom == FALSE) { if (AskNotEnoughRoomQuestion(ulDirSize, ulDiskAvailable, szMainBackupPath) == FALSE) return; } /* ------------------------------------------------------------------ * Close the current database in case are trying to copy it. * Copy the data and show progress. Inform of the results of the copy. * ----------------------------------------------------------------*/ GetDbName(szCurrentDbPath); _flushall(); status = CopyDirectory(szMainCurrentDbPath, szMainBackupPath); // Customize for COMs, if don't write to this log directory if (status != TRUE) { RadReviewMsg(uiCOPY_DB_ERR, (const char *)szCurrentDbPath, (const char *)szRootBackupPath); } else { MyStrnCpy(szDfltRootPath,szRootBackupPath, PATH_LEN); // remember the default for next time msg.Printf("Logs copied to %s.", szRootBackupPath); GUI_MsgBox(msg, GUI_ICON_INFO); } } } }
void GenesisCopyWindow::CopyDirectory(const char *dirname, const char *destination, const char *destdirname) //////////////////////////////////////////////////////////////////////// { BEntry srcentry(dirname); BEntry dstentry; char name[B_FILE_NAME_LENGTH]; BString fulldestdir; if (srcentry.InitCheck()!=B_OK) return; if (!srcentry.Exists()) return; srcentry.GetName(name); fulldestdir.SetTo(destination); if (destdirname) fulldestdir << "/" << destdirname; else fulldestdir << "/" << name; dstentry.SetTo(fulldestdir.String()); if (dstentry.InitCheck()!=B_OK) return; if (!dstentry.Exists()) { if (create_directory(fulldestdir.String(), 0777)!=B_OK) // TODO: jo a 0777? return; } BDirectory dir; dir.SetTo(dirname); if (dir.InitCheck()==B_OK) { BEntry entry; if (dir.GetEntry(&entry)==B_OK) { while (dir.GetNextEntry(&entry)==B_OK) { entry.GetName(name); if (entry.IsDirectory()) { BString fullname; fullname.SetTo(dirname); fullname << "/" << name; CopyDirectory(fullname.String(), fulldestdir.String()); } else if (entry.IsSymLink()) { BString fullname; fullname.SetTo(dirname); fullname << "/" << name; CopyLink(fullname.String(), fulldestdir.String()); } else { BString fullname; fullname.SetTo(dirname); fullname << "/" << name; CopyFile(fullname.String(), fulldestdir.String()); } } } } // Copy attributes... CopyAttr(dirname, fulldestdir.String()); }