aboutsummaryrefslogtreecommitdiff
path: root/utils/midiplay
diff options
context:
space:
mode:
authorWohlstand <admin@wohlnet.ru>2024-08-02 08:49:16 +0300
committerWohlstand <admin@wohlnet.ru>2024-08-02 08:49:16 +0300
commit98c7e97d0bad655ed80a4652d4a01f3e7eea1493 (patch)
tree1b99158f3c6596b0fbc833a80a8495e970a2d0c0 /utils/midiplay
parent525e31073530115fe0500c7da006aaf7019c9aa1 (diff)
downloadlibADLMIDI-98c7e97d0bad655ed80a4652d4a01f3e7eea1493.tar.gz
libADLMIDI-98c7e97d0bad655ed80a4652d4a01f3e7eea1493.tar.bz2
libADLMIDI-98c7e97d0bad655ed80a4652d4a01f3e7eea1493.zip
MidiPlay: Added Utf8Main to support unicode paths
Diffstat (limited to 'utils/midiplay')
-rw-r--r--utils/midiplay/CMakeLists.txt3
-rw-r--r--utils/midiplay/adlmidiplay.cpp2
-rw-r--r--utils/midiplay/utf8main.cmake10
-rw-r--r--utils/midiplay/utf8main.h41
-rw-r--r--utils/midiplay/utf8main_win32.cpp95
5 files changed, 150 insertions, 1 deletions
diff --git a/utils/midiplay/CMakeLists.txt b/utils/midiplay/CMakeLists.txt
index 36c88b5..3d5eeda 100644
--- a/utils/midiplay/CMakeLists.txt
+++ b/utils/midiplay/CMakeLists.txt
@@ -7,9 +7,12 @@ if(NOT ADLMIDI_DOS AND NOT MIDIPLAY_WAVE_ONLY)
endif()
endif()
+include(utf8main.cmake)
+
set(ADLMIDI_PLAY_SRC
adlmidiplay.cpp
wave_writer.c
+ ${UTF8MAIN_SRCS}
)
if(USE_SDL2_AUDIO)
diff --git a/utils/midiplay/adlmidiplay.cpp b/utils/midiplay/adlmidiplay.cpp
index f5fb855..6a43ba4 100644
--- a/utils/midiplay/adlmidiplay.cpp
+++ b/utils/midiplay/adlmidiplay.cpp
@@ -34,7 +34,7 @@
#include <algorithm>
#include <signal.h>
#include <stdint.h>
-
+#include "utf8main.h"
#if defined(ADLMIDI_ENABLE_HW_SERIAL) && !defined(OUTPUT_WAVE_ONLY)
# ifdef ADLMIDI_USE_SDL2
diff --git a/utils/midiplay/utf8main.cmake b/utils/midiplay/utf8main.cmake
new file mode 100644
index 0000000..1dcac78
--- /dev/null
+++ b/utils/midiplay/utf8main.cmake
@@ -0,0 +1,10 @@
+# message("Path to UTF8-Main is [${CMAKE_CURRENT_LIST_DIR}]")
+include_directories(${CMAKE_CURRENT_LIST_DIR}/)
+
+set(UTF8MAIN_SRCS)
+
+if(WIN32)
+ list(APPEND UTF8MAIN_SRCS
+ ${CMAKE_CURRENT_LIST_DIR}/utf8main_win32.cpp
+ )
+endif()
diff --git a/utils/midiplay/utf8main.h b/utils/midiplay/utf8main.h
new file mode 100644
index 0000000..8cab2cc
--- /dev/null
+++ b/utils/midiplay/utf8main.h
@@ -0,0 +1,41 @@
+/*
+ * utf8main - a small wrapper over entry points
+ * to provide the UTF8 encoded main function
+ *
+ * Copyright (c) 2017-2023 Vitaly Novichkov <admin@wohlnet.ru>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this
+ * software and associated documentation files (the "Software"), to deal in the Software
+ * without restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies
+ * or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+ * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef UTF8MAIN_H
+#define UTF8MAIN_H
+
+#ifndef PGE_ENGINE//Don't use in PGE Engine where SDL Main is already in use
+//Windows platform
+#ifdef _WIN32
+//Avoid Qt to steal Main function
+#if defined(QT_NEEDS_QMAIN)
+#undef main
+#endif
+//Define custom UTF8 main function which will convert command line arguments into UTF8 and will pass them
+#define main UTF8_Main
+#endif
+
+#endif
+
+#endif // UTF8MAIN_H
diff --git a/utils/midiplay/utf8main_win32.cpp b/utils/midiplay/utf8main_win32.cpp
new file mode 100644
index 0000000..1159b97
--- /dev/null
+++ b/utils/midiplay/utf8main_win32.cpp
@@ -0,0 +1,95 @@
+/*
+ * utf8main - a small wrapper over entry points
+ * to provide the UTF8 encoded main function
+ *
+ * Copyright (c) 2017-2023 Vitaly Novichkov <admin@wohlnet.ru>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this
+ * software and associated documentation files (the "Software"), to deal in the Software
+ * without restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies
+ * or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+ * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef _WIN32
+#include <windows.h>
+#include <shellapi.h>
+#include <string>
+#include <vector>
+
+#ifdef PGE_ENGINE
+# include <SDL2/SDL_main.h>
+#else
+# include "utf8main.h"
+#endif
+
+#ifndef _In_
+# define _In_
+#endif
+#ifndef _In_opt_
+# define _In_opt_
+#endif
+
+extern int main(int argc, char *argv[]);
+
+static void buildUtf8Args(std::vector<std::string> &utf8_args)
+{
+ //Get raw UTF-16 command line
+ wchar_t *cmdLineW = GetCommandLineW();
+ int argc = 0;
+ //Convert it into array of strings
+ wchar_t **argvW = CommandLineToArgvW(cmdLineW, &argc);
+
+ utf8_args.reserve(argc);
+ //Convert every argument into UTF-8
+ for(int i = 0; i < argc; i++)
+ {
+ wchar_t *argW = argvW[i];
+ size_t argWlen = wcslen(argW);
+ std::string arg;
+ arg.resize(argWlen * 2);
+ size_t newLen = WideCharToMultiByte(CP_UTF8, 0, argW, static_cast<int>(argWlen), &arg[0], static_cast<int>(arg.size()), 0, 0);
+ arg.resize(newLen);
+ utf8_args.push_back(arg);
+ }
+}
+
+#ifdef WIN32_CONSOLE
+#undef main
+int main()
+# define main UTF8_Main
+#else
+int WINAPI WinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PSTR, _In_ int)
+#endif
+{
+ //! Storage of UTF8-encoded command line arguments
+ std::vector<std::string> g_utf8_args;
+ //! Storage of the pointers to begin of every argument
+ std::vector<char *> g_utf8_argvV;
+
+ buildUtf8Args(g_utf8_args);
+
+#ifdef UTF8Main_Debug
+ printf("UTF8 ARGS RAN!\n");
+ fflush(stdout);
+#endif
+
+ size_t argc = g_utf8_args.size();
+ g_utf8_argvV.reserve(argc);
+ for(size_t i = 0; i < argc; i++)
+ g_utf8_argvV.push_back(&g_utf8_args[i][0]);
+
+ return main((int)argc, g_utf8_argvV.data());
+}
+#endif