Log uploading.

This commit is contained in:
Matthew Bowra-Dean
2010-05-26 19:23:58 +12:00
parent a6d0adbab3
commit e7c7a117a8
3 changed files with 50 additions and 1 deletions

View File

@@ -25,7 +25,9 @@ namespace OpenRA
{ {
public static class Log 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() static Log()
{ {
@@ -36,5 +38,10 @@ namespace OpenRA
{ {
writer.WriteLine(format, args); writer.WriteLine(format, args);
} }
public static void Close()
{
writer.Close();
}
} }
} }

View File

@@ -22,6 +22,9 @@ using System;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Windows.Forms; using System.Windows.Forms;
using System.Net;
using System.IO.Compression;
using System.IO;
namespace OpenRA namespace OpenRA
{ {
@@ -46,10 +49,35 @@ namespace OpenRA
catch( Exception e ) catch( Exception e )
{ {
Log.Write( "{0}", e.ToString() ); Log.Write( "{0}", e.ToString() );
UploadLog();
throw; 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 ) static void Run( string[] args )
{ {
Game.Initialize( new Settings( args ) ); Game.Initialize( new Settings( args ) );

14
web/logs/upload.php Normal file
View File

@@ -0,0 +1,14 @@
<?php
$post_file = fopen("php://input", "rb");
$log_file = fopen("log.".time().".gz", "wb");
$post_data = '';
while (!feof($post_file)) {
$post_data .= fread($post_file, 8192);
}
fwrite($log_file, $post_data);
fclose($post_file);
fclose($log_file);
?>