-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
210 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.Drawing.Imaging; | ||
using System.IO; | ||
using NDesk.Options; | ||
using System.Reflection; | ||
using QRCoder; | ||
using System.Text; | ||
|
||
namespace QRCoderConsole | ||
{ | ||
class MainClass | ||
{ | ||
public static void Main (string[] args) | ||
{ | ||
var friendlyName = AppDomain.CurrentDomain.FriendlyName; | ||
var newLine = Environment.NewLine; | ||
var setter = new OptionSetter (); | ||
|
||
String fileName = null, outputFileName = null; | ||
|
||
QRCodeGenerator.ECCLevel eccLevel = QRCodeGenerator.ECCLevel.L; | ||
|
||
var showHelp = false; | ||
|
||
|
||
var optionSet = new OptionSet { | ||
{ "e|ecc-level=", | ||
"error correction level", | ||
value => eccLevel = setter.GetECCLevel(value) | ||
}, | ||
{ | ||
"i|in=", | ||
"input file", | ||
value => fileName = value | ||
}, | ||
{ | ||
"o|out=", | ||
"output file", | ||
value => outputFileName = value | ||
}, | ||
{ "h|help", | ||
"show this message and exit.", | ||
value => showHelp = value != null | ||
} | ||
}; | ||
|
||
try | ||
{ | ||
|
||
var settings = optionSet.Parse(args); | ||
|
||
if (showHelp) { | ||
optionSet.WriteOptionDescriptions(Console.Out); | ||
Environment.Exit(0); | ||
} | ||
|
||
var fileInfo = new FileInfo(fileName); | ||
|
||
if (fileInfo.Exists) | ||
{ | ||
var buffer = new byte[fileInfo.Length]; | ||
|
||
using (var fileStream = new FileStream(fileInfo.FullName, FileMode.Open)) | ||
{ | ||
fileStream.Read(buffer, 0, buffer.Length); | ||
} | ||
|
||
var text = Encoding.UTF8.GetString(buffer); | ||
|
||
using (var generator = new QRCodeGenerator()) | ||
{ | ||
using (var data = generator.CreateQrCode(text, eccLevel)) | ||
{ | ||
using (var code = new QRCode(data)) | ||
{ | ||
using (var bitmap = code.GetGraphic(20)) | ||
{ | ||
bitmap.Save(outputFileName, ImageFormat.Png); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
} | ||
else { | ||
Console.WriteLine($"{friendlyName}: {fileName}: No such file or directory"); | ||
} | ||
} | ||
catch (OptionException oe) { | ||
Console.Error.WriteLine($"{friendlyName}:{newLine}{oe.Message}{newLine}Try '{friendlyName} --help' for more information"); | ||
Environment.Exit (-1); | ||
} | ||
|
||
} | ||
} | ||
|
||
public class OptionSetter | ||
{ | ||
public QRCodeGenerator.ECCLevel GetECCLevel(string value) | ||
{ | ||
QRCodeGenerator.ECCLevel level; | ||
|
||
Enum.TryParse (value, out level); | ||
|
||
return level; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
// Information about this assembly is defined by the following attributes. | ||
// Change them to the values specific to your project. | ||
|
||
[assembly: AssemblyTitle ("QRCoderConsole")] | ||
[assembly: AssemblyDescription ("")] | ||
[assembly: AssemblyConfiguration ("")] | ||
[assembly: AssemblyCompany ("")] | ||
[assembly: AssemblyProduct ("")] | ||
[assembly: AssemblyCopyright ("mishochu")] | ||
[assembly: AssemblyTrademark ("")] | ||
[assembly: AssemblyCulture ("")] | ||
|
||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". | ||
// The form "{Major}.{Minor}.*" will automatically update the build and revision, | ||
// and "{Major}.{Minor}.{Build}.*" will update just the revision. | ||
|
||
[assembly: AssemblyVersion ("1.0.*")] | ||
|
||
// The following attributes are used to specify the signing key for the assembly, | ||
// if desired. See the Mono documentation for more information about signing. | ||
|
||
//[assembly: AssemblyDelaySign(false)] | ||
//[assembly: AssemblyKeyFile("")] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{014F04C6-6099-4552-9A4F-D09C6E39D576}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>QRCoderConsole</RootNamespace> | ||
<AssemblyName>QRCoderConsole</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug</OutputPath> | ||
<DefineConstants>DEBUG;</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Externalconsole>true</Externalconsole> | ||
<Commandlineparameters>--in foo --out fooQR.png</Commandlineparameters> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>full</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release</OutputPath> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Externalconsole>true</Externalconsole> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="NDesk.Options"> | ||
<HintPath>..\packages\NDesk.Options.0.2.1\lib\NDesk.Options.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Drawing" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\QRCoder\QRCoder.csproj"> | ||
<Project>{AECE5DF3-C379-46CA-BB7D-7BDBE59011FD}</Project> | ||
<Name>QRCoder</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="NDesk.Options" version="0.2.1" targetFramework="net45" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters