Upload Src code.

This commit is contained in:
SilicaAndPina 2020-07-06 19:37:49 +12:00
parent 063e639cd4
commit 4d40cc0e27
14 changed files with 2471 additions and 0 deletions

25
ContentServer.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29806.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ContentServer", "ContentServer\ContentServer.csproj", "{352AA0E2-A443-4615-97BF-4CF2C08A09A3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{352AA0E2-A443-4615-97BF-4CF2C08A09A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{352AA0E2-A443-4615-97BF-4CF2C08A09A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{352AA0E2-A443-4615-97BF-4CF2C08A09A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{352AA0E2-A443-4615-97BF-4CF2C08A09A3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6D38E934-B5DF-4A2D-B3AA-FD0EFCDCE29F}
EndGlobalSection
EndGlobal

6
ContentServer/App.config Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

View File

@ -0,0 +1,331 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
namespace ContentServer
{
class ContentItem
{
public String name;
public String filePath;
public ContentItem(string Name,string FilePath)
{
if(File.Exists(FilePath))
{
filePath = FilePath;
name = Name;
}
else
{
throw new FileNotFoundException();
}
}
}
class ContentClient
{
public ContentClient(ContentServer Server, Socket ClientSocket)
{
clientSock = ClientSocket;
baseServ = Server;
Server.Clients.Add(this);
baseServ.WriteDebugOutput("PSVita Connected @ " + clientSock.RemoteEndPoint.ToString());
ProcessRequests();
clientSock.Close();
}
private ContentServer baseServ;
private Socket clientSock;
private byte[] ReadData()
{
while (clientSock.Available < 1) { }
byte[] by = new byte[clientSock.Available];
clientSock.Receive(by);
return by;
}
private void SendString(string str)
{
byte[] response = Encoding.UTF8.GetBytes(str);
clientSock.Send(response);
}
private string GenerateHeaders(string path, long content_length = 0)
{
string headers = "";
if (path == "/")
{
headers += "HTTP/1.1 200 OK\r\n";
headers += "Content-Type: text/html\r\n";
headers += "Accept-Ranges: bytes\r\n";
headers += "Server: ContentServer\r\n";
headers += "Content-Length: " + content_length + "\r\n";
headers += "Cache-Control: max-age=3600\r\n";
headers += "Connection: keep-alive\r\n";
headers += "\r\n";
}
else if (File.Exists(path))
{
FileInfo info = new FileInfo(path);
long length = info.Length;
if (content_length != 0)
length = content_length;
headers += "HTTP/1.1 200 OK\r\n";
headers += "Content-Type: application/octet-stream\r\n";
headers += "Accept-Ranges: bytes\r\n";
headers += "Server: ContentServer\r\n";
headers += "Content-Length: " + length + "\r\n";
headers += "Cache-Control: max-age=3600\r\n";
headers += "Connection: keep-alive\r\n";
headers += "\r\n";
}
else
{
headers += "HTTP/1.1 404 Not Found\r\n";
headers += "Content-Type: text/plain\r\n";
headers += "Accept-Ranges: bytes\r\n";
headers += "Server: ContentServer\r\n";
headers += "Content-Length: " + content_length + "\r\n";
headers += "Cache-Control: max-age=3600\r\n";
headers += "Connection: keep-alive\r\n";
headers += "\r\n";
}
return headers;
}
private void RespondGet(string path, Dictionary<string, string> query)
{
baseServ.WriteDebugOutput("GET " + path);
string name = Path.GetFileName(path);
if (ContentItemExists(name))
{
ContentItem ci = GetContentItem(name);
FileStream fs = File.OpenRead(ci.filePath);
try
{
string requestStr = GenerateHeaders(ci.filePath, fs.Length - fs.Position);
SendString(requestStr);
while(fs.Position < fs.Length)
{
int BUFFER_SIZE = 0x8500000;
if(fs.Position + BUFFER_SIZE <= fs.Length)
{
byte[] buffer = new byte[BUFFER_SIZE];
fs.Read(buffer, 0x00, BUFFER_SIZE);
clientSock.Send(buffer);
}
else
{
byte[] buffer = new byte[fs.Length - fs.Position];
fs.Read(buffer, 0x00, buffer.Length);
clientSock.Send(buffer);
}
}
}
catch (Exception) {
fs.Close();
};
}
else
{
string body = GeneratePage(path);
string requestStr = GenerateHeaders(path, body.Length);
requestStr += body;
SendString(requestStr);
}
}
private void RespondHead(string path)
{
string name = Path.GetFileName(path);
baseServ.WriteDebugOutput("HEAD " + path);
if (ContentItemExists(name))
{
ContentItem ci = GetContentItem(name);
string requestStr = GenerateHeaders(ci.filePath);
SendString(requestStr);
}
else
{
string body = GeneratePage(path);
string requestStr = GenerateHeaders(path, body.Length);
SendString(requestStr);
}
}
private bool ContentItemExists(string name)
{
bool exists = false;
foreach (ContentItem ci in baseServ.Contents)
{
if (ci.name == name)
{
exists = true;
}
}
return exists;
}
private ContentItem GetContentItem(string name)
{
foreach (ContentItem ci in baseServ.Contents)
{
if (ci.name == name)
{
return ci;
}
}
throw new FileNotFoundException();
}
private string GeneratePage(string path)
{
if (path == "/")
{
string body = "Content Downloader Server.<br>Open this url in PSVita's \"Content Downloader\" To view avalible files.";
foreach (ContentItem content in baseServ.Contents)
{
body += "<a href=\"" + content.name + "\"></a>";
}
return body;
}
else
{
string body = "File not found.";
return body;
}
}
private string ExtractPath(string relativeUri)
{
int questionIndex = relativeUri.IndexOf("?");
if (questionIndex != -1)
return relativeUri.Substring(0, questionIndex);
else
return relativeUri;
}
private Dictionary<string,string> ExtractQuery(string relativeUri)
{
int questionIndex = relativeUri.IndexOf("?");
if (questionIndex != -1)
{
string[] queryStrList = relativeUri.Substring(questionIndex + 1).Split('&');
Dictionary<string,string> queryDict = new Dictionary<string, string>();
foreach(string queryStr in queryStrList)
{
string[] qStr = queryStr.Split('=');
queryDict.Add(qStr[0], qStr[1]);
}
return queryDict;
}
else
return new Dictionary<string, string>();
}
private string ExtractRelativeUrl(string header)
{
int slashIndex = header.IndexOf("/");
int httpLen = header.IndexOf(" HTTP/1.1") - slashIndex;
string path = header.Substring(slashIndex, httpLen);
return path;
}
private void ProcessRequests()
{
byte[] data = ReadData();
// Parse Request
string curReq = Encoding.UTF8.GetString(data);
curReq = curReq.Replace("\r\n", "\n");
string[] reqLines = curReq.Split('\n');
foreach (string line in reqLines)
{
if (line.StartsWith("GET"))
{
string relUrl = ExtractRelativeUrl(line);
string path = ExtractPath(relUrl);
Dictionary<string,string> query = ExtractQuery(relUrl);
RespondGet(path, query);
return;
}
else if (line.StartsWith("HEAD"))
{
string relUrl = ExtractRelativeUrl(line);
string path = ExtractPath(relUrl);
RespondHead(path);
return;
}
}
}
}
class ContentServer
{
public List<ContentItem> Contents = new List<ContentItem>();
public List<ContentClient> Clients = new List<ContentClient>();
public void WriteDebugOutput(string txt)
{
Program.MainForm.Invoke((Action)delegate
{
Program.MainForm.AppendToConsole(txt + "\r\n");
});
}
public ContentServer()
{
new Thread(() =>
{
WriteDebugOutput("Listening for connections on port 1337.");
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 1337);
Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
newsock.Bind(localEndPoint);
newsock.Listen(20);
while(true)
{
Socket clientSock = newsock.Accept();
new Thread(() =>
{
ContentClient client = new ContentClient(this, clientSock);
Clients.Remove(client);
}).Start();
}
}).Start();
}
}
}

View File

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{352AA0E2-A443-4615-97BF-4CF2C08A09A3}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>ContentServer</RootNamespace>
<AssemblyName>ContentServer</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>icon0.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ServerGui.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="ServerGui.Designer.cs">
<DependentUpon>ServerGui.cs</DependentUpon>
</Compile>
<Compile Include="ContentServer.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="ServerGui.resx">
<DependentUpon>ServerGui.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Content Include="icon0.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

26
ContentServer/Program.cs Normal file
View File

@ -0,0 +1,26 @@
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
namespace ContentServer
{
static class Program
{
public static ServerGui MainForm;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
MainForm = new ServerGui();
Application.Run(MainForm);
}
}
}

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("ContentServer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ContentServer")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[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("352aa0e2-a443-4615-97bf-4cf2c08a09a3")]
// 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")]

View File

@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ContentServer.Properties
{
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ContentServer.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}

View File

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,30 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ContentServer.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}

View File

@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

174
ContentServer/ServerGui.Designer.cs generated Normal file
View File

@ -0,0 +1,174 @@
namespace ContentServer
{
partial class ServerGui
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ServerGui));
this.serverContents = new System.Windows.Forms.ListBox();
this.addPKG = new System.Windows.Forms.Button();
this.addPUP = new System.Windows.Forms.Button();
this.addMisc = new System.Windows.Forms.Button();
this.rmFile = new System.Windows.Forms.Button();
this.addFolder = new System.Windows.Forms.Button();
this.rmAll = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.consoleOutput = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// serverContents
//
this.serverContents.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.serverContents.FormattingEnabled = true;
this.serverContents.Location = new System.Drawing.Point(12, 44);
this.serverContents.Name = "serverContents";
this.serverContents.Size = new System.Drawing.Size(660, 394);
this.serverContents.TabIndex = 0;
//
// addPKG
//
this.addPKG.Location = new System.Drawing.Point(12, 12);
this.addPKG.Name = "addPKG";
this.addPKG.Size = new System.Drawing.Size(102, 23);
this.addPKG.TabIndex = 1;
this.addPKG.Text = "Add PKG File";
this.addPKG.UseVisualStyleBackColor = true;
this.addPKG.Click += new System.EventHandler(this.addPKG_Click);
//
// addPUP
//
this.addPUP.Location = new System.Drawing.Point(120, 12);
this.addPUP.Name = "addPUP";
this.addPUP.Size = new System.Drawing.Size(110, 23);
this.addPUP.TabIndex = 2;
this.addPUP.Text = "Add PUP File";
this.addPUP.UseVisualStyleBackColor = true;
this.addPUP.Click += new System.EventHandler(this.addPUP_Click);
//
// addMisc
//
this.addMisc.Location = new System.Drawing.Point(236, 12);
this.addMisc.Name = "addMisc";
this.addMisc.Size = new System.Drawing.Size(106, 23);
this.addMisc.TabIndex = 3;
this.addMisc.Text = "Add Misc";
this.addMisc.UseVisualStyleBackColor = true;
this.addMisc.Click += new System.EventHandler(this.addMisc_Click);
//
// rmFile
//
this.rmFile.Location = new System.Drawing.Point(460, 12);
this.rmFile.Name = "rmFile";
this.rmFile.Size = new System.Drawing.Size(106, 23);
this.rmFile.TabIndex = 4;
this.rmFile.Text = "Remove Selected";
this.rmFile.UseVisualStyleBackColor = true;
this.rmFile.Click += new System.EventHandler(this.rmFile_Click);
//
// addFolder
//
this.addFolder.Location = new System.Drawing.Point(348, 12);
this.addFolder.Name = "addFolder";
this.addFolder.Size = new System.Drawing.Size(106, 23);
this.addFolder.TabIndex = 5;
this.addFolder.Text = "Add Folder";
this.addFolder.UseVisualStyleBackColor = true;
this.addFolder.Click += new System.EventHandler(this.addFolder_Click);
//
// rmAll
//
this.rmAll.Location = new System.Drawing.Point(572, 12);
this.rmAll.Name = "rmAll";
this.rmAll.Size = new System.Drawing.Size(106, 23);
this.rmAll.TabIndex = 6;
this.rmAll.Text = "Remove All";
this.rmAll.UseVisualStyleBackColor = true;
this.rmAll.Click += new System.EventHandler(this.rmAll_Click);
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 446);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 13);
this.label1.TabIndex = 7;
this.label1.Text = "Console:";
//
// consoleOutput
//
this.consoleOutput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.consoleOutput.Location = new System.Drawing.Point(15, 462);
this.consoleOutput.Multiline = true;
this.consoleOutput.Name = "consoleOutput";
this.consoleOutput.ReadOnly = true;
this.consoleOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.consoleOutput.Size = new System.Drawing.Size(657, 147);
this.consoleOutput.TabIndex = 8;
//
// ServerGui
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(684, 621);
this.Controls.Add(this.consoleOutput);
this.Controls.Add(this.label1);
this.Controls.Add(this.rmAll);
this.Controls.Add(this.addFolder);
this.Controls.Add(this.rmFile);
this.Controls.Add(this.addMisc);
this.Controls.Add(this.addPUP);
this.Controls.Add(this.addPKG);
this.Controls.Add(this.serverContents);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MinimumSize = new System.Drawing.Size(700, 660);
this.Name = "ServerGui";
this.Text = "Content Server - Listening on Port 1337";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ServerGui_FormClosing);
this.Load += new System.EventHandler(this.ServerGui_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ListBox serverContents;
private System.Windows.Forms.Button addPKG;
private System.Windows.Forms.Button addPUP;
private System.Windows.Forms.Button addMisc;
private System.Windows.Forms.Button rmFile;
private System.Windows.Forms.Button addFolder;
private System.Windows.Forms.Button rmAll;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox consoleOutput;
}
}

119
ContentServer/ServerGui.cs Normal file
View File

@ -0,0 +1,119 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
namespace ContentServer
{
public partial class ServerGui : Form
{
ContentServer cs;
public ServerGui()
{
InitializeComponent();
}
public void AppendToConsole(string txt)
{
consoleOutput.AppendText(txt);
}
private void AddToList(string path)
{
try
{
string Name = Path.GetFileName(path);
ContentItem ci = new ContentItem(Name, path);
cs.Contents.Add(ci);
serverContents.Items.Add(Name);
}catch(FileNotFoundException)
{
MessageBox.Show("File \"" + path + "\" does not exist!", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ServerGui_Load(object sender, EventArgs e)
{
cs = new ContentServer();
}
private void addPKG_Click(object sender, EventArgs e)
{
OpenFileDialog pkgFileDialog = new OpenFileDialog();
pkgFileDialog.Filter = "Packages|*.PKG";
pkgFileDialog.Title = "Select a PKG File";
if (pkgFileDialog.ShowDialog() == DialogResult.OK)
{
AddToList(pkgFileDialog.FileName);
}
}
private void addPUP_Click(object sender, EventArgs e)
{
OpenFileDialog pupFileDialog = new OpenFileDialog();
pupFileDialog.Filter = "Packages|*.PUP";
pupFileDialog.Title = "Select a PUP File";
if (pupFileDialog.ShowDialog() == DialogResult.OK)
{
AddToList(pupFileDialog.FileName);
}
}
private void addMisc_Click(object sender, EventArgs e)
{
OpenFileDialog anyFileDialog = new OpenFileDialog();
anyFileDialog.Filter = "Misc|*.*";
anyFileDialog.Title = "Select a File";
if (anyFileDialog.ShowDialog() == DialogResult.OK)
{
AddToList(anyFileDialog.FileName);
}
}
private void addFolder_Click(object sender, EventArgs e)
{
FolderBrowserDialog addFolderDialog = new FolderBrowserDialog();
if(addFolderDialog.ShowDialog() == DialogResult.OK)
{
string[] fileList = Directory.GetFiles(addFolderDialog.SelectedPath, "*", SearchOption.AllDirectories);
foreach(string file in fileList)
{
AddToList(file);
}
}
}
private void rmFile_Click(object sender, EventArgs e)
{
try
{
string Name = serverContents.SelectedItem.ToString();
foreach (ContentItem ci in cs.Contents)
{
if (ci.name == Name)
{
cs.Contents.Remove(ci);
serverContents.Items.Remove(Name);
return;
}
}
}
catch (Exception){ }
}
private void rmAll_Click(object sender, EventArgs e)
{
cs.Contents.Clear();
serverContents.Items.Clear();
}
private void ServerGui_FormClosing(object sender, FormClosingEventArgs e)
{
Process.GetCurrentProcess().Kill(); //kys
}
}
}

1436
ContentServer/ServerGui.resx Normal file

File diff suppressed because it is too large Load Diff

BIN
ContentServer/icon0.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB