/*! * Uses the selected cover for the song. */ void QUCoverGroup::copyCoverToSongPath(bool deleteCurrentCover) { if(currentFilePath().isEmpty()) { logSrv->add(QString(tr("Could not copy cover to song path. No cover selected for: \"%1 - %2\"")).arg(song()->artist()).arg(song()->title()), QU::Warning); return; } QFileInfo target(song()->songFileInfo().dir(), "cover_" + QFileInfo(currentFilePath()).fileName()); if(!QFile::copy(currentFilePath(), target.filePath())) { logSrv->add(QString(tr("Could not copy the new cover \"%1\" to \"%2\".")).arg(currentFilePath()).arg(target.filePath()), QU::Warning); return; } QString oldName = song()->coverFileInfo().filePath(); if(deleteCurrentCover) { if(!QFile::remove(oldName)) { logSrv->add(QString(tr("Could not delete current cover: \"%1\"")).arg(song()->coverFileInfo().filePath()), QU::Warning); song()->autoSetFile(target, true); } else { logSrv->add(QString(tr("Current cover was replaced successfully for: \"%1 - %2\"")).arg(song()->artist()).arg(song()->title()), QU::Information); QFile::rename(target.filePath(), oldName); } } else { // copy operation well done - now set the new cover song()->autoSetFile(target, true); } song()->save(); _item->update(); }
QString QResourceFileEngineIterator::next() { if (!hasNext()) return QString(); ++index; return currentFilePath(); }
QString next() { if (!hasNext()) return QString(); ++index; return currentFilePath(); }
QString QFSFileEngineIterator::next() { if (!hasNext()) return QString(); advance(); return currentFilePath(); }
/*! The virtual function returns a QFileInfo for the current directory entry. This function is provided for convenience. It can also be slightly faster than creating a QFileInfo object yourself, as the object returned by this function might contain cached information that QFileInfo otherwise would have to access through the file engine. \sa currentFileName() */ QFileInfo QAbstractFileEngineIterator::currentFileInfo() const { QString path = currentFilePath(); if (d->fileInfo.filePath() != path) d->fileInfo.setFile(path); // return a shallow copy return d->fileInfo; }
QFileInfo currentFileInfo() const override { return QFileInfo(currentFilePath()); }
virtual QFileInfo currentFileInfo() const { return QFileInfo(currentFilePath()); }
int main() { //First set the default root content folder in gleed2D pugi::xml_document gleedSettings; //Load the xml file into memory std::cout << "Loading Gleed Settings XML File " << std::endl; pugi::xml_parse_result result = gleedSettings.load_file(gleedSettingsPath.c_str()); if (result) { std::cout << "Gleed settings was loaded without errors." << std::endl; } else { std::cout << "Gleed settings had some trouble loading and failed" << std::endl; std::cout << "Error description: " << result.description() << "\n"; std::cin.get(); return false; } std::cout << std::endl; //Get the path that the executeable is in, make it a string HMODULE hModule = GetModuleHandleW(NULL); WCHAR path[MAX_PATH]; GetModuleFileNameW(hModule, path, MAX_PATH); //convert from wide char to narrow char array char ch[MAX_PATH]; char DefChar = ' '; WideCharToMultiByte(CP_ACP,0,path,-1, ch,260,&DefChar, NULL); //make a nice string with just the path std::string currentFilePath(ch); //This is the file and name of the executeable, needs to be removed to set the correct content root folder std::string stuffToRemove = "/LevelEditor/MakeGleedWork.exe"; currentFilePath.erase(currentFilePath.end() - stuffToRemove.size(), currentFilePath.end()); std::cout << "Setting content root folder of Gleed2d setting as : " << currentFilePath << std::endl; gleedSettings.child("Constants").child("DefaultContentRootFolder").first_child().set_value(currentFilePath.c_str()); gleedSettings.save_file(gleedSettingsPath.c_str()); std::cout << std::endl; //save the root folder path for later std::string rootFolderPath = currentFilePath; //go to the levels folder std::string fromRootToLevels = "\\Assets\\Levels"; currentFilePath.append(fromRootToLevels); std::cout << "Moving to :" << currentFilePath << std::endl; //copy the template level from here to there std::string templateLevelName = "TemplateLevel.xml"; pugi::xml_document templateLevel; templateLevel.load_file(templateLevelName.c_str()); std::string savePath = currentFilePath; savePath.append("\\" + templateLevelName); templateLevel.save_file(savePath.c_str()); std::cout << "Putting TemplateLevel.xml in :" << savePath << std::endl; std::cout << "Files found in levels folder : " << std::endl; //stores the file names from a scan through this directory std::vector<std::string> levelFileNames; //MOST OF THIS CODE SNIPPET IS NOT MINE, TAKEN FROM http://stackoverflow.com/questions/612097/how-can-i-get-a-list-of-files-in-a-directory-using-c-or-c uses dirent.h DIR *dir; struct dirent *ent; if ((dir = opendir (currentFilePath.c_str())) != NULL) { /* print all the files and directories within directory */ while ((ent = readdir (dir)) != NULL) { std::cout << ent->d_name << std::endl; levelFileNames.push_back(std::string(ent->d_name)); } closedir (dir); } else { /* could not open directory */ std::cout << "Could not open levels directory" << std::endl; perror (""); return EXIT_FAILURE; } for(int i = 0; i < levelFileNames.size(); i++) { if((levelFileNames[i] == ".") || (levelFileNames[i] == "..")) { //ignore the weird directory dots continue; } else { std::cout << std::endl; std::cout << "Changing the content root folder in : " << levelFileNames[i] << std::endl; //Load the xml file into memory pugi::xml_document levelFile; std::cout << "Loading Gleed Settings XML File " << std::endl; pugi::xml_parse_result result = levelFile.load_file((currentFilePath + "\\" + levelFileNames[i]).c_str()); if (result) { std::cout << "Gleed settings was loaded without errors." << std::endl; } else { std::cout << "Gleed settings had some trouble loading and failed" << std::endl; std::cout << "Error description: " << result.description() << "\n"; std::cin.get(); return false; } pugi::xml_node rootFolder = levelFile.child("Level").child("EditorRelated").child("ContentRootFolder").first_child(); rootFolder.set_value(rootFolderPath.c_str()); levelFile.save_file((currentFilePath + "\\" + levelFileNames[i]).c_str()); } } //// //C:\Coding\C++\AMG Teaching\AMG_Teaching_Repo std::cin.get(); return 0; }