mirror of
https://github.com/alexkay/spek.git
synced 2025-04-19 01:47:37 +03:00
Add Platform.read_line
This commit is contained in:
parent
1426e66ea4
commit
f1f63561f9
@ -64,3 +64,23 @@ void spek_platform_show_uri (const gchar *uri) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
gchar *spek_platform_read_line (const gchar *uri) {
|
||||
gchar *line = NULL;
|
||||
GFile *file = NULL;
|
||||
GFileInputStream *file_stream = NULL;
|
||||
|
||||
file = g_file_new_for_uri (uri);
|
||||
file_stream = g_file_read (file, NULL, NULL);
|
||||
if (file_stream) {
|
||||
GDataInputStream *data_stream = NULL;
|
||||
|
||||
data_stream = g_data_input_stream_new (G_INPUT_STREAM (file_stream));
|
||||
line = g_data_input_stream_read_line (data_stream, NULL, NULL, NULL);
|
||||
|
||||
g_object_unref (data_stream);
|
||||
g_object_unref (file_stream);
|
||||
}
|
||||
g_object_unref (file);
|
||||
return line;
|
||||
}
|
||||
|
@ -27,4 +27,7 @@ void spek_platform_fix_args (gchar **argv, gint argc);
|
||||
/* Open a link in the browser */
|
||||
void spek_platform_show_uri (const gchar *uri);
|
||||
|
||||
/* Read a line from a uri */
|
||||
gchar *spek_platform_read_line (const gchar *uri);
|
||||
|
||||
#endif
|
||||
|
@ -306,15 +306,8 @@ namespace Spek {
|
||||
}
|
||||
|
||||
// Get the version number.
|
||||
var file = File.new_for_uri ("http://www.spek-project.org/version");
|
||||
if (!file.query_exists (null)) {
|
||||
return null;
|
||||
}
|
||||
string version;
|
||||
try {
|
||||
var stream = new DataInputStream (file.read (null));
|
||||
version = stream.read_line (null, null);
|
||||
} catch (Error e) {
|
||||
var version = Platform.read_line ("http://www.spek-project.org/version");
|
||||
if (version == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -2,4 +2,5 @@
|
||||
namespace Spek.Platform {
|
||||
public static void fix_args (string[] args);
|
||||
public static void show_uri (string uri);
|
||||
public static string read_line (string uri);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user