Skip to content

Commit

Permalink
Move all logic into a .net standard library and create a .NET Framewo…
Browse files Browse the repository at this point in the history
…rk 4.6.2 version
  • Loading branch information
zerratar committed Apr 11, 2018
1 parent c40b875 commit d9fb5a1
Show file tree
Hide file tree
Showing 50 changed files with 249 additions and 19 deletions.
16 changes: 15 additions & 1 deletion SubSync.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C182B254-972
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{7D3E5130-833D-4426-9E7C-7D91CBA217B3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SubSync.Tests", "tests\SubSync.Tests\SubSync.Tests.csproj", "{71C95A54-2D86-4AC9-AE79-05CF93E063EA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SubSync.Tests", "tests\SubSync.Tests\SubSync.Tests.csproj", "{71C95A54-2D86-4AC9-AE79-05CF93E063EA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SubSync.Net462", "src\SubSync.Net462\SubSync.Net462.csproj", "{509779D3-9078-4E5D-A669-201D64D9B31B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SubSync.Core", ".src\SubSync.Core\SubSync.Core.csproj", "{3B7818EB-0872-460B-B4CA-499FDCD32CBE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -25,13 +29,23 @@ Global
{71C95A54-2D86-4AC9-AE79-05CF93E063EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71C95A54-2D86-4AC9-AE79-05CF93E063EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71C95A54-2D86-4AC9-AE79-05CF93E063EA}.Release|Any CPU.Build.0 = Release|Any CPU
{509779D3-9078-4E5D-A669-201D64D9B31B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{509779D3-9078-4E5D-A669-201D64D9B31B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{509779D3-9078-4E5D-A669-201D64D9B31B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{509779D3-9078-4E5D-A669-201D64D9B31B}.Release|Any CPU.Build.0 = Release|Any CPU
{3B7818EB-0872-460B-B4CA-499FDCD32CBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B7818EB-0872-460B-B4CA-499FDCD32CBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B7818EB-0872-460B-B4CA-499FDCD32CBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B7818EB-0872-460B-B4CA-499FDCD32CBE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A1B8C57E-2B99-4D21-A35E-D050F3BA279B} = {C182B254-972A-4CB2-8002-1653E0F24323}
{71C95A54-2D86-4AC9-AE79-05CF93E063EA} = {7D3E5130-833D-4426-9E7C-7D91CBA217B3}
{509779D3-9078-4E5D-A669-201D64D9B31B} = {C182B254-972A-4CB2-8002-1653E0F24323}
{3B7818EB-0872-460B-B4CA-499FDCD32CBE} = {C182B254-972A-4CB2-8002-1653E0F24323}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1EBFA09F-C84B-4414-AAF2-998BD08F6A97}
Expand Down
9 changes: 0 additions & 9 deletions publish.bat

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void Stop()

public void Reset()
{
queue.Clear();
while (queue.TryDequeue(out _)) ;
queueTries.Clear();
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Runtime.Serialization;

Expand Down Expand Up @@ -83,20 +84,30 @@ private T DeserializeGeneric<T>(string dataRoot, Type genericType, PropertyInfo[

private T DeserializeArray<T>(string dataRoot, Type elementType, PropertyInfo[] properties)
{
dynamic list = Activator.CreateInstance(typeof(List<>).MakeGenericType(elementType));
var list = Activator.CreateInstance(typeof(List<>).MakeGenericType(elementType)) as IList;
//var listAdd = list.GetType().GetMethod("Add", BindingFlags.Public);

if (FindRecursive(dataRoot) is XmlRpcMember member)
{
if (member.Value is XmlRpcArray array)
{
foreach (var item in array.Items)
{
dynamic value = Deserialize(elementType, item, properties);
list.Add(value);
var value = Deserialize(elementType, item, properties);
list.Add(Convert.ChangeType(value, elementType));
}
}
}

return list.ToArray();
var result = Array.CreateInstance(elementType, list.Count);
var index = 0;
foreach (var item in list)
{
result.SetValue(item, index++);
}


return (T)(object)result;
}

private object Deserialize(Type targetType, XmlRpcObjectBase item, PropertyInfo[] properties)
Expand All @@ -121,8 +132,8 @@ private object DeserializeStruct(Type structType, XmlRpcStruct structData, Prope
{
if (member.Value is IXmlRpcObjectValue val)
{
dynamic v = val.GetValue();
prop.SetValue(instance, v);
var v = val.GetValue();
prop.SetValue(instance, Convert.ChangeType(v, prop.PropertyType));
}
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/SubSync.Core/Properties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("SubSync.Tests")]
[assembly: InternalsVisibleTo("SubSync.Net462")]
[assembly: InternalsVisibleTo("SubSync")]
12 changes: 12 additions & 0 deletions src/SubSync.Core/SubSync.Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>SubSync</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SharpCompress" Version="0.20.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private async Task<Subtitle[]> SearchSubtitleAsync(string name)
var episodeGroup = m.Groups["episode"];
if (episodeGroup.Success && string.IsNullOrEmpty(episode))
{
var item = episodeGroup.Captures.FirstOrDefault();
var item = episodeGroup.Captures[0];
if (item != null && !string.IsNullOrEmpty(item.Value))
{
episode = item.Value;
Expand All @@ -141,7 +141,7 @@ private async Task<Subtitle[]> SearchSubtitleAsync(string name)
var seasonGroup = m.Groups["season"];
if (seasonGroup.Success && string.IsNullOrEmpty(season))
{
var item = seasonGroup.Captures.FirstOrDefault();
var item = seasonGroup.Captures[0];
if (item != null && !string.IsNullOrEmpty(item.Value))
{
season = item.Value;
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions src/SubSync.Net462/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.6.2" />
</startup>
</configuration>
93 changes: 93 additions & 0 deletions src/SubSync.Net462/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace SubSync.Net462
{
class Program
{
static void Main(string[] args)
{
var input = "./";
var videoExtensions = ParseList("*.avi;*.mp4;*.mkv;*.mpeg;*.flv;*.webm");
var subtitleExtensions = ParseList("*.srt;*.txt;*.sub;*.idx;*.ssa;*.ass");
var languages = ParseList("english");

if (args.Length > 0 && !string.IsNullOrEmpty(args[0]))
{
input = args[0];
}

if (args.Length > 1 && !string.IsNullOrEmpty(args[1]))
{
languages = ParseList(args[1]);
}

if (args.Length > 2 && !string.IsNullOrEmpty(args[2]))
{
videoExtensions = ParseList(args[2]);
}

var version = GetVersion();
var logger = new ConsoleLogger();

using (var fallbackSubtitleProvider = new FallbackSubtitleProvider(
new OpenSubtitles(languages, new FileBasedCredentialsProvider("opensubtitle.auth", logger)),
new Subscene(languages)))
{
var resultReporter = new QueueProcessReporter();
var subSyncWorkerProvider = new WorkerProvider(logger, subtitleExtensions, fallbackSubtitleProvider, resultReporter);
var subSyncWorkerQueue = new WorkerQueue(subSyncWorkerProvider, resultReporter);

using (var mediaWatcher = new SubtitleSynchronizer(logger, subSyncWorkerQueue, resultReporter, input, videoExtensions, subtitleExtensions))
{
logger.WriteLine("╔════════════════════════════════════════════╗");
logger.WriteLine("║ @whi@SubSync v" + version.PadRight(30 - version.Length) + "@gray@ ║");
logger.WriteLine("║ -------------------------------------- ║");
logger.WriteLine("║ Copyright (c) 2018 zerratar\\@gmail.com ║");
logger.WriteLine("╚════════════════════════════════════════════╝");
logger.WriteLine("");
logger.WriteLine(" Following folder and its subfolders being watched");
logger.WriteLine($" @whi@{input} @gray@");
logger.WriteLine("");
logger.WriteLine(" You may press @green@'q' @gray@at any time to quit.");
logger.WriteLine("");
logger.WriteLine(" ───────────────────────────────────────────────────── ");
logger.WriteLine("");

mediaWatcher.Start();
ConsoleKeyInfo ck;
while ((ck = Console.ReadKey(true)).Key != ConsoleKey.Q)
{
if (ck.Key == ConsoleKey.A)
{
mediaWatcher.SyncAll();
}
System.Threading.Thread.Sleep(10);
}
}
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static string GetVersion()
{
var assembly = System.Reflection.Assembly.GetExecutingAssembly();
var fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
return fvi.FileVersion;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static HashSet<string> ParseList(string s)
{
return new HashSet<string>(s
.Split(';')
.Select(x => x.Trim())
.Select(x => x.StartsWith("*") ? x.Substring(1) : x));
}
}
}
36 changes: 36 additions & 0 deletions src/SubSync.Net462/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SubSync")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SubSync")]
[assembly: AssemblyCopyright("Copyright © Shinobytes 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("509779d3-9078-4e5d-a669-201d64d9b31b")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.4.0")]
[assembly: AssemblyFileVersion("0.1.4.0")]
58 changes: 58 additions & 0 deletions src/SubSync.Net462/SubSync.Net462.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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)' == '' ">AnyCPU</Platform>
<ProjectGuid>{509779D3-9078-4E5D-A669-201D64D9B31B}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>SubSync</RootNamespace>
<AssemblyName>SubSync</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\build\net462\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\SubSync.Core\SubSync.Core.csproj">
<Project>{3b7818eb-0872-460b-b4ca-499fdcd32cbe}</Project>
<Name>SubSync.Core</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
4 changes: 4 additions & 0 deletions src/SubSync/SubSync.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<PackageReference Include="SharpCompress" Version="0.20.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\SubSync.Core\SubSync.Core.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="opensubtitles.auth">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down

0 comments on commit d9fb5a1

Please sign in to comment.