std::shared_ptr<VSRG::Song> LoadSong7KFromFilename(std::filesystem::path Filename, std::filesystem::path Prefix, VSRG::Song *Sng) { auto prefix = Prefix.string(); bool AllocSong = false; if (!Sng) { AllocSong = true; Sng = new VSRG::Song(); } std::wstring Ext = Utility::Widen(Filename.extension().string()); // no extension if (!Filename.has_extension() || !VSRGValidExtension(Ext)) { if (AllocSong) delete Sng; return nullptr; } Sng->SongDirectory = Prefix.string(); auto fn = Prefix / Filename; auto fnu8 = Utility::Narrow(fn.wstring()); for (int i = 0; i < sizeof(LoadersVSRG) / sizeof(loaderVSRGEntry_t); i++) { if (Ext == LoadersVSRG[i].Ext) { Log::LogPrintf("Load %s from disk...", fnu8.c_str()); try { LoadersVSRG[i].LoadFunc(fn, Sng); Log::LogPrintf(" ok\n"); } catch (std::exception &e) { Log::LogPrintf("Failure loading: %s\n", e.what()); } break; } } if (AllocSong) return std::shared_ptr<VSRG::Song>(Sng); return nullptr; }
std::shared_ptr<VSRG::Song> LoadSong7KFromFilename(const std::filesystem::path& filename, VSRG::Song *Sng) { if (!filename.has_extension()) { return nullptr; } bool AllocSong = false; if (!Sng) { AllocSong = true; Sng = new VSRG::Song(); } Sng->SongDirectory = filename.parent_path(); for (int i = 0; i < sizeof(LoadersVSRG) / sizeof(loaderVSRGEntry_t); i++) { if (filename.extension() == LoadersVSRG[i].Ext) { Log::LogPrintf("Load %s from disk...", filename.string().c_str()); try { LoadersVSRG[i].LoadFunc(filename, Sng); Log::LogPrintf(" ok\n"); } catch (std::exception &e) { Log::LogPrintf("Failure loading %s: %s\n", filename.string().c_str(), e.what()); } break; } } if (AllocSong) return std::shared_ptr<VSRG::Song>(Sng); return nullptr; }