let's try this

This commit is contained in:
2025-12-13 23:06:14 -05:00
parent efa9533a52
commit 225a584a21
5 changed files with 34 additions and 14 deletions

View File

@@ -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;

View File

@@ -10,6 +10,7 @@
#endif
#include <cstdlib>
#include <cstring>
#include <format>
#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();
}
}
}

View File

@@ -14,6 +14,7 @@
#include <imgui/imgui.h>
#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();
}

View File

@@ -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);

View File

@@ -3,8 +3,13 @@
#include <SDL3/SDL_filesystem.h>
#include <SDL3/SDL_properties.h>
#include <SDL3/SDL_stdinc.h>
#include <cstdio>
#include <utility>
#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<unsigned char*>(fileData), static_cast<unsigned char*>(fileData) + fileSize);
SDL_free(fileData);
data.resize(static_cast<std::size_t>(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)