diff --git a/src/anm2/anm2_sounds.cpp b/src/anm2/anm2_sounds.cpp index ac25f02..eba4a3e 100644 --- a/src/anm2/anm2_sounds.cpp +++ b/src/anm2/anm2_sounds.cpp @@ -22,7 +22,7 @@ namespace anm2ed::anm2 labels.emplace_back(localize.get(BASIC_NONE)); for (auto& [id, sound] : content.sounds) { - auto pathString = sound.path.string(); + auto pathString = filesystem::path_to_utf8(sound.path); labels.emplace_back(std::vformat(localize.get(FORMAT_SOUND), std::make_format_args(id, pathString))); } return labels; diff --git a/src/dialog.cpp b/src/dialog.cpp index dc3b122..8c3d5d0 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -10,6 +10,7 @@ #endif #include +#include #include #include "filesystem_.h" @@ -22,11 +23,14 @@ namespace anm2ed::dialog if (filelist && filelist[0] && strlen(filelist[0]) > 0) { - self->path = filelist[0]; + self->path = anm2ed::util::filesystem::path_from_utf8(filelist[0]); self->selectedFilter = filter; } else + { self->selectedFilter = -1; + self->path.clear(); + } } } diff --git a/src/imgui/taskbar.cpp b/src/imgui/taskbar.cpp index 048a7b8..72ed05b 100644 --- a/src/imgui/taskbar.cpp +++ b/src/imgui/taskbar.cpp @@ -14,6 +14,7 @@ #include +#include "filesystem_.h" #include "log.h" #include "math_.h" #include "render.h" @@ -31,6 +32,7 @@ using namespace anm2ed::types; using namespace anm2ed::canvas; using namespace anm2ed::util; using namespace glm; +namespace filesystem = anm2ed::util::filesystem; namespace anm2ed::imgui { @@ -874,7 +876,7 @@ namespace anm2ed::imgui if (dialog.is_selected(dialog::FFMPEG_PATH_SET)) { - ffmpegPath = dialog.path.string(); + ffmpegPath = filesystem::path_to_utf8(dialog.path); dialog.reset(); } @@ -892,7 +894,7 @@ namespace anm2ed::imgui if (dialog.is_selected(dialogType)) { - path = dialog.path.string(); + path = filesystem::path_to_utf8(dialog.path); dialog.reset(); } diff --git a/src/imgui/window/sounds.cpp b/src/imgui/window/sounds.cpp index f6c1774..0e13fd3 100644 --- a/src/imgui/window/sounds.cpp +++ b/src/imgui/window/sounds.cpp @@ -34,7 +34,7 @@ namespace anm2ed::imgui auto behavior = [&]() { int id{}; - auto pathString = path.string(); + auto pathString = filesystem::path_to_utf8(path); if (anm2.sound_add(document.directory_get(), path, id)) { selection = {id}; @@ -76,7 +76,7 @@ namespace anm2ed::imgui { anm2::Sound& sound = anm2.content.sounds[id]; sound.reload(document.directory_get()); - auto pathString = sound.path.string(); + auto pathString = filesystem::path_to_utf8(sound.path); toasts.push(std::vformat(localize.get(TOAST_RELOAD_SOUND), std::make_format_args(id, pathString))); logger.info( std::vformat(localize.get(TOAST_RELOAD_SOUND, anm2ed::ENGLISH), std::make_format_args(id, pathString))); @@ -95,7 +95,7 @@ namespace anm2ed::imgui auto& id = *selection.begin(); anm2::Sound& sound = anm2.content.sounds[id]; sound = anm2::Sound(document.directory_get(), path); - auto pathString = sound.path.string(); + auto pathString = filesystem::path_to_utf8(sound.path); toasts.push(std::vformat(localize.get(TOAST_REPLACE_SOUND), std::make_format_args(id, pathString))); logger.info( std::vformat(localize.get(TOAST_REPLACE_SOUND, anm2ed::ENGLISH), std::make_format_args(id, pathString))); @@ -215,7 +215,7 @@ namespace anm2ed::imgui bool isValid = sound.is_valid(); auto& soundIcon = isValid ? resources.icons[icon::SOUND] : resources.icons[icon::NONE]; auto tintColor = !isValid ? ImVec4(1.0f, 0.25f, 0.25f, 1.0f) : ImVec4(1.0f, 1.0f, 1.0f, 1.0f); - auto pathString = sound.path.string(); + auto pathString = filesystem::path_to_utf8(sound.path); ImGui::SetNextItemSelectionUserData(id); ImGui::SetNextItemStorageID(id); diff --git a/src/resource/audio.cpp b/src/resource/audio.cpp index f97814a..6d945c3 100644 --- a/src/resource/audio.cpp +++ b/src/resource/audio.cpp @@ -3,8 +3,13 @@ #include #include #include +#include #include +#include "filesystem_.h" + +namespace filesystem = anm2ed::util::filesystem; + namespace anm2ed::resource { MIX_Mixer* Audio::mixer_get() @@ -17,16 +22,25 @@ namespace anm2ed::resource { if (path.empty()) return; - size_t fileSize = 0; - void* fileData = SDL_LoadFile(path.string().c_str(), &fileSize); - if (!fileData || fileSize == 0) + filesystem::File file(path, "rb"); + if (!file) return; + + if (std::fseek(file.get(), 0, SEEK_END) != 0) return; + auto size = std::ftell(file.get()); + if (size <= 0) { - if (fileData) SDL_free(fileData); return; } + std::rewind(file.get()); - data.assign(static_cast(fileData), static_cast(fileData) + fileSize); - SDL_free(fileData); + data.resize(static_cast(size)); + auto read = std::fread(data.data(), 1, data.size(), file.get()); + if (read == 0) + { + data.clear(); + return; + } + data.resize(read); SDL_IOStream* io = SDL_IOFromConstMem(data.data(), data.size()); if (!io)