Upload tool.

This commit is contained in:
Matthew Bowra-Dean
2010-05-04 12:29:32 +12:00
parent cf31999703
commit d75174a671
4 changed files with 207 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{B56CAEB1-F805-48D6-8EBF-CB30CE5F1F35}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OpenRAUploader</RootNamespace>
<AssemblyName>OpenRAUploader</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRAUploader", "OpenRAUploader.csproj", "{B56CAEB1-F805-48D6-8EBF-CB30CE5F1F35}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B56CAEB1-F805-48D6-8EBF-CB30CE5F1F35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B56CAEB1-F805-48D6-8EBF-CB30CE5F1F35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B56CAEB1-F805-48D6-8EBF-CB30CE5F1F35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B56CAEB1-F805-48D6-8EBF-CB30CE5F1F35}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

92
OpenRAUploader/Program.cs Normal file
View File

@@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
namespace OpenRAUploader
{
class Program
{
static void Main(string[] args)
{
if (args.Length != 6) { PrintUsage(); return; }
var server = args[0];
var user = args[1];
var password = args[2];
var platform = args[3];
var version = args[4];
var filename = args[5];
var uri = new UriBuilder("ftp", server);
uri.UserName = user;
uri.Password = password;
uri.Path += platform + "/";
var mainFileUri = new UriBuilder(uri.Uri);
mainFileUri.Path += Path.GetFileName(filename);
if (!File.Exists(filename)) { Console.WriteLine(filename + " does not exist."); return; }
Console.WriteLine(string.Format("Uploading {0} to {1}", Path.GetFileName(filename), mainFileUri.Uri));
var fileStream = File.Open(filename, FileMode.Open, FileAccess.Read);
var size = fileStream.Length;
var response = UploadFile(mainFileUri.Uri, fileStream, false);
if (response != null) Console.WriteLine("Response: " + response.StatusDescription);
fileStream.Close();
var jsonUri = new UriBuilder(uri.Uri);
jsonUri.Path += "_version.json";
string formatString = "{{\n" +
"\t\"version\":\"{0}\",\n" +
"\t\"size\":\"{1:F2}MB\"\n" +
"}}";
string json = string.Format(formatString,
version,
((double)size / 1048576));
MemoryStream jsonStream = new MemoryStream(Encoding.ASCII.GetBytes(json));
Console.WriteLine("Uploading version JSON file");
response = UploadFile(jsonUri.Uri, jsonStream, true);
if (response != null) Console.WriteLine("Response: " + response.StatusDescription);
jsonStream.Close();
var latestUri = new UriBuilder(uri.Uri);
latestUri.Path += "latest.txt";
MemoryStream latestStream = new MemoryStream(Encoding.ASCII.GetBytes(Path.GetFileName(filename)));
Console.WriteLine("Uploading latest.txt");
response = UploadFile(latestUri.Uri, latestStream, true);
if (response != null) Console.WriteLine("Response: " + response.StatusDescription);
latestStream.Close();
}
static FtpWebResponse UploadFile(Uri uri, Stream file, bool text)
{
var ftp = WebRequest.Create(uri) as FtpWebRequest;
if (ftp == null) { Console.WriteLine("Couldn't create FTP client. URI incorrect?\n" + uri.ToString()); return null; }
ftp.Method = WebRequestMethods.Ftp.UploadFile;
ftp.UseBinary = !text;
var stream = ftp.GetRequestStream();
const int bufferLength = 2048;
byte[] buffer = new byte[bufferLength];
int readBytes = 0;
while ((readBytes = file.Read(buffer, 0, bufferLength)) != 0)
stream.Write(buffer, 0, readBytes);
stream.Close();
return ftp.GetResponse() as FtpWebResponse;
}
static void PrintUsage()
{
Console.WriteLine("Usage:\n OpenRAUploader.exe <ftp path> <username> <password> <platform> <version> <filename>");
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("OpenRAUploader")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OpenRAUploader")]
[assembly: AssemblyCopyright("Copyright © Matthew Bowra-Dean 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("560074b7-5fdf-4e21-aa72-4cb4f664b639")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]