Move ClientCreds to NAPS2.Lib.Common and avoid custom prebuild

This commit is contained in:
Ben Olden-Cooligan 2022-07-29 22:09:34 -07:00
parent 7e162d82bd
commit 7f87a681f6
26 changed files with 260 additions and 41 deletions

View File

@ -14,7 +14,6 @@
<!--
We reference the 32-bit worker directly so the EXE is included in the output.
TODO: Is there a better way to do this?
-->
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>

View File

@ -16,7 +16,6 @@
<!--
We reference the 32-bit worker directly so the EXE is included in the output.
TODO: Is there a better way to do this?
-->
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>

View File

@ -29,5 +29,4 @@ _ReSharper*/
$tf*/
publish/
bin/
temp/
*.credentials.json
temp/

View File

@ -22,7 +22,6 @@
<!--
We reference the 32-bit worker directly so the EXE is included in the output.
TODO: Is there a better way to do this?
-->
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>

View File

@ -29,5 +29,4 @@ _ReSharper*/
$tf*/
publish/
bin/
temp/
*.credentials.json
temp/

View File

@ -29,5 +29,4 @@ _ReSharper*/
$tf*/
publish/
bin/
temp/
*.credentials.json
temp/

View File

@ -29,4 +29,6 @@ _ReSharper*/
$tf*/
publish/
bin/
temp/
temp/
google.credentials.json
microsoft.credentials.json

View File

@ -22,14 +22,14 @@ namespace NAPS2 {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class ClientCreds {
internal class ClientCreds_ {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal ClientCreds() {
internal ClientCreds_() {
}
/// <summary>
@ -39,7 +39,7 @@ namespace NAPS2 {
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NAPS2.ClientCreds", typeof(ClientCreds).Assembly);
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NAPS2.ClientCreds-", typeof(ClientCreds_).Assembly);
resourceMan = temp;
}
return resourceMan;

View File

@ -0,0 +1,130 @@
<?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.Runtime.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:import namespace="http://www.w3.org/XML/1998/namespace" />
<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" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</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" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="google_credentials" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>default.credentials.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="microsoft_credentials" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>default.credentials.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="naps2_public" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>naps2-public.cer;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>

View File

@ -0,0 +1,93 @@
//------------------------------------------------------------------------------
// <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 NAPS2 {
using System;
/// <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", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class ClientCreds_ {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal ClientCreds_() {
}
/// <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 (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NAPS2.ClientCreds_", typeof(ClientCreds_).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;
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] google_credentials {
get {
object obj = ResourceManager.GetObject("google_credentials", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] microsoft_credentials {
get {
object obj = ResourceManager.GetObject("microsoft_credentials", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] naps2_public {
get {
object obj = ResourceManager.GetObject("naps2_public", resourceCulture);
return ((byte[])(obj));
}
}
}
}

View File

@ -28,7 +28,7 @@ public class GmailOauthProvider : OauthProvider
{
if (_creds == null)
{
var credObj = JObject.Parse(Encoding.UTF8.GetString(NAPS2.ClientCreds.google_credentials));
var credObj = JObject.Parse(Encoding.UTF8.GetString(ClientCreds_.google_credentials));
var installed = credObj.Value<JObject>("installed");
_creds = new OauthClientCreds(installed?.Value<string>("client_id"),
installed?.Value<string>("client_secret"));

View File

@ -27,7 +27,7 @@ public class OutlookWebOauthProvider : OauthProvider
{
if (_creds == null)
{
var credObj = JObject.Parse(Encoding.UTF8.GetString(NAPS2.ClientCreds.microsoft_credentials));
var credObj = JObject.Parse(Encoding.UTF8.GetString(ClientCreds_.microsoft_credentials));
_creds = new OauthClientCreds(credObj.Value<string>("client_id"), credObj.Value<string>("client_secret"));
}
return _creds;

View File

@ -50,4 +50,20 @@
</ItemGroup>
<!--
This is a weird pattern and there's probably a better way to do it, but in order to have optional build files:
1. Have two resource files with similar names (so they generate the same class name, "ClientCreds_")
2. Have one resource file reference the optional build files, the other a placeholder build file
3. Conditionally exclude them from the build based on whether the optional files exist
-->
<ItemGroup Condition="Exists('google.credentials.json') and Exists('microsoft.credentials.json')">
<EmbeddedResource Remove="ClientCreds-.resx" />
<Compile Remove="ClientCreds-.Designer.cs" />
</ItemGroup>
<ItemGroup Condition="!Exists('google.credentials.json') or !Exists('microsoft.credentials.json')">
<EmbeddedResource Remove="ClientCreds_.resx" />
<Compile Remove="ClientCreds_.Designer.cs" />
</ItemGroup>
</Project>

View File

@ -0,0 +1 @@
{}

View File

@ -29,5 +29,4 @@ _ReSharper*/
$tf*/
publish/
bin/
temp/
*.credentials.json
temp/

View File

@ -177,7 +177,7 @@ public class UpdateOperation : OperationBase
private bool VerifySignature()
{
var cert = new X509Certificate2(ClientCreds.naps2_public);
var cert = new X509Certificate2(ClientCreds_.naps2_public);
var csp = (RSACryptoServiceProvider) cert.PublicKey.Key;
return csp.VerifyHash(_update!.Sha1, CryptoConfig.MapNameToOID("SHA1"), _update.Signature);
}

View File

@ -29,5 +29,4 @@ _ReSharper*/
$tf*/
publish/
bin/
temp/
*.credentials.json
temp/

View File

@ -29,5 +29,4 @@ _ReSharper*/
$tf*/
publish/
bin/
temp/
*.credentials.json
temp/

View File

@ -29,5 +29,4 @@ _ReSharper*/
$tf*/
publish/
bin/
temp/
*.credentials.json
temp/

View File

@ -29,5 +29,4 @@ _ReSharper*/
$tf*/
publish/
bin/
temp/
*.credentials.json
temp/

View File

@ -29,5 +29,4 @@ _ReSharper*/
$tf*/
publish/
bin/
temp/
*.credentials.json
temp/

View File

@ -29,5 +29,4 @@ _ReSharper*/
$tf*/
publish/
bin/
temp/
*.credentials.json
temp/

View File

@ -29,15 +29,6 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Standalone|AnyCPU'">
<DefineConstants>STANDALONE</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<PreBuildEvent Condition="'$(OS)' == 'Windows_NT'">If Not Exist $(ProjectDir)google.credentials.json (
echo {} &gt; $(ProjectDir)google.credentials.json
)
If Not Exist $(ProjectDir)microsoft.credentials.json (
echo { client_id: null, client_secret: null } &gt; $(ProjectDir)microsoft.credentials.json
)</PreBuildEvent>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ZXing.Net.Bindings.Windows.Compatibility" Version="0.16.7" />

View File

@ -29,5 +29,4 @@ _ReSharper*/
$tf*/
publish/
bin/
temp/
*.credentials.json
temp/