From e7c7a117a8e0ebb78404c96ba0d10383e8390f67 Mon Sep 17 00:00:00 2001 From: Matthew Bowra-Dean Date: Wed, 26 May 2010 19:23:58 +1200 Subject: [PATCH] Log uploading. --- OpenRA.FileFormats/Support/Log.cs | 9 ++++++++- OpenRA.Game/Support/Program.cs | 28 ++++++++++++++++++++++++++++ web/logs/upload.php | 14 ++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 web/logs/upload.php diff --git a/OpenRA.FileFormats/Support/Log.cs b/OpenRA.FileFormats/Support/Log.cs index d0d6be195f..3749bec046 100755 --- a/OpenRA.FileFormats/Support/Log.cs +++ b/OpenRA.FileFormats/Support/Log.cs @@ -25,7 +25,9 @@ namespace OpenRA { public static class Log { - static StreamWriter writer = File.CreateText(Environment.GetFolderPath(Environment.SpecialFolder.Personal) + Path.DirectorySeparatorChar + "openra.log.txt"); + public static string Filename = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + Path.DirectorySeparatorChar + "openra.log.txt"; + + static StreamWriter writer = File.CreateText(Filename); static Log() { @@ -36,5 +38,10 @@ namespace OpenRA { writer.WriteLine(format, args); } + + public static void Close() + { + writer.Close(); + } } } diff --git a/OpenRA.Game/Support/Program.cs b/OpenRA.Game/Support/Program.cs index 026f8a3654..a364bbcb8e 100644 --- a/OpenRA.Game/Support/Program.cs +++ b/OpenRA.Game/Support/Program.cs @@ -22,6 +22,9 @@ using System; using System.Diagnostics; using System.Globalization; using System.Windows.Forms; +using System.Net; +using System.IO.Compression; +using System.IO; namespace OpenRA { @@ -46,10 +49,35 @@ namespace OpenRA catch( Exception e ) { Log.Write( "{0}", e.ToString() ); + UploadLog(); throw; } } + static void UploadLog() + { + Log.Close(); + var logfile = File.OpenRead(Log.Filename); + byte[] fileContents = logfile.ReadAllBytes(); + var ms = new MemoryStream(); + + using (var gzip = new GZipStream(ms, CompressionMode.Compress, true)) + gzip.Write(fileContents, 0, fileContents.Length); + + ms.Position = 0; + byte[] buffer = ms.ReadAllBytes(); + + WebRequest request = WebRequest.Create("http://open-ra.org/logs/upload.php"); + request.ContentType = "application/x-gzip"; + request.ContentLength = buffer.Length; + request.Method = "POST"; + + using (var requestStream = request.GetRequestStream()) + requestStream.Write(buffer, 0, buffer.Length); + + var response = (HttpWebResponse)request.GetResponse(); + } + static void Run( string[] args ) { Game.Initialize( new Settings( args ) ); diff --git a/web/logs/upload.php b/web/logs/upload.php new file mode 100644 index 0000000000..53fc40910f --- /dev/null +++ b/web/logs/upload.php @@ -0,0 +1,14 @@ +