2016-07-05 20:22:34 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-07-18 14:46:26 +00:00
|
|
|
|
using System.Runtime.ExceptionServices;
|
2016-07-05 20:22:34 +00:00
|
|
|
|
|
|
|
|
|
namespace GalleryShare
|
|
|
|
|
{
|
|
|
|
|
class MainClass
|
|
|
|
|
{
|
|
|
|
|
public static int Main(string[] args)
|
|
|
|
|
{
|
2016-07-06 18:20:05 +00:00
|
|
|
|
string directory = Environment.CurrentDirectory;
|
2016-07-05 20:22:34 +00:00
|
|
|
|
int port = 3333;
|
|
|
|
|
List<string> extras = new List<string>();
|
|
|
|
|
for(int i = 0; i < args.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (!args[i].StartsWith("-"))
|
|
|
|
|
{
|
|
|
|
|
extras.Add(args[i]);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string trimmedArg = args[i].Trim('-');
|
|
|
|
|
switch (trimmedArg)
|
|
|
|
|
{
|
|
|
|
|
case "port":
|
|
|
|
|
case "p":
|
|
|
|
|
port = int.Parse(args[++i]);
|
|
|
|
|
break;
|
2016-07-06 18:20:05 +00:00
|
|
|
|
|
|
|
|
|
case "d":
|
|
|
|
|
case "directory":
|
|
|
|
|
directory = args[++i];
|
|
|
|
|
break;
|
2017-07-21 19:22:33 +00:00
|
|
|
|
|
|
|
|
|
case "h":
|
|
|
|
|
case "help":
|
|
|
|
|
Console.WriteLine("GalleryShare");
|
|
|
|
|
Console.WriteLine("by Starbeamrainbowlabs, find out more at https://github.com/sbrl/GalleryShare");
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
Console.WriteLine("Usage: ");
|
|
|
|
|
Console.WriteLine(" ./GalleryShare.exe [options]");
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
Console.WriteLine("Options: ");
|
|
|
|
|
Console.WriteLine(" -h --help Show this message");
|
|
|
|
|
Console.WriteLine(" -d --directory {directory_path} Specify the directory to serve files from. Defaults tot he current directory.");
|
|
|
|
|
Console.WriteLine(" -p --port {port_number} Specify the port to listen on. Default: 3333.");
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
return 0;
|
2016-07-06 18:20:05 +00:00
|
|
|
|
|
2016-07-05 20:22:34 +00:00
|
|
|
|
default:
|
|
|
|
|
Console.Error.WriteLine("Error: Unknown argument '{0}'.", args[i]);
|
2017-07-21 19:22:33 +00:00
|
|
|
|
Console.Error.WriteLine("Try ./GalleryShare --help to learn how to use GalleryShare.");
|
2016-07-05 20:22:34 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-06 18:20:05 +00:00
|
|
|
|
GalleryServer gserver = new GalleryServer(directory, port);
|
2016-07-18 14:46:26 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
gserver.StartSync();
|
|
|
|
|
}
|
|
|
|
|
catch(AggregateException agError)
|
|
|
|
|
{
|
|
|
|
|
agError.Handle((error) => {
|
|
|
|
|
ExceptionDispatchInfo.Capture(error).Throw();
|
|
|
|
|
throw error;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
Console.Error.WriteLine("Something went very wrong O.o");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2016-07-05 20:22:34 +00:00
|
|
|
|
|
|
|
|
|
return 255;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|