void FileFunctionsTestCase::RemoveFile() { // Create & remove file with name containing ASCII characters only. DoRemoveFile(m_fileNameASCII); // Create & remove file with name containing non-ASCII characters. DoRemoveFile(m_fileNameNonASCII); }
void CMissionManager::UninstallMod() { // To uninstall the current FM, just clear the FM name in currentfm.txt WriteCurrentFmFile(""); #if 0 // Path to the darkmod directory fs::path darkmodPath = GetDarkmodPath(); // Path to file that holds the current FM name fs::path currentFMPath(darkmodPath / cv_tdm_fm_current_file.GetString()); DM_LOG(LC_MAINMENU, LT_DEBUG)LOGSTRING("Trying to clear current FM name in %s\r", currentFMPath.file_string().c_str()); if (DoRemoveFile(currentFMPath)) { DM_LOG(LC_MAINMENU, LT_INFO)LOGSTRING("Current FM file removed: %s.\r", currentFMPath.string().c_str()); } else { // Log removal error DM_LOG(LC_MAINMENU, LT_DEBUG)LOGSTRING("Caught exception while removing current FM file %s.\r", currentFMPath.string().c_str()); } #endif }
CMissionManager::RequestStatus CMissionManager::ProcessMissionScreenshotRequest() { if (!IsMissionScreenshotRequestInProgress()) { return NOT_IN_PROGRESS; } RequestStatus status = GetRequestStatusForDownloadId(_modScreenshotDownloadId); // Clean up the result if the request is complete if (status == FAILED || status == SUCCESSFUL) { fs::path tempFilename = g_Global.GetDarkmodPath(); tempFilename /= cv_tdm_fm_path.GetString(); tempFilename /= TMP_MISSION_SCREENSHOT_FILENAME; if (status == SUCCESSFUL) { CDownloadPtr download = gameLocal.m_DownloadManager->GetDownload(_modScreenshotDownloadId); assert(download != NULL); // Mission was stored as userdata in the download object int missionIndex = download->GetUserData().id; int screenshotNum = download->GetUserData().id2; assert(missionIndex >= 0 && missionIndex < _downloadableMods.Num()); DownloadableMod& mission = *_downloadableMods[missionIndex]; assert(screenshotNum >= 0 && screenshotNum < mission.screenshots.Num()); // Open, convert and save the image if (!ProcessMissionScreenshot(tempFilename, mission, screenshotNum)) { gameLocal.Warning("Failed to process downloaded screenshot, mission %s, screenshot #%d", mission.modName.c_str(), screenshotNum); DM_LOG(LC_MAINMENU, LT_ERROR)LOGSTRING("Failed to process downloaded screenshot, mission %s, screenshot #%d\r", mission.modName.c_str(), screenshotNum); status = FAILED; } } // Remove the temporary file DoRemoveFile(tempFilename); // Clear the download gameLocal.m_DownloadManager->RemoveDownload(_modScreenshotDownloadId); _modScreenshotDownloadId = -1; } return status; }
void CMissionManager::SearchForNewMods() { // List all PK4s in the fms/ directory MoveList moveList = SearchForNewMods(".pk4"); MoveList zipMoveList = SearchForNewMods(".zip"); // Merge the zips into the pk4 list if (!zipMoveList.empty()) { moveList.merge(zipMoveList); } DM_LOG(LC_MAINMENU, LT_INFO)LOGSTRING("Found %d new mission packages.\r", static_cast<int>(moveList.size())); gameLocal.Printf("Found %d new mission packages.\n", static_cast<int>(moveList.size())); // greebo: The D3 engine should no longer hold locks on those files // and we can start moving them into their respective locations for (MoveList::const_iterator i = moveList.begin(); i != moveList.end(); ++i) { fs::path targetPath = i->second; // Remove any target file first, to overwrite when moving DoRemoveFile(targetPath); // Move the file DoMoveFile(i->first, targetPath); // Remove the file portion targetPath.remove_leaf(); // Remove any darkmod.txt, splashimage etc. when copying a new PK4. It may contain updated versions of those. DoRemoveFile(targetPath / cv_tdm_fm_desc_file.GetString()); DoRemoveFile(targetPath / cv_tdm_fm_splashimage_file.GetString()); DoRemoveFile(targetPath / cv_tdm_fm_notes_file.GetString()); } }
CMissionManager::RequestStatus CMissionManager::ProcessReloadModDetailsRequest() { if (!IsModDetailsRequestInProgress()) { return NOT_IN_PROGRESS; } RequestStatus status = GetRequestStatusForDownloadId(_modDetailsDownloadId); // Clean up the result if the request is complete if (status == FAILED || status == SUCCESSFUL) { fs::path tempFilename = g_Global.GetDarkmodPath(); tempFilename /= TMP_MISSION_DETAILS_FILENAME; if (status == SUCCESSFUL) { XmlDocumentPtr doc(new pugi::xml_document); pugi::xml_parse_result result = doc->load_file(tempFilename.string().c_str()); if (result) { CDownloadPtr download = gameLocal.m_DownloadManager->GetDownload(_modDetailsDownloadId); assert(download != NULL); // Mod number was stored as userdata in the download object int modNum = download->GetUserData().id; LoadModDetailsFromXml(doc, modNum); } else { // Failed to parse XML status = FAILED; } } // Remove the temporary file DoRemoveFile(tempFilename); // Clear the download gameLocal.m_DownloadManager->RemoveDownload(_modDetailsDownloadId); _modDetailsDownloadId = -1; } return status; }
CMissionManager::RequestStatus CMissionManager::ProcessReloadDownloadableModsRequest() { if (!IsDownloadableModsRequestInProgress()) { return NOT_IN_PROGRESS; } RequestStatus status = GetRequestStatusForDownloadId(_refreshModListDownloadId); // Clean up the result if the request is complete if (status == FAILED || status == SUCCESSFUL) { fs::path tempFilename = g_Global.GetDarkmodPath(); tempFilename /= TMP_MISSION_LIST_FILENAME; if (status == SUCCESSFUL) { XmlDocumentPtr doc(new pugi::xml_document); pugi::xml_parse_result result = doc->load_file(tempFilename.string().c_str()); if (result) { LoadModListFromXml(doc); } else { status = FAILED; } } // Remove the temporary file DoRemoveFile(tempFilename); // Clear the download gameLocal.m_DownloadManager->RemoveDownload(_refreshModListDownloadId); _refreshModListDownloadId = -1; } return status; }