Add Platform.read_line

This commit is contained in:
Alexander Kojevnikov 2011-02-23 13:00:34 +08:00
parent 1426e66ea4
commit f1f63561f9
4 changed files with 26 additions and 9 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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);
}