Skip to content

Commit

Permalink
Program skeleton including args parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueSkeye committed Oct 2, 2016
1 parent 4ff8a23 commit 6fde0b3
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 0 deletions.
6 changes: 6 additions & 0 deletions SSUpdate/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
113 changes: 113 additions & 0 deletions SSUpdate/Program.cs
Original file line number Diff line number Diff line change
@@ -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 <database path>|-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;
}
}
15 changes: 15 additions & 0 deletions SSUpdate/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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.*")]
65 changes: 65 additions & 0 deletions SSUpdate/SSUpdate.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" 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)' == '' ">x64</Platform>
<ProjectGuid>{E62D8C43-5970-4FEF-96B7-921DCA8B6717}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SSUpdate</RootNamespace>
<AssemblyName>SSUpdate</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data.SQLite, Version=1.0.103.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Core.1.0.103\lib\net451\System.Data.SQLite.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\System.Data.SQLite.Core.1.0.103\build\net451\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.103\build\net451\System.Data.SQLite.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.103\build\net451\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.103\build\net451\System.Data.SQLite.Core.targets'))" />
</Target>
</Project>
4 changes: 4 additions & 0 deletions SSUpdate/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.Data.SQLite.Core" version="1.0.103" targetFramework="net452" />
</packages>
22 changes: 22 additions & 0 deletions VFeed.sln
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6fde0b3

Please sign in to comment.