mirror of
https://github.com/alexkay/spek.git
synced 2025-04-17 00:52:20 +03:00
[win] Fix Unicode arguments
This commit is contained in:
parent
c9e4146536
commit
95788c11e3
1
.gitignore
vendored
1
.gitignore
vendored
@ -30,6 +30,7 @@ samples/
|
||||
src/*.c
|
||||
!src/spek-audio.c
|
||||
!src/spek-fft.c
|
||||
!src/spek-platform.c
|
||||
src/*.o
|
||||
src/*.stamp
|
||||
src/spek
|
||||
|
66
src/spek-platform.c
Normal file
66
src/spek-platform.c
Normal file
@ -0,0 +1,66 @@
|
||||
/* spek-platform.c
|
||||
*
|
||||
* Copyright (C) 2010 Alexander Kojevnikov <alexander@kojevnikov.com>
|
||||
*
|
||||
* Spek is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Spek is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Spek. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
#endif
|
||||
|
||||
#include "spek-platform.h"
|
||||
|
||||
void spek_platform_fix_args (gchar **argv, gint argc) {
|
||||
#ifdef G_OS_WIN32
|
||||
/* Because MinGW does not support Unicode arguments we are going to
|
||||
* get them using Windows API. In addition, GLib's option parser
|
||||
* doesn't work well with utf-8 strings on Windows, converting
|
||||
* them to URIs works around this problem.
|
||||
*/
|
||||
int i;
|
||||
gchar *s, *t;
|
||||
wchar_t **wargv;
|
||||
int wargc;
|
||||
wargv = CommandLineToArgvW (GetCommandLineW (), &wargc);
|
||||
for (i = 0; i < argc; i++) {
|
||||
s = g_utf16_to_utf8 (wargv[i], -1, NULL, NULL, NULL);
|
||||
if (s) {
|
||||
t = g_filename_to_uri (s, NULL, NULL);
|
||||
g_free (s);
|
||||
if (t) {
|
||||
g_free (argv[i]);
|
||||
argv[i] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
LocalFree (wargv);
|
||||
#endif
|
||||
}
|
||||
|
||||
void spek_platform_show_uri (const gchar *uri) {
|
||||
#ifdef G_OS_WIN32
|
||||
/* gtk_show_uri doesn't work on Windows */
|
||||
ShellExecuteA (NULL, "open", uri, "", NULL, SW_SHOWNORMAL);
|
||||
#else
|
||||
GError *error = NULL;
|
||||
if (!gtk_show_uri (NULL, uri, gtk_get_current_event_time (), &error)) {
|
||||
g_error_free (error);
|
||||
}
|
||||
#endif
|
||||
}
|
@ -21,6 +21,9 @@
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
/* Convert from UTF-16 to UTF-8 when running on Windows */
|
||||
void spek_platform_fix_args (gchar **argv, gint argc);
|
||||
|
||||
/* Open a link in the browser */
|
||||
void spek_platform_show_uri (const gchar *uri);
|
||||
|
||||
|
@ -28,6 +28,8 @@ namespace Spek {
|
||||
};
|
||||
|
||||
int main (string[] args) {
|
||||
Platform.fix_args (args);
|
||||
|
||||
Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
|
||||
Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
|
||||
Intl.textdomain (Config.GETTEXT_PACKAGE);
|
||||
@ -52,7 +54,14 @@ namespace Spek {
|
||||
}
|
||||
|
||||
Audio.init ();
|
||||
var window = new Window (files == null ? null : files[0]);
|
||||
var file_name = files == null ? null : files[0];
|
||||
if (file_name != null && file_name.has_prefix ("file://")) {
|
||||
try {
|
||||
file_name = Filename.from_uri (file_name);
|
||||
} catch (ConvertError e) {
|
||||
}
|
||||
}
|
||||
var window = new Window (file_name);
|
||||
Gtk.main ();
|
||||
window.destroy ();
|
||||
return 0;
|
||||
|
@ -1,4 +1,5 @@
|
||||
[CCode (cprefix = "SpekPlatform", lower_case_cprefix = "spek_platform_", cheader_filename = "spek-platform.h")]
|
||||
namespace Spek.Platform {
|
||||
public static void fix_args (string[] args);
|
||||
public static void show_uri (string uri);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user