From 6fde0b3aa6d76c991e661b0fa9bf8bea8a708b20 Mon Sep 17 00:00:00 2001 From: BlueSkeye Date: Sun, 2 Oct 2016 13:59:15 +0200 Subject: [PATCH] Program skeleton including args parsing --- SSUpdate/App.config | 6 ++ SSUpdate/Program.cs | 113 ++++++++++++++++++++++++++++ SSUpdate/Properties/AssemblyInfo.cs | 15 ++++ SSUpdate/SSUpdate.csproj | 65 ++++++++++++++++ SSUpdate/packages.config | 4 + VFeed.sln | 22 ++++++ 6 files changed, 225 insertions(+) create mode 100644 SSUpdate/App.config create mode 100644 SSUpdate/Program.cs create mode 100644 SSUpdate/Properties/AssemblyInfo.cs create mode 100644 SSUpdate/SSUpdate.csproj create mode 100644 SSUpdate/packages.config create mode 100644 VFeed.sln diff --git a/SSUpdate/App.config b/SSUpdate/App.config new file mode 100644 index 0000000..cb54343 --- /dev/null +++ b/SSUpdate/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SSUpdate/Program.cs b/SSUpdate/Program.cs new file mode 100644 index 0000000..d98c00d --- /dev/null +++ b/SSUpdate/Program.cs @@ -0,0 +1,113 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Data.SQLite; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace SSUpdate +{ + public static class Program + { + private static void DisplayUsage(string programName) + { + Console.WriteLine("{0} [-f |-h]"); + Console.WriteLine(); + Console.WriteLine("-f : path to vFeed database."); + Console.WriteLine("-h : display this help notice."); + return; + } + + private static void DisplayVersion(out string name) + { + Assembly mainAssembly = Assembly.GetEntryAssembly(); + AssemblyName mainAssemblyName = mainAssembly.GetName(); + + name = mainAssemblyName.Name; + Console.WriteLine("{0} v{1}.", name, mainAssemblyName.Version); + return; + } + + public static int Main(string[] args) + { + int result = 0; + string programName; + DisplayVersion(out programName); + + if (!ParseArgs(args)) { + _displayUsage = true; + } + if (_displayUsage) { + DisplayUsage(programName); + return result; + } + return result; + } + + private static bool ParseArgs(string[] args) + { + for(int argIndex = 0; args.Length > argIndex; argIndex++) { + string scannedArg = args[argIndex]; + bool unrecognizedArgument = false; + if ((2 > scannedArg.Length) || !scannedArg.StartsWith("-")) { + unrecognizedArgument = true; + } + else { + switch (scannedArg.Substring(1).ToUpper()) { + case "F": + string dbPath = TryGetAdditionalArgument(args, ref argIndex); + if (null == dbPath) { return false; } + _database = new FileInfo(dbPath); + if (!_database.Exists) { + Console.WriteLine("Database '{0}' not found.", _database.FullName); + return false; + } + using (FileStream data = TryOpenDatabase()) { + if (null == data) { return false; } + } + break; + default: + unrecognizedArgument = true; + break; + } + } + if (unrecognizedArgument) { + Console.WriteLine("Unrecognized argument '{0}'.", + scannedArg); + return false; + } + } + _connectionString = string.Format("Data Source={0};Version=3;", + _database.FullName); + return true; + } + + private static string TryGetAdditionalArgument(string[] from, ref int index) + { + string currentArgument = from[index]; + if (from.Length <= ++index) { + Console.WriteLine("Additional argument missing after {0}.", + currentArgument); + return null; + } + return from[index]; + } + + private static FileStream TryOpenDatabase() + { + try { + return File.Open(_database.FullName, FileMode.Open, FileAccess.Read, FileShare.Read); + } + catch (Exception e) { + Console.WriteLine("Error occurred while opening database '{0}' : {1}", + _database.FullName, e.Message); + return null; + } + } + + private static string _connectionString; + private static FileInfo _database; + private static bool _displayUsage; + } +} diff --git a/SSUpdate/Properties/AssemblyInfo.cs b/SSUpdate/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..33ad9af --- /dev/null +++ b/SSUpdate/Properties/AssemblyInfo.cs @@ -0,0 +1,15 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("SSUpdate")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SSUpdate")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] +[assembly: Guid("e62d8c43-5970-4fef-96b7-921dca8b6717")] +[assembly: AssemblyVersion("1.0.*")] diff --git a/SSUpdate/SSUpdate.csproj b/SSUpdate/SSUpdate.csproj new file mode 100644 index 0000000..1cb7967 --- /dev/null +++ b/SSUpdate/SSUpdate.csproj @@ -0,0 +1,65 @@ + + + + + Debug + x64 + {E62D8C43-5970-4FEF-96B7-921DCA8B6717} + Exe + Properties + SSUpdate + SSUpdate + v4.5.2 + 512 + true + + + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + ..\packages\System.Data.SQLite.Core.1.0.103\lib\net451\System.Data.SQLite.dll + True + + + + + + + + + + + + + + + + + + Ce projet fait référence à des packages NuGet qui sont manquants sur cet ordinateur. Utilisez l'option de restauration des packages NuGet pour les télécharger. Pour plus d'informations, consultez http://go.microsoft.com/fwlink/?LinkID=322105. Le fichier manquant est : {0}. + + + + \ No newline at end of file diff --git a/SSUpdate/packages.config b/SSUpdate/packages.config new file mode 100644 index 0000000..d2f1d43 --- /dev/null +++ b/SSUpdate/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/VFeed.sln b/VFeed.sln new file mode 100644 index 0000000..051606a --- /dev/null +++ b/VFeed.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SSUpdate", "SSUpdate\SSUpdate.csproj", "{E62D8C43-5970-4FEF-96B7-921DCA8B6717}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E62D8C43-5970-4FEF-96B7-921DCA8B6717}.Debug|x64.ActiveCfg = Debug|x64 + {E62D8C43-5970-4FEF-96B7-921DCA8B6717}.Debug|x64.Build.0 = Debug|x64 + {E62D8C43-5970-4FEF-96B7-921DCA8B6717}.Release|x64.ActiveCfg = Release|x64 + {E62D8C43-5970-4FEF-96B7-921DCA8B6717}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal