Merge cb9588ab68 into 05fa625eac
This commit is contained in:
commit
144f0b1352
|
|
@ -25,6 +25,13 @@
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#ifndef NOMINMAX
|
||||||
|
#define NOMINMAX
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
struct clip_logger_state g_logger_state = {clip_log_callback_default, NULL};
|
struct clip_logger_state g_logger_state = {clip_log_callback_default, NULL};
|
||||||
|
|
||||||
//#define CLIP_DEBUG_FUNCTIONS
|
//#define CLIP_DEBUG_FUNCTIONS
|
||||||
|
|
@ -1877,7 +1884,21 @@ struct clip_model_loader {
|
||||||
{
|
{
|
||||||
std::vector<uint8_t> read_buf;
|
std::vector<uint8_t> read_buf;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
// Convert UTF-8 to UTF-16 for Windows
|
||||||
|
int wlen = MultiByteToWideChar(CP_UTF8, 0, fname.c_str(), -1, NULL, 0);
|
||||||
|
if (!wlen) {
|
||||||
|
throw std::runtime_error(string_format("%s: failed to convert filename to UTF-16: %s\n", __func__, fname.c_str()));
|
||||||
|
}
|
||||||
|
std::vector<wchar_t> wfname(wlen);
|
||||||
|
wlen = MultiByteToWideChar(CP_UTF8, 0, fname.c_str(), -1, wfname.data(), wlen);
|
||||||
|
if (!wlen) {
|
||||||
|
throw std::runtime_error(string_format("%s: failed to convert filename to UTF-16: %s\n", __func__, fname.c_str()));
|
||||||
|
}
|
||||||
|
auto fin = std::ifstream(wfname.data(), std::ios::binary);
|
||||||
|
#else
|
||||||
auto fin = std::ifstream(fname, std::ios::binary);
|
auto fin = std::ifstream(fname, std::ios::binary);
|
||||||
|
#endif
|
||||||
if (!fin) {
|
if (!fin) {
|
||||||
throw std::runtime_error(string_format("%s: failed to open %s\n", __func__, fname.c_str()));
|
throw std::runtime_error(string_format("%s: failed to open %s\n", __func__, fname.c_str()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -298,6 +298,9 @@ int main(int argc, char ** argv) {
|
||||||
|
|
||||||
int n_predict = params.n_predict < 0 ? INT_MAX : params.n_predict;
|
int n_predict = params.n_predict < 0 ? INT_MAX : params.n_predict;
|
||||||
|
|
||||||
|
console::init(params.simple_io, params.use_color);
|
||||||
|
atexit([]() { console::cleanup(); });
|
||||||
|
|
||||||
// Ctrl+C handling
|
// Ctrl+C handling
|
||||||
{
|
{
|
||||||
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
|
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
|
||||||
|
|
|
||||||
|
|
@ -498,13 +498,38 @@ mtmd_bitmap * mtmd_helper_bitmap_init_from_buf(mtmd_context * ctx, const unsigne
|
||||||
}
|
}
|
||||||
|
|
||||||
mtmd_bitmap * mtmd_helper_bitmap_init_from_file(mtmd_context * ctx, const char * fname) {
|
mtmd_bitmap * mtmd_helper_bitmap_init_from_file(mtmd_context * ctx, const char * fname) {
|
||||||
std::vector<unsigned char> buf;
|
#ifdef _WIN32
|
||||||
|
// Convert UTF-8 to UTF-16 for Windows
|
||||||
|
int wlen = MultiByteToWideChar(CP_UTF8, 0, fname, -1, NULL, 0);
|
||||||
|
if (!wlen) {
|
||||||
|
LOG_ERR("Unable to convert filename to UTF-16: %s\n", fname);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<wchar_t> wfname(wlen);
|
||||||
|
wlen = MultiByteToWideChar(CP_UTF8, 0, fname, -1, wfname.data(), wlen);
|
||||||
|
if (!wlen) {
|
||||||
|
LOG_ERR("Unable to convert filename to UTF-16: %s\n", fname);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open file with UTF-16 filename
|
||||||
|
FILE * f = _wfopen(wfname.data(), L"rb");
|
||||||
|
if (!f) {
|
||||||
|
LOG_ERR("Unable to open file %s: %s\n", fname, strerror(errno));
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// On non-Windows platforms, use fopen directly
|
||||||
FILE * f = fopen(fname, "rb");
|
FILE * f = fopen(fname, "rb");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
LOG_ERR("Unable to open file %s: %s\n", fname, strerror(errno));
|
LOG_ERR("Unable to open file %s: %s\n", fname, strerror(errno));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Read file content
|
||||||
|
std::vector<unsigned char> buf;
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
long file_size = ftell(f);
|
long file_size = ftell(f);
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
|
|
@ -512,8 +537,9 @@ mtmd_bitmap * mtmd_helper_bitmap_init_from_file(mtmd_context * ctx, const char *
|
||||||
|
|
||||||
size_t n_read = fread(buf.data(), 1, file_size, f);
|
size_t n_read = fread(buf.data(), 1, file_size, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
if (n_read != (size_t)file_size) {
|
if (n_read != (size_t)file_size) {
|
||||||
LOG_ERR("Failed to read entire file %s", fname);
|
LOG_ERR("Failed to read entire file %s\n", fname);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue