├── LICENSE
├── README.md
├── res
├── Setup.json
├── libwnd.png
└── mainwnd.png
└── src
├── AaxAudioConverter 2.x.sln
├── Audible.json.core
├── Audible.json.core.csproj
├── LibraryResponse.cs
├── LicenseResponse.cs
├── RegistrationResponse.cs
├── Serialization.cs
└── Voucher.cs
├── AuxLib.core
├── AffineSynchronizationContext.cs
├── ApplEnv.cs
├── ArgParser.cs
├── AuxLib.core.csproj
├── BigEndianReader.cs
├── BooleanYesNoConverter.cs
├── ChainPunctuation.cs
├── EnumChainTypeConverter.cs
├── EnumConverter.cs
├── EnumUtil.cs
├── ExtensionsSyncContext.cs
├── ExtensionsVarious.cs
├── IInteractionCallback.cs
├── Indent.cs
├── InteractionCallback.cs
├── InteractionMessage.cs
├── Interfaces.cs
├── JsonSerialization.cs
├── LogGuard.cs
├── Logging.cs
├── ProcessHost.cs
├── ProcessList.cs
├── ResourceGuard.cs
├── ResourceManagerEx.cs
├── SettingsManager.cs
├── ShellExecute.cs
├── Singleton.cs
├── SymmetricEncryptor.cs
├── Temp.cs
├── TimeUtil.cs
└── crc.cs
├── AuxWin.DialogBox.core
├── AuxWin.DialogBox.core.csproj
├── CbtHook.cs
├── DialogBox.cs
├── Win32API.cs
├── WindowsHook.cs
└── WndProcRetHook.cs
├── AuxWin.lib.core
├── AuxWin.lib.core.csproj
├── ExtensionsControl.cs
├── ExtensionsForm.cs
├── InteractionCallbackHandler.cs
├── Interfaces.cs
├── Properties
│ ├── Resources.Designer.cs
│ └── Resources.resx
├── SimpleWizard.Designer.cs
├── SimpleWizard.cs
├── SimpleWizard.resx
├── SortableBindingList.cs
├── SortableBindingListSuspensible.cs
└── SystemMenu.cs
├── AuxWin32Lib.core
├── AuxWin32Lib.core.csproj
├── FileAssociation.cs
└── Win32FileIO.cs
├── BooksDatabase.core
├── AudioQuality.cs
├── BooksDatabase.core.csproj
├── BooksDbContext.cs
├── Entities.cs
├── Extensions.cs
├── Interfaces.cs
├── InternalsVisible.cs
├── Migrations
│ ├── 20220107145340_InitialCreate.Designer.cs
│ ├── 20220107145340_InitialCreate.cs
│ ├── 20220119172449_SeriesSeq.Designer.cs
│ ├── 20220119172449_SeriesSeq.cs
│ ├── 20220122181409_ChapterTree.Designer.cs
│ ├── 20220122181409_ChapterTree.cs
│ ├── 20220210175323_NullableDeleted.Designer.cs
│ ├── 20220210175323_NullableDeleted.cs
│ ├── 20220219161122_DownloadQuality.Designer.cs
│ ├── 20220219161122_DownloadQuality.cs
│ └── BookDbContextModelSnapshot.cs
└── enums.cs
├── CommonTypes.lib.core
├── CommonTypes.lib.core.csproj
├── Enums.cs
└── Interfaces.cs
├── CommonUtil.lib.core
├── CommonUtil.lib.core.csproj
├── FileEx.cs
├── LogTmpFileMaintenance.cs
├── OnlineUpdate.cs
├── Records.cs
├── Settings.cs
├── ThreadProgress.cs
├── ToStringConverters.cs
└── enums.cs
├── Connect.app.gui.core
├── AboutForm.Designer.cs
├── AboutForm.cs
├── AboutForm.resx
├── AppSettings.cs
├── BookLibConnect.odt
├── Connect.app.gui.core.csproj
├── ConversionContext.cs
├── MainForm.Designer.cs
├── MainForm.cs
├── MainForm.resx
├── Program.cs
├── ProgressProcessor.cs
├── Properties
│ ├── PublishProfiles
│ │ └── FolderProfile.pubxml
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ ├── Settings.settings
│ └── launchSettings.json
├── Resources
│ ├── audio.ico
│ └── audio.png
├── UserSettings.cs
├── WaitForm.Designer.cs
├── WaitForm.cs
├── WaitForm.resx
├── WizStepDownload.Designer.cs
├── WizStepDownload.cs
├── WizStepDownload.resx
├── WizStepExport.Designer.cs
├── WizStepExport.cs
├── WizStepExport.resx
├── WizStepHelp.Designer.cs
├── WizStepHelp.cs
├── WizStepHelp.resx
├── WizStepProfile.Designer.cs
├── WizStepProfile.cs
├── WizStepProfile.resx
└── appsettings.json
├── Connect.lib.core
├── AaxExporter.cs
├── AccountAlias.cs
├── Anonymizer.cs
├── AudibleApi.cs
├── AudibleClient.cs
├── Authorize.cs
├── BookLibrary.cs
├── Connect.lib.core.csproj
├── ConsoleExternalLoginCallback.cs
├── Delegates.cs
├── DownloadDecryptJob.cs
├── ExtensionsLogging.cs
├── ExtensionsVarious.cs
├── HttpClientEx.cs
├── Interfaces.cs
├── InternalsVisible.cs
├── Localization.cs
├── Login.cs
├── Profile.cs
├── Properties
│ ├── Resources.Designer.cs
│ └── Resources.resx
├── Records.cs
├── ReducedChoicesDownloadQuality.cs
├── Settings.cs
└── enums.cs
├── Connect.ui.lib.core
├── AccountAliasForm.Designer.cs
├── AccountAliasForm.cs
├── AccountAliasForm.resx
├── BookDataSource.cs
├── BookDataSourceBase.cs
├── BookLibDGVControl.Designer.cs
├── BookLibDGVControl.cs
├── BookLibDGVControl.resx
├── BookLibForm.Designer.cs
├── BookLibForm.cs
├── BookLibForm.resx
├── BookPGA.cs
├── Connect.ui.lib.core.csproj
├── ConversionDataSource.cs
├── ConvertDGVControl.Designer.cs
├── ConvertDGVControl.cs
├── ConvertDGVControl.resx
├── DataGridViewEx.cs
├── DataGridViewEx.resx
├── DataSourceBase.cs
├── Events.cs
├── Extensions.cs
├── InternalsVisible.cs
├── ManageProfilesForm.Designer.cs
├── ManageProfilesForm.cs
├── ManageProfilesForm.resx
├── NewProfileForm.Designer.cs
├── NewProfileForm.cs
├── NewProfileForm.resx
├── Properties
│ ├── Resources.Designer.cs
│ └── Resources.resx
├── Resources
│ ├── blank.png
│ ├── check.png
│ ├── checkGrey.png
│ ├── checkMauve.png
│ ├── down.png
│ ├── downBroken.png
│ ├── globe.png
│ ├── globeDown.png
│ ├── globeFailed.png
│ ├── license.png
│ ├── licenseDenied.png
│ ├── locked.png
│ ├── plus.png
│ ├── question.png
│ ├── redx.png
│ ├── right.png
│ ├── rightFailed.png
│ ├── unlocked.png
│ ├── unlocking.png
│ └── unlockingFailed.png
└── TypeConvertersRM.cs
├── InnoSetup
└── BookLibConnect setup.iss
├── PropGridLib.core
├── Attributes.cs
├── BasePropertyGridAdapter.cs
├── Descriptor.cs
├── DynamicProperty.cs
├── PropGridLib.core.csproj
├── PropertyGridExtension.cs
└── PropertySorter.cs
├── SystemMgmt.core
├── HardwareId.cs
├── MotherboardInfo.cs
└── SystemMgmt.core.csproj
└── TreeDecomposition.core
├── AbstractPrimitiveTypes.cs
├── CustomAttributes.cs
├── Enums.cs
├── Interfaces.cs
├── ToStringConverter.cs
├── TreeDecomposition.core.csproj
├── TreeDecomposition.cs
├── TreeDecompositionExtension.cs
└── TypeExtension.cs
/res/Setup.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "Url": "https://github.com/audiamus/BookLibConnect/releases/download/v0.13.1/BookLibConnect-0.13.1-Setup.exe",
4 | "AppName": "BookLibConnect",
5 | "Version": "0.13.1",
6 | "Preview": false,
7 | "Descript": "Standalone Audible downloader and decrypter, companion to AAX Audio Converter",
8 | "Md5": "f3113ee6dfe9bb44604fb34011d45c7d"
9 | }
10 | ]
11 |
--------------------------------------------------------------------------------
/res/libwnd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audiamus/BookLibConnect/865f3bc0eee88dd408864ec25e14750dabc5e918/res/libwnd.png
--------------------------------------------------------------------------------
/res/mainwnd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audiamus/BookLibConnect/865f3bc0eee88dd408864ec25e14750dabc5e918/res/mainwnd.png
--------------------------------------------------------------------------------
/src/Audible.json.core/Audible.json.core.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | core.audiamus.adb.json
6 | audiamus.audiible.json.core
7 | audiamus
8 | Copyright © 2021 - $([System.DateTime]::UtcNow.Year) audiamus ($([System.DateTime]::UtcNow.ToString("s")))
9 | 0.5.0.0
10 | 0.5.0.0
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/Audible.json.core/LicenseResponse.cs:
--------------------------------------------------------------------------------
1 | namespace core.audiamus.adb.json {
2 |
3 | public class LicenseResponse : Serialization {
4 | public ContentLicense content_license { get; set; }
5 | public string[] response_groups { get; set; }
6 | }
7 |
8 | public class MetadataContainer : Serialization {
9 | public ContentMetadata content_metadata { get; set; }
10 | }
11 |
12 | public partial class ContentLicense {
13 | public string acr { get; set; }
14 | public string asin { get; set; }
15 | public ContentMetadata content_metadata { get; set; }
16 | public string drm_type { get; set; }
17 | public string license_id { get; set; }
18 | public string license_response { get; set; }
19 | public string message { get; set; }
20 | public string request_id { get; set; }
21 | public bool? requires_ad_supported_playback { get; set; }
22 | public string status_code { get; set; }
23 | public string voucher_id { get; set; }
24 |
25 | public Voucher voucher { get; set; }
26 | }
27 |
28 | public class ContentMetadata {
29 | public ChapterInfo chapter_info { get; set; }
30 | public ContentReference content_reference { get; set; }
31 | public ContentUrl content_url { get; set; }
32 | public LastPositionHeard last_position_heard { get; set; }
33 | }
34 |
35 | public class ChapterInfo {
36 | public int? brandIntroDurationMs { get; set; }
37 | public int? brandOutroDurationMs { get; set; }
38 | public Chapter[] chapters { get; set; }
39 | public bool? is_accurate { get; set; }
40 | public int? runtime_length_ms { get; set; }
41 | public int? runtime_length_sec { get; set; }
42 | }
43 |
44 | public class Chapter {
45 | public int? length_ms { get; set; }
46 | public int? start_offset_ms { get; set; }
47 | public int? start_offset_sec { get; set; }
48 | public string title { get; set; }
49 | public Chapter[] chapters { get; set; }
50 | }
51 |
52 | public class ContentReference {
53 | public string acr { get; set; }
54 | public string asin { get; set; }
55 | public string content_format { get; set; }
56 | public long? content_size_in_bytes { get; set; }
57 | public string file_version { get; set; }
58 | public string marketplace { get; set; }
59 | public string sku { get; set; }
60 | public string tempo { get; set; }
61 | public string version { get; set; }
62 | }
63 |
64 | public class ContentUrl {
65 | public string offline_url { get; set; }
66 | }
67 |
68 | public class LastPositionHeard {
69 | public string last_updated { get; set; }
70 | public int? position_ms { get; set; }
71 | public string status { get; set; }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/Audible.json.core/RegistrationResponse.cs:
--------------------------------------------------------------------------------
1 | namespace core.audiamus.adb.json {
2 | public class RegistrationResponse : Serialization {
3 | public Response response { get; set; }
4 | public string request_id { get; set; }
5 | }
6 |
7 | public class Response {
8 | public Success success { get; set; }
9 | }
10 |
11 | public class Success {
12 | public Extensions extensions { get; set; }
13 | public Tokens tokens { get; set; }
14 | public string customer_id { get; set; }
15 | }
16 |
17 | public class Extensions {
18 | public Device_Info device_info { get; set; }
19 | public Customer_Info customer_info { get; set; }
20 | }
21 |
22 | public class Device_Info {
23 | public string device_name { get; set; }
24 | public string device_serial_number { get; set; }
25 | public string device_type { get; set; }
26 | }
27 |
28 | public class Customer_Info {
29 | public string account_pool { get; set; }
30 | public string user_id { get; set; }
31 | public string home_region { get; set; }
32 | public string name { get; set; }
33 | public string given_name { get; set; }
34 | }
35 |
36 | public class Tokens {
37 | public Website_Cookies[] website_cookies { get; set; }
38 | public Store_Authentication_Cookie store_authentication_cookie { get; set; }
39 | public Mac_Dms mac_dms { get; set; }
40 | public Bearer bearer { get; set; }
41 | }
42 |
43 | public class Store_Authentication_Cookie {
44 | public string cookie { get; set; }
45 | }
46 |
47 | public class Mac_Dms {
48 | public string device_private_key { get; set; }
49 | public string adp_token { get; set; }
50 | }
51 |
52 | public class Bearer {
53 | public string access_token { get; set; }
54 | public string refresh_token { get; set; }
55 | public string expires_in { get; set; }
56 | }
57 |
58 | public class Website_Cookies {
59 | public string Path { get; set; }
60 | public string Secure { get; set; }
61 | public string Value { get; set; }
62 | public string Expires { get; set; }
63 | public string Domain { get; set; }
64 | public string HttpOnly { get; set; }
65 | public string Name { get; set; }
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/Audible.json.core/Serialization.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text.Json;
3 | using core.audiamus.aux;
4 | using core.audiamus.aux.ex;
5 |
6 | namespace core.audiamus.adb.json {
7 | public abstract class Serialization {
8 | private static JsonSerializerOptions Options { get; } = JsonExtensions.Options;
9 |
10 | public string Serialize () {
11 | return JsonSerializer.Serialize (this, typeof(T), Options);
12 | }
13 |
14 | public static T Deserialize (string json) {
15 | try {
16 | return JsonSerializer.Deserialize (json, Options);
17 | } catch (Exception exc) {
18 | Logging.Log (1, typeof (Serialization), () => exc.Summary ());
19 | return default;
20 | }
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Audible.json.core/Voucher.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace core.audiamus.adb.json {
4 |
5 | public class Voucher : Serialization {
6 | public string key { get; set; }
7 | public string iv { get; set; }
8 | public Rule[] rules { get; set; }
9 | }
10 |
11 | public class Rule {
12 | public Parameter[] parameters { get; set; }
13 | public string name { get; set; }
14 | }
15 |
16 | public class Parameter {
17 | public DateTime expireDate { get; set; }
18 | public string type { get; set; }
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/AuxLib.core/ApplEnv.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Reflection;
4 | using System.Resources;
5 | using System.Runtime.InteropServices;
6 | using System.Text.RegularExpressions;
7 |
8 | namespace core.audiamus.aux {
9 | public static class ApplEnv {
10 |
11 | static readonly char[] INVALID_CHARS = Path.GetInvalidFileNameChars ();
12 |
13 | public static Version OSVersion { get; } = getOSVersion();
14 | public static bool Is64BitOperatingSystem => Environment.Is64BitOperatingSystem;
15 | public static bool Is64BitProcess => Environment.Is64BitProcess;
16 | public static int ProcessorCount => Environment.ProcessorCount;
17 |
18 | public static Assembly EntryAssembly { get; } = Assembly.GetEntryAssembly ();
19 | public static Assembly ExecutingAssembly { get; } = Assembly.GetExecutingAssembly ();
20 |
21 | public static Version AssemblyVersion { get; } = EntryAssembly.GetName ().Version;
22 | public static string AssemblyTitle { get; } =
23 | getAttribute ()?.Title ?? Path.GetFileNameWithoutExtension (ExecutingAssembly.Location);
24 | public static string AssemblyProduct { get; } = getAttribute ()?.Product;
25 | public static string AssemblyCopyright { get; } = getAttribute ()?.Copyright;
26 | public static string AssemblyCompany { get; } = getAttribute ()?.Company;
27 | public static string NeutralCultureName { get; } = getAttribute ()?.CultureName;
28 |
29 | public static string AssemblyGuid { get; } = getAttribute ()?.Value;
30 |
31 | public static string ApplName { get; } = EntryAssembly.GetName ().Name;
32 | public static string ApplDirectory { get; } = AppContext.BaseDirectory;
33 | public static string LocalDirectoryRoot { get; } = Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData);
34 | public static string LocalCompanyDirectory { get; } = Path.Combine (LocalDirectoryRoot, getCompanyFileName());
35 | public static string LocalApplDirectory { get; } = Path.Combine (LocalCompanyDirectory, ApplName);
36 | public static string SettingsDirectory { get; } = Path.Combine (LocalApplDirectory, "settings");
37 | public static string TempDirectory { get; } = Path.Combine (LocalApplDirectory, "tmp");
38 | public static string LogDirectory { get; } = Path.Combine (LocalApplDirectory, "log");
39 | public static string UserName { get; } = Environment.UserName;
40 | public static string UserDirectoryRoot { get; } = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile);
41 |
42 | private static T getAttribute () where T : Attribute {
43 | object[] attributes = EntryAssembly.GetCustomAttributes (typeof (T), false);
44 | if (attributes.Length == 0)
45 | return null;
46 | return attributes[0] as T;
47 | }
48 |
49 |
50 | private static string getCompanyFileName () {
51 | string company = AssemblyCompany;
52 | if (string.IsNullOrEmpty (company))
53 | company = "misc";
54 | if (company.IndexOfAny (INVALID_CHARS) >= 0)
55 | foreach (char c in INVALID_CHARS)
56 | company.Replace (c, ' ');
57 | company = company.Replace (' ', '_');
58 | return company;
59 | }
60 |
61 |
62 | private static Version getOSVersion () {
63 | const string REGEX = @"\s([0-9.]+)";
64 | string os = RuntimeInformation.OSDescription;
65 | var regex = new Regex (REGEX);
66 | var match = regex.Match (os);
67 | if (!match.Success)
68 | return new Version ();
69 | string osvers = match.Groups[1].Value;
70 | try {
71 | return new Version (osvers);
72 | } catch (Exception) {
73 | return new Version ();
74 | }
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/AuxLib.core/AuxLib.core.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | core.audiamus.aux
6 | audiamus.aux.core
7 | audiamus
8 | 2.2.0.0
9 | 2.2.0.0
10 | Copyright © 2019 - $([System.DateTime]::UtcNow.Year) audiamus ($([System.DateTime]::UtcNow.ToString("s")))
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/AuxLib.core/BigEndianReader.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace core.audiamus.aux.ex {
5 | public static class BigEndianReader {
6 | // Note this MODIFIES THE GIVEN ARRAY then returns a reference to the modified array.
7 | public static byte[] Reverse (this byte[] b) {
8 | Array.Reverse (b);
9 | return b;
10 | }
11 |
12 | public static UInt16 ReadUInt16BE (this BinaryReader binRdr) {
13 | return BitConverter.ToUInt16 (binRdr.ReadBytesRequired (sizeof (UInt16)).Reverse (), 0);
14 | }
15 |
16 | public static Int16 ReadInt16BE (this BinaryReader binRdr) {
17 | return BitConverter.ToInt16 (binRdr.ReadBytesRequired (sizeof (Int16)).Reverse (), 0);
18 | }
19 |
20 | public static UInt32 ReadUInt32BE (this BinaryReader binRdr) {
21 | return BitConverter.ToUInt32 (binRdr.ReadBytesRequired (sizeof (UInt32)).Reverse (), 0);
22 | }
23 |
24 | public static Int32 ReadInt32BE (this BinaryReader binRdr) {
25 | return BitConverter.ToInt32 (binRdr.ReadBytesRequired (sizeof (Int32)).Reverse (), 0);
26 | }
27 |
28 | public static UInt64 ReadUInt64BE (this BinaryReader binRdr) {
29 | return BitConverter.ToUInt64 (binRdr.ReadBytesRequired (sizeof (UInt64)).Reverse (), 0);
30 | }
31 |
32 | public static Int64 ReadInt64BE (this BinaryReader binRdr) {
33 | return BitConverter.ToInt64 (binRdr.ReadBytesRequired (sizeof (Int64)).Reverse (), 0);
34 | }
35 |
36 | public static byte[] ReadBytesRequired (this BinaryReader binRdr, int byteCount) {
37 | var result = binRdr.ReadBytes (byteCount);
38 |
39 | if (result.Length != byteCount)
40 | throw new EndOfStreamException (string.Format ("{0} bytes required from stream, but only {1} returned.", byteCount, result.Length));
41 |
42 | return result;
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/AuxLib.core/BooleanYesNoConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Diagnostics;
5 | using System.Globalization;
6 | using System.Resources;
7 | using core.audiamus.aux.ex;
8 |
9 | namespace core.audiamus.aux {
10 | public class BooleanYesNoConverter : BooleanConverter {
11 |
12 | const string TRUE = "Yes";
13 | const string FALSE = "No";
14 |
15 | private ResourceManager _resourceManager;
16 |
17 | protected ResourceManager ResourceManager {
18 | get => _resourceManager;
19 | set
20 | {
21 | _resourceManager = value;
22 | initReverseLookup ();
23 | }
24 | }
25 |
26 | Dictionary _reverseLookup;
27 |
28 | public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType) {
29 | if (destinationType != typeof (string))
30 | return base.CanConvertTo (context, destinationType);
31 | else
32 | return true;
33 | }
34 |
35 |
36 | public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
37 | #if TRACE && EXTRA
38 | Log.WriteLine ($"{nameof (ConvertTo)}: \"{value}\", from: {value.GetType ().Name}, to: {destinationType.Name}");
39 | #endif
40 | switch (value) {
41 | default:
42 | return base.ConvertTo (context, culture, value, destinationType);
43 | case bool val:
44 | return toDisplayString (val);
45 | }
46 | }
47 |
48 | public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value) {
49 | #if TRACE && EXTRA
50 | Log.WriteLine ($"{nameof (ConvertFrom)}: \"{value}\", from: {value.GetType ().Name}");
51 | #endif
52 | if (!(_reverseLookup is null)) {
53 | if (value is string s) {
54 | bool succ = _reverseLookup.TryGetValue (s, out bool b);
55 | if (succ)
56 | return b;
57 | }
58 | }
59 | return base.ConvertFrom (context, culture, value);
60 |
61 | }
62 |
63 | private string toDisplayString (bool value) {
64 | string s = value ? TRUE : FALSE;
65 | return ResourceManager.GetStringEx (s);
66 | }
67 |
68 | private void initReverseLookup () {
69 | _reverseLookup = new Dictionary ();
70 | initReverseLookup (false);
71 | initReverseLookup (true);
72 | }
73 |
74 | private void initReverseLookup (bool value) => _reverseLookup.Add (toDisplayString (value), value);
75 |
76 | }
77 |
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/AuxLib.core/ChainPunctuation.cs:
--------------------------------------------------------------------------------
1 | namespace core.audiamus.aux {
2 | public interface IChainPunctuation {
3 | string Prefix { get; }
4 | string Suffix { get; }
5 | string[] Infix { get; }
6 | //string[] Punctuation { get; }
7 | }
8 |
9 | public abstract class ChainPunctuation : IChainPunctuation {
10 | public abstract string Prefix { get; }
11 | public abstract string Suffix { get; }
12 | public abstract string[] Infix { get; }
13 | //public string[] Punctuation => new string[] { Prefix, Suffix, Infix };
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/AuxLib.core/EnumConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Diagnostics;
5 | using System.Globalization;
6 | using System.Linq;
7 | using System.Resources;
8 | using core.audiamus.aux.ex;
9 | using static core.audiamus.aux.EnumUtil;
10 |
11 | namespace core.audiamus.aux {
12 |
13 | public class EnumConverter : TypeConverter
14 | where TEnum : struct, Enum
15 | {
16 |
17 | protected IList Values { get; }
18 |
19 | private ResourceManager _resourceManager;
20 |
21 | protected ResourceManager ResourceManager {
22 | get => _resourceManager;
23 | set
24 | {
25 | _resourceManager = value;
26 | initReverseLookup ();
27 | }
28 | }
29 |
30 | Dictionary _reverseLookup;
31 |
32 | public EnumConverter () {
33 | Values = GetValues ().ToArray ();
34 | }
35 |
36 | public override bool GetStandardValuesSupported (ITypeDescriptorContext context) => true;
37 |
38 | public override StandardValuesCollection GetStandardValues (ITypeDescriptorContext context) {
39 | StandardValuesCollection svc = new StandardValuesCollection (Values.ToArray());
40 | return svc;
41 | }
42 |
43 |
44 | public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType) {
45 | if (destinationType != typeof (string))
46 | return base.CanConvertTo (context, destinationType);
47 | else
48 | return true;
49 | }
50 |
51 | public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType) {
52 | if (sourceType != typeof (string))
53 | return base.CanConvertFrom (context, sourceType);
54 | else
55 | return true;
56 | }
57 |
58 |
59 | public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
60 | #if TRACE && EXTRA
61 | Trace.WriteLine ($"{nameof (ConvertTo)}: \"{value}\", from: {value.GetType ().Name}, to: {destinationType.Name}");
62 | #endif
63 | switch (value) {
64 | default:
65 | return base.ConvertTo (context, culture, value, destinationType);
66 | case TEnum enm:
67 | return toDisplayString (enm);
68 | }
69 | }
70 |
71 | public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value) {
72 | #if TRACE && EXTRA
73 | Trace.WriteLine ($"{nameof (ConvertFrom)}: \"{value}\", from: {value.GetType ().Name}");
74 | #endif
75 | if (!(_reverseLookup is null)) {
76 | if (value is string s) {
77 | bool succ = _reverseLookup.TryGetValue (s, out TEnum e);
78 | if (succ)
79 | return e;
80 | }
81 | }
82 | return base.ConvertFrom (context, culture, value);
83 |
84 | }
85 |
86 | private string toDisplayString (TEnum value) => ResourceManager.GetStringEx (value.ToString ());
87 |
88 | private void initReverseLookup () {
89 | _reverseLookup = new Dictionary ();
90 | foreach (var v in Values)
91 | _reverseLookup.Add (toDisplayString (v), v);
92 | }
93 |
94 | }
95 |
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/src/AuxLib.core/EnumUtil.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Resources;
5 | using System.Text;
6 | using core.audiamus.aux.ex;
7 |
8 | namespace core.audiamus.aux {
9 | public static class EnumUtil {
10 | // Note: constraint System.Enum available in C# 7.3
11 | public static IEnumerable GetValues () where T : struct, Enum {
12 | var values = Enum.GetValues (typeof (T));
13 | return values.Cast ().ToList ();
14 | }
15 |
16 | // Note: constraint System.Enum available in C# 7.3
17 | public static string[] GetStringValues () where T : struct, Enum {
18 | var values = GetValues ();
19 | return values.Select (v => $"<{v}>").ToArray ();
20 | }
21 |
22 | const char USCORE = '_';
23 | static readonly byte __a = Convert.ToByte ('a');
24 |
25 | public static string ToDisplayString (this TEnum value, ResourceManager rm)
26 | where TEnum: struct, Enum
27 | where TPunct : class, IChainPunctuation, new()
28 | {
29 |
30 |
31 | var punct = Singleton.Instance;
32 |
33 | string sval = value.ToString ();
34 |
35 | //verbatim ?
36 | if (sval.StartsWith ("_")) {
37 | return rm.GetStringEx (sval.Substring (1));
38 | }
39 |
40 | string[] parts = sval.Split (USCORE);
41 |
42 | bool noSubstitutes = parts.Select (s => s.Length).Min () > 1;
43 | StringBuilder sb = new StringBuilder ();
44 | if (noSubstitutes) {
45 | for (int i = 0; i < parts.Length; i++)
46 | parts[i] = punct.Prefix + rm.GetStringEx (parts[i]) + punct.Suffix;
47 | foreach (string s in parts) {
48 | if (sb.Length > 0)
49 | sb.Append (punct.Infix?[0]);
50 | sb.Append (s);
51 | }
52 | } else {
53 | for (int i = 0; i < parts.Length; i++) {
54 | if (parts[i].Length > 1)
55 | parts[i] = punct.Prefix + rm.GetStringEx (parts[i]) + punct.Suffix;
56 | else {
57 | byte x = Convert.ToByte (parts[i][0]);
58 | try {
59 | parts[i] = punct.Infix?[x - __a];
60 | } catch (IndexOutOfRangeException) {
61 | parts[i] = string.Empty;
62 | }
63 | }
64 | }
65 | foreach (string s in parts)
66 | sb.Append (s);
67 | }
68 | return sb.ToString ();
69 | }
70 |
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/AuxLib.core/IInteractionCallback.cs:
--------------------------------------------------------------------------------
1 | namespace core.audiamus.aux {
2 | public interface IInteractionCallback {
3 | TResult Interact (T value);
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/src/AuxLib.core/Indent.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace core.audiamus.aux {
4 | ///
5 | /// Automatic indentation, managed as a resource
6 | ///
7 | public class Indent : IResource {
8 |
9 | uint _inc = 2;
10 | uint _offset = 0;
11 | int _indent;
12 | string _output = string.Empty;
13 |
14 | public int Level { get; private set; }
15 |
16 | public Indent () { }
17 | public Indent (uint inc) => this._inc = inc;
18 | public Indent (uint? inc, uint offset) {
19 | this._inc = inc ?? this._inc;
20 | this._offset = offset;
21 | buildString ();
22 | }
23 |
24 | public void Acquire () {
25 | Level++;
26 | _indent += (int)_inc;
27 | buildString ();
28 | }
29 |
30 | public void Release () {
31 | Level--;
32 | _indent -= (int)_inc;
33 | buildString ();
34 | }
35 |
36 | public bool InRange (int level) {
37 | if (level < 0)
38 | return true;
39 | else
40 | return Level <= level;
41 | }
42 |
43 | public override string ToString () => _output;
44 |
45 | public void Write (TextWriter osm) => osm.Write (this);
46 |
47 | private void buildString () => _output = new string (' ', (int)_offset + _indent);
48 |
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/AuxLib.core/InteractionCallback.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics.Contracts;
3 | using System.Threading;
4 |
5 | namespace core.audiamus.aux {
6 |
7 |
8 | ///
9 | /// Provides an IInteractCallback{T, TResult} that invokes callbacks for interaction on the captured SynchronizationContext.
10 | ///
11 | public class InteractionCallback : IInteractionCallback {
12 | private readonly SynchronizationContext _synchronizationContext;
13 | private readonly Func _handler;
14 |
15 | private static readonly SynchronizationContext DefaultContext = new SynchronizationContext ();
16 |
17 | public InteractionCallback (Func handler) {
18 | _synchronizationContext = SynchronizationContext.Current ?? DefaultContext;
19 | Contract.Assert (_synchronizationContext != null);
20 | if (handler is null)
21 | throw new ArgumentNullException (nameof(handler));
22 | _handler = handler;
23 | }
24 |
25 |
26 | protected virtual TResult onInteract (T value) {
27 | // If there's no handler, don't bother going through the sync context.
28 | TResult retval = default (TResult);
29 | if (_handler != null) {
30 | // Post the processing to the sync context.
31 | // (If T is a value type, it will get boxed here.)
32 | _synchronizationContext.Send (new SendOrPostCallback ((x) =>
33 | {
34 | retval = _handler (value);
35 | })
36 | , null);
37 |
38 | }
39 | return retval;
40 | }
41 |
42 | TResult IInteractionCallback.Interact(T value) => onInteract (value);
43 |
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/AuxLib.core/InteractionMessage.cs:
--------------------------------------------------------------------------------
1 | namespace core.audiamus.aux {
2 | public enum ECallbackType { info, infoCancel, warning, error, errorQuestion, errorQuestion3, question, question3 }
3 |
4 | public record InteractionMessage (
5 | ECallbackType Type,
6 | string Message
7 | );
8 |
9 | public record InteractionMessage (ECallbackType Type, string Message, T Custom) :
10 | InteractionMessage (Type, Message);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/AuxLib.core/Interfaces.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics;
2 |
3 | namespace core.audiamus.aux {
4 | public interface IProcessList {
5 | bool Add (Process process);
6 | bool Remove (Process process);
7 | }
8 |
9 | public interface IUserSettings {
10 | }
11 |
12 | public interface IInitSettings {
13 | void Init ();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/AuxLib.core/JsonSerialization.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using System.Text.Encodings.Web;
3 | using System.Text.Json;
4 | using System.Text.Json.Serialization;
5 | using System.Threading.Tasks;
6 |
7 | namespace core.audiamus.aux {
8 | public static class JsonSerialization {
9 | private static readonly JsonSerializerOptions __jsonSerializerOptions = new JsonSerializerOptions {
10 | WriteIndented = true,
11 | ReadCommentHandling = JsonCommentHandling.Skip,
12 | AllowTrailingCommas = true,
13 | Converters ={
14 | new JsonStringEnumConverter()
15 | },
16 | Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
17 | };
18 |
19 | public static string ToJsonString (this T obj) {
20 | return JsonSerializer.Serialize (obj, __jsonSerializerOptions);
21 | }
22 |
23 | public static void ToJsonFile (this T obj, string path) {
24 | using var fs = new FileStream (path, FileMode.Create);
25 | var task = Task.Run (async () => await JsonSerializer.SerializeAsync (fs, obj, __jsonSerializerOptions));
26 | task.Wait ();
27 | }
28 |
29 | public static T FromJsonString (this string json) {
30 | return JsonSerializer.Deserialize (json, __jsonSerializerOptions);
31 | }
32 |
33 | public static T FromJsonFile (this string path) {
34 | using var fs = new FileStream (path, FileMode.Open, FileAccess.Read);
35 | Task task = Task.Run (async () => await JsonSerializer.DeserializeAsync (fs, __jsonSerializerOptions));
36 | return task.Result;
37 | }
38 |
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/AuxLib.core/LogGuard.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 |
4 | namespace core.audiamus.aux {
5 |
6 | public class LogGuard : IDisposable {
7 |
8 | const string IN = ">>> ";
9 | const string OUT = "<<< ";
10 | readonly uint _level;
11 | readonly Func _func;
12 | readonly string _msg;
13 | readonly string _method;
14 | readonly object _caller;
15 | readonly Type _type;
16 | bool _isDispose;
17 |
18 | public LogGuard (uint level, Type type, Func func, [CallerMemberName] string method = null) {
19 | _level = level;
20 | _type = type;
21 | _func = func;
22 | _method = method;
23 | Logging.Log (level, type, getFuncMsg, method);
24 | }
25 |
26 | public LogGuard (uint level, object caller, Func func, [CallerMemberName] string method = null) {
27 | _level = level;
28 | _caller = caller;
29 | _func = func;
30 | _method = method;
31 | Logging.Log (level, caller, getFuncMsg, method);
32 | }
33 |
34 | public LogGuard (uint level, Type type, string msg, [CallerMemberName] string method = null) {
35 | _level = level;
36 | _type = type;
37 | _msg = msg;
38 | _method = method;
39 | Logging.Log (level, type, getMsg, method);
40 | }
41 |
42 | public LogGuard (uint level, object caller, string msg, [CallerMemberName] string method = null) {
43 | _level = level;
44 | _caller = caller;
45 | _msg = msg;
46 | _method = method;
47 | Logging.Log (level, caller, getMsg (), method);
48 | }
49 |
50 | public LogGuard (uint level, Type type, [CallerMemberName] string method = null) {
51 | _level = level;
52 | _type = type;
53 | _method = method;
54 | Logging.Log (level, type, () => IN, method);
55 | }
56 |
57 | public LogGuard (uint level, object caller, [CallerMemberName] string method = null) {
58 | _level = level;
59 | _caller = caller;
60 | _method = method;
61 | Logging.Log (level, caller, () => IN, method);
62 | }
63 |
64 | public void Dispose () {
65 | _isDispose = true;
66 | if (_type is null) {
67 | if (_func is null) {
68 | if (_msg is null)
69 | Logging.Log (_level, _caller, () => OUT, _method);
70 | else
71 | Logging.Log (_level, _caller, getMsg (), _method);
72 | } else
73 | Logging.Log (_level, _caller, getFuncMsg, _method);
74 | } else if (_type is not null) {
75 | if (_func is null) {
76 | if (_msg is null)
77 | Logging.Log (_level, _type, () => OUT, _method);
78 | else
79 | Logging.Log (_level, _type, getMsg (), _method);
80 | } else
81 | Logging.Log (_level, _type, getFuncMsg, _method);
82 | }
83 | }
84 |
85 | private string getFuncMsg () {
86 | string prefix = _isDispose ? OUT : IN;
87 | return prefix + _func?.Invoke ();
88 | }
89 |
90 | private string getMsg () {
91 | string prefix = _isDispose ? OUT : IN;
92 | return prefix + _msg;
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/AuxLib.core/ProcessHost.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.IO;
4 | using System.Text;
5 |
6 | namespace core.audiamus.aux {
7 | public class ProcessHost {
8 |
9 | protected Process Process { get; private set; }
10 |
11 | ///
12 | /// Executes a process and passes its command-line output back after the process has exited
13 | ///
14 | protected string runProcess (
15 | string exePath, string parameters,
16 | bool getStdErrorNotOutput = false,
17 | DataReceivedEventHandler eventHandler = null)
18 | {
19 |
20 | if (!File.Exists (exePath))
21 | return null;
22 |
23 | string result = String.Empty;
24 | bool async = eventHandler != null;
25 |
26 | using (Process p = new Process ()) {
27 | p.StartInfo.UseShellExecute = false;
28 | p.StartInfo.CreateNoWindow = true;
29 | p.StartInfo.FileName = exePath;
30 | p.StartInfo.Arguments = parameters;
31 |
32 | if (getStdErrorNotOutput)
33 | p.StartInfo.RedirectStandardError = true;
34 | else
35 | p.StartInfo.RedirectStandardOutput = true;
36 | p.StartInfo.RedirectStandardInput = true;
37 |
38 | if (async) {
39 | if (getStdErrorNotOutput)
40 | p.ErrorDataReceived += eventHandler;
41 | else
42 | p.OutputDataReceived += eventHandler;
43 | }
44 |
45 | var processOutputStringBuilder = new StringBuilder ();
46 |
47 | p.Start ();
48 | try {
49 | p.PriorityClass = ProcessPriorityClass.BelowNormal;
50 | } catch (Exception) {
51 | }
52 |
53 | Singleton.Instance.Add (p);
54 | Process = p;
55 |
56 | if (async) {
57 | if (getStdErrorNotOutput)
58 | p.BeginErrorReadLine ();
59 | else
60 | p.BeginOutputReadLine ();
61 | }
62 | p.WaitForExit ();
63 |
64 | Singleton.Instance.Remove (p);
65 | Process = null;
66 |
67 | if (!async) {
68 | if (getStdErrorNotOutput)
69 | result = p.StandardError.ReadToEnd ();
70 | else
71 | result = p.StandardOutput.ReadToEnd ();
72 | } else {
73 | if (processOutputStringBuilder.Length > 0)
74 | result = processOutputStringBuilder.ToString ();
75 | }
76 |
77 | }
78 |
79 | return result;
80 | }
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/src/AuxLib.core/ProcessList.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 |
5 | namespace core.audiamus.aux {
6 | public class ProcessList : IDisposable, IProcessList {
7 |
8 | private readonly object _lockable = new object ();
9 | private bool _disposed = false;
10 |
11 | HashSet _processes = new HashSet ();
12 |
13 | public IProcessList Notify { private get; set; }
14 |
15 | public bool Add (Process process) {
16 | Notify?.Add (process);
17 | lock (_lockable)
18 | return _processes.Add (process);
19 | }
20 |
21 | public bool Remove (Process process) {
22 | Notify?.Remove (process);
23 | lock (_lockable)
24 | return _processes.Remove (process);
25 | }
26 |
27 | #region IDisposable Members
28 |
29 | public void Dispose () {
30 | Dispose (true);
31 | GC.SuppressFinalize (this);
32 | }
33 |
34 | #endregion
35 | private void Dispose (bool disposing) {
36 | if (_disposed)
37 | return;
38 |
39 | if (disposing) {
40 | }
41 |
42 | lock (_lockable)
43 | foreach (Process p in _processes)
44 | p.Kill ();
45 |
46 | _disposed = true;
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/AuxLib.core/ResourceGuard.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace core.audiamus.aux {
4 | ///
5 | /// Implementing and using it with allows
6 | /// RAII behavior within the lifecycle of an instance, beyond ctor/dtor, e.g. for indentation of text.
7 | ///
8 | public interface IResource {
9 | void Acquire ();
10 | void Release ();
11 | }
12 |
13 | ///
14 | /// The "using" statement in C# is syntactic sugar for try {} finally {} and implements the RAII programming idiom.
15 | /// In conjunction with and optionally it can be used
16 | /// for all sorts of dedicated and guaranteed scope entry/exit action.
17 | ///
18 | /// Examples:
19 | ///
20 | /// var resource = new NonIDisposableResource();
21 | /// using (new ResourceGuard(() => resource.Close()) {
22 | /// /* ... */
23 | /// }
24 | ///
25 | ///
26 | /// bool flag = false;
27 | /// using (new ResourceGuard(x => flag = x)) {
28 | /// /* ... */
29 | /// }
30 | ///
31 | ///
32 | /// var stopwatch = Stopwatch.StartNew();
33 | /// /* pausing(!) stopwatch */
34 | /// using (new ResourceGuard(x => {
35 | /// if (x) stopwatch.Stop(); else stopwatch.Start();
36 | /// })) {
37 | /// /* ... */
38 | /// }
39 | ///
40 | ///
41 | /// class Indent : IResource { /*...*/ }
42 | /// Indent ind = new Indent ();
43 | /// using (new ResourceGuard(ind)) {
44 | /// /* ... */
45 | /// }
46 | ///
47 | ///
48 | public class ResourceGuard : IDisposable {
49 | readonly Action _onDispose;
50 | readonly Action _onNewAndDispose;
51 | readonly IResource _resource;
52 |
53 | public ResourceGuard (IResource resource) {
54 | _resource = resource;
55 | _resource.Acquire ();
56 | }
57 |
58 | public ResourceGuard (Action onDispose) {
59 | _onDispose = onDispose;
60 | }
61 |
62 | public ResourceGuard (Action onNewAndDispose) {
63 | _onNewAndDispose = onNewAndDispose;
64 | _onNewAndDispose?.Invoke (true);
65 | }
66 |
67 | public void Dispose () {
68 | _onDispose?.Invoke ();
69 | _onNewAndDispose?.Invoke (false);
70 | _resource?.Release ();
71 | }
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/src/AuxLib.core/ResourceManagerEx.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Resources;
3 |
4 | namespace core.audiamus.aux.ex {
5 | public static class ResourceManagerEx {
6 |
7 | public static ResourceManager GetDefaultResourceManager (this object o) {
8 | return o.GetType().GetDefaultResourceManager ();
9 | }
10 |
11 | public static ResourceManager GetDefaultResourceManager (this Type type) {
12 | string tableName = type.Namespace + ".Properties.Resources";
13 | var assembly = type.Assembly;
14 | var rm = new ResourceManager (tableName, assembly);
15 | return rm;
16 | }
17 |
18 | public static ResourceManager GetTypeResourceManager (this object o) {
19 | return o.GetType().GetTypeResourceManager();
20 | }
21 |
22 | public static ResourceManager GetTypeResourceManager (this Type type) {
23 | string tableName = type.FullName;
24 | var assembly = type.Assembly;
25 | var rm = new ResourceManager (tableName, assembly);
26 | return rm;
27 | }
28 |
29 | public static string GetStringEx (this ResourceManager rm, string val) {
30 | if (rm is null)
31 | return val;
32 | string s = null;
33 | try {
34 | s = rm.GetString (val.ToLowerInvariant());
35 | } catch (MissingManifestResourceException) {
36 | }
37 | return s ?? val;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/AuxLib.core/ShellExecute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 |
4 | namespace core.audiamus.aux {
5 | public static class ShellExecute {
6 | public static void Url (Uri uri) => File (uri.OriginalString);
7 |
8 | public static void File (string url) {
9 | Process.Start (new ProcessStartInfo () {
10 | UseShellExecute = true,
11 | CreateNoWindow = true,
12 | FileName = url,
13 | });
14 |
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/AuxLib.core/Singleton.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace core.audiamus.aux {
4 | ///
5 | /// Implementation of the "Singleton" pattern.
6 | ///
7 | /// Type of class to be instantiated as a singleton.
8 | public class Singleton where T : class, new() {
9 | private static T __t;
10 | private static readonly object __lockable;
11 |
12 | ///
13 | /// Static ctor. Initializes the class, but does not yet create the instance.
14 | ///
15 | static Singleton () {
16 | __lockable = new object ();
17 | }
18 |
19 | ///
20 | /// Get the instance of the singleton.
21 | /// C#-style implementation as a property.
22 | ///
23 | ///
24 | /// Instance of singleton.
25 | ///
26 | public static T Instance {
27 | get {
28 | lock (__lockable) {
29 | if (__t is null)
30 | __t = new T ();
31 |
32 | return __t;
33 | }
34 | }
35 | }
36 |
37 | public static void Dispose () {
38 | lock (__lockable) {
39 | if (__t is IDisposable obj)
40 | obj.Dispose ();
41 | __t = null;
42 | }
43 | }
44 |
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/AuxLib.core/Temp.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 |
4 | namespace core.audiamus.aux {
5 | public static class Temp {
6 | public static string GetPseudoUniqueString () {
7 | long ticks = DateTime.UtcNow.Ticks;
8 | int thrdid = Thread.CurrentThread.ManagedThreadId;
9 | return $"{thrdid}_{ticks}";
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/AuxLib.core/TimeUtil.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace core.audiamus.aux {
4 | public static class TimeUtil {
5 | private readonly static DateTime EPOCH = new(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
6 |
7 | private static double dateTimeToDouble (DateTime dt) {
8 | if (dt == default)
9 | return 0;
10 |
11 | TimeSpan ts = dt.Subtract (EPOCH);
12 | return ts.TotalSeconds;
13 | }
14 |
15 | public static int DateTimeToUnix32 (DateTime dt) => (int)dateTimeToDouble (dt);
16 |
17 | public static long DateTimeToUnix64 (DateTime dt) => (long)dateTimeToDouble (dt);
18 |
19 | public static long DateTimeToUnix64Msec (DateTime dt) {
20 | if (dt == default)
21 | return 0;
22 |
23 | TimeSpan ts = dt.Subtract (EPOCH);
24 | return (long)ts.TotalMilliseconds;
25 | }
26 |
27 | public static DateTime UnixToDateTime (long timestamp) {
28 | if (timestamp == 0)
29 | return default;
30 |
31 | DateTime dt = EPOCH.AddSeconds (timestamp);
32 | return dt;
33 | }
34 |
35 | public static DateTime UnixMsecToDateTime (long timestampMsec) {
36 | if (timestampMsec == 0)
37 | return default;
38 |
39 | DateTime dt = EPOCH.AddMilliseconds (timestampMsec);
40 | return dt;
41 | }
42 |
43 | public static int ToUnix32 (this DateTime dt) => DateTimeToUnix32 (dt);
44 |
45 | public static long ToUnix64 (this DateTime dt) => DateTimeToUnix64 (dt);
46 |
47 | public static long ToUnix64Msec (this DateTime dt) => DateTimeToUnix64Msec (dt);
48 |
49 | /// Replace time kind without changing value.
50 | /// The DateTime value to be reinterpreted.
51 | /// The new DateTime kind.
52 | /// Reinterpreted DateTime value.
53 | public static DateTime As (this DateTime dt, DateTimeKind kind) => new(dt.Ticks, kind);
54 |
55 | public static DateTime ToDateTimeFromUnix (this int timval) => UnixToDateTime (timval);
56 |
57 | public static DateTime ToDateTimeFromUnix (this long timval) => UnixToDateTime (timval);
58 |
59 | public static DateTime ToDateTimeFromUnixMsec (this long timvalMsec) => UnixMsecToDateTime (timvalMsec);
60 |
61 | }
62 | }
63 |
64 |
--------------------------------------------------------------------------------
/src/AuxWin.DialogBox.core/AuxWin.DialogBox.core.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0-windows
5 | true
6 | core.audiamus.aux.win
7 | audiamus.aux.win.dialogbox.core
8 | audiamus
9 | 2.1.0.0
10 | 2.1.0.0
11 | Copyright © 2019 - $([System.DateTime]::UtcNow.Year) audiamus ($([System.DateTime]::UtcNow.ToString("s")))
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/AuxWin.DialogBox.core/Win32API.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | // COPYRIGHT: Prosoft-Lanz
3 | //=============================================================================
4 | //
5 | // $Workfile: Win32API.cs $
6 | //
7 | // PROJECT : CodeProject Components
8 | // VERSION : 1.00
9 | // CREATION : 19.02.2003
10 | // AUTHOR : JCL
11 | //
12 | // DETAILS : This class implement Win32 API calls
13 | // and the contants used for these calls.
14 | //
15 | //-----------------------------------------------------------------------------
16 | using System;
17 | using System.Text;
18 | using System.Drawing;
19 | using System.Windows.Forms;
20 | using System.Runtime.InteropServices;
21 |
22 | namespace core.audiamus.aux.win.Win32API
23 | {
24 | ///////////////////////////////////////////////////////////////////////
25 | #region Generic declarations
26 |
27 | ///
28 | /// Rectangle parameters exposed as a structure.
29 | ///
30 | public struct RECT
31 | {
32 | ///
33 | /// Rectangle members.
34 | ///
35 | public int left, top, right, bottom;
36 | }
37 |
38 | #endregion
39 |
40 | ///////////////////////////////////////////////////////////////////////
41 | #region Util class
42 |
43 | ///
44 | /// Utility functions.
45 | ///
46 | public sealed class API
47 | {
48 | private API() {} // To remove the constructor from the documentation!
49 |
50 | ///
51 | /// Get true multiscreen size.
52 | ///
53 | public static Rectangle TrueScreenRect
54 | {
55 | get
56 | {
57 | // get the biggest screen area
58 | Rectangle rectScreen = Screen.PrimaryScreen.WorkingArea;
59 | int left = rectScreen.Left;
60 | int top = rectScreen.Top;
61 | int right = rectScreen.Right;
62 | int bottom = rectScreen.Bottom;
63 | foreach (Screen screen in Screen.AllScreens)
64 | {
65 | left = Math.Min(left, screen.WorkingArea.Left);
66 | right = Math.Max(right, screen.WorkingArea.Right);
67 | top = Math.Min(top, screen.WorkingArea.Top);
68 | bottom = Math.Max(bottom, screen.WorkingArea.Bottom);
69 | }
70 | return new Rectangle(left, top, right-left, bottom-top);
71 | }
72 | }
73 | }
74 |
75 | #endregion
76 |
77 | ///////////////////////////////////////////////////////////////////////
78 | #region USER32 class
79 |
80 | ///
81 | /// Class to expose USER32 API functions.
82 | ///
83 | public static class USER32
84 | {
85 | [DllImport ("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
86 | internal static extern int GetWindowRect(IntPtr hWnd, ref RECT rect);
87 |
88 | [DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
89 | internal static extern int MoveWindow(IntPtr hWnd, int x, int y, int w, int h, int repaint);
90 |
91 | [DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
92 | internal static extern IntPtr GetActiveWindow();
93 |
94 | [DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
95 | internal static extern int GetClassName(IntPtr hwnd, StringBuilder lpClassName, int nMaxCount);
96 | }
97 | #endregion
98 |
99 | #region USER32 class
100 |
101 | ///
102 | /// Class to expose KERNEL32 API functions.
103 | ///
104 | public static class KERNEL32 {
105 | [DllImport ("kernel32.dll")]
106 | internal static extern int GetCurrentThreadId ();
107 | }
108 | #endregion
109 | }
110 |
--------------------------------------------------------------------------------
/src/AuxWin.lib.core/AuxWin.lib.core.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0-windows
5 | true
6 | core.audiamus.aux.win
7 | audiamus.aux.win.core
8 | audiamus
9 | 2.2.0.0
10 | 2.2.0.0
11 | Copyright © 2019 - $([System.DateTime]::UtcNow.Year) audiamus ($([System.DateTime]::UtcNow.ToString("s")))
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | True
23 | True
24 | Resources.resx
25 |
26 |
27 |
28 |
29 |
30 | ResXFileCodeGenerator
31 | Resources.Designer.cs
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/src/AuxWin.lib.core/ExtensionsControl.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Drawing;
3 | using System.Windows.Forms;
4 |
5 | namespace core.audiamus.aux.win.ex {
6 | public static class ControlExtensions {
7 | public static Form GetParentForm (this Control control) {
8 | Control parent = control;
9 | while (!(parent is null || parent is Form))
10 | parent = parent.Parent;
11 |
12 | return parent as Form;
13 | }
14 |
15 | private static readonly Dictionary