aboutsummaryrefslogtreecommitdiff
path: root/Src/nu/AutoCharFn.h
diff options
context:
space:
mode:
authorJean-Francois Mauguit <jfmauguit@mac.com>2024-09-24 09:03:25 -0400
committerGitHub <noreply@github.com>2024-09-24 09:03:25 -0400
commitbab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/nu/AutoCharFn.h
parent4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff)
parent20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff)
downloadwinamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/nu/AutoCharFn.h')
-rw-r--r--Src/nu/AutoCharFn.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/Src/nu/AutoCharFn.h b/Src/nu/AutoCharFn.h
new file mode 100644
index 00000000..3b5b7750
--- /dev/null
+++ b/Src/nu/AutoCharFn.h
@@ -0,0 +1,50 @@
+#ifndef NULLSOFT_UTILITY_AUTOCHARFN_H
+#define NULLSOFT_UTILITY_AUTOCHARFN_H
+
+/* Winamp defines this, but this little block lets us use this thing outside of Winamp */
+#ifndef FILENAME_SIZE
+#define FILENAME_SIZE (MAX_PATH*4)
+#define REMOVE_FILENAME_SIZE
+#endif
+
+
+#include <windows.h>
+#include <shlwapi.h>
+
+class AutoCharFn
+{
+public:
+ AutoCharFn(const wchar_t *filename)
+ {
+ out[0]=0;
+ if (!filename)
+ return;
+ if (PathIsURLW(filename))
+ {
+ WideCharToMultiByte(CP_ACP, 0, filename, -1, out, FILENAME_SIZE, NULL, NULL);
+ return ;
+ }
+
+ BOOL unconvertable = FALSE;
+ WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, filename, -1, out, FILENAME_SIZE, NULL, &unconvertable);
+
+ if (unconvertable)
+ {
+ wchar_t temp[MAX_PATH];
+ if (GetShortPathNameW(filename, temp, MAX_PATH))
+ WideCharToMultiByte(CP_ACP, 0, temp, -1, out, FILENAME_SIZE, NULL, NULL);
+
+ }
+ }
+
+ operator char *() { return out; }
+private:
+ char out[FILENAME_SIZE];
+};
+
+
+#ifdef REMOVE_FILENAME_SIZE
+#undef FILENAME_SIZE
+#endif
+
+#endif