├── Common
├── Controls
│ ├── BitmapViewer.cs
│ ├── BitmapViewerSideBySide.cs
│ ├── Breadcrumb.cs
│ ├── ComboBox.cs
│ ├── DownloadDialog.cs
│ ├── GitHubButton.cs
│ ├── HexDiffer.cs
│ ├── HexViewer.cs
│ ├── Hyperlink.cs
│ ├── ImageButton.cs
│ ├── ImageCheckButton.cs
│ ├── ImageRadioPanel.cs
│ ├── ListBox.cs
│ ├── MainDockPanel.cs
│ ├── SelectFolderDialog.cs
│ ├── StackPanel.cs
│ ├── TextBoxDialog.cs
│ ├── TextDiffer.cs
│ ├── TextDifferBackgroundRenderer.cs
│ ├── TextSearchBackgroundRenderer.cs
│ ├── TextSearchPanel.cs
│ ├── TextTabFoldingStrategy.cs
│ ├── TextViewer.cs
│ ├── TextViewerFolding.cs
│ ├── TreeView.cs
│ └── XmlViewer.cs
├── Extensions
│ ├── Octokit.cs
│ ├── Pfim.Dds.x.cs
│ ├── System.Array.x.cs
│ ├── System.Collections.Generic.IReadOnlyList.x.cs
│ ├── System.Collections.IList.x.cs
│ ├── System.DateTime.x.cs
│ ├── System.Delegate.x.cs
│ ├── System.IEnumerable.x.cs
│ ├── System.IO.Stream.x.cs
│ ├── System.Net.Http.HttpClient.x.cs
│ ├── System.Object.x.cs
│ ├── System.Reflection.FieldInfo.x.cs
│ ├── System.Span.x.cs
│ ├── System.String.x.cs
│ ├── System.String.x.p.CompareNumeric.cs
│ ├── System.Text.StringBuilder.x.cs
│ ├── System.Threading.Tasks.Task.x.cs
│ ├── System.Type.x.cs
│ ├── System.Version.x.cs
│ ├── System.WeakReference.cs
│ ├── System.Windows.Controls.ColumnDefinitionCollection.x.cs
│ ├── System.Windows.Controls.RowDefinitionCollection.x.cs
│ ├── System.Windows.DependencyObject.x.cs
│ └── System.Windows.Media.Imaging.BitmapSource.x.cs
├── NMS
│ ├── Game
│ │ ├── Game.Data.cs
│ │ ├── Game.Data.p.instances.cs
│ │ ├── Game.Files.Cache.cs
│ │ ├── Game.Files.ComboBox.cs
│ │ ├── Game.Files.View.cs
│ │ ├── Game.Items.GroupListBox.cs
│ │ ├── Game.Items.Products.cs
│ │ ├── Game.Items.Substances.cs
│ │ ├── Game.Items.Technologies.cs
│ │ ├── Game.Items.cs
│ │ ├── Game.Language.cs
│ │ ├── Game.Location.Buttons.cs
│ │ ├── Game.Location.Data.cs
│ │ ├── Game.Location.Dialog.cs
│ │ ├── Game.MODS.Files.cs
│ │ ├── Game.PCBANKS.Files.cs
│ │ ├── Game.Recipes.ListBox.cs
│ │ ├── Game.Recipes.cs
│ │ └── Game.Releases.cs
│ ├── MBINC
│ │ ├── MBINC.cs
│ │ ├── MBINC.p.EBIN.cs
│ │ ├── MBINC.p.cache.cs
│ │ └── MBINC.p.types.cs
│ └── PAK
│ │ ├── Data
│ │ ├── PAK.BIN.Data.cs
│ │ ├── PAK.BNK.Data.cs
│ │ ├── PAK.CS.Data.cs
│ │ ├── PAK.CSV.Data.cs
│ │ ├── PAK.DDS.Data.cs
│ │ ├── PAK.JSON.Data.cs
│ │ ├── PAK.LUA.Data.cs
│ │ ├── PAK.MBIN.Data.cs
│ │ ├── PAK.MBIN.Header.cs
│ │ ├── PAK.SPV.Data.cs
│ │ ├── PAK.TXT.Data.cs
│ │ ├── PAK.VDF.Data.cs
│ │ ├── PAK.WEM.Data.cs
│ │ └── PAK.XML.Data.cs
│ │ ├── Differ
│ │ ├── PAK.BIN.Differ.cs
│ │ ├── PAK.BNK.Differ.cs
│ │ ├── PAK.CS.Differ.cs
│ │ ├── PAK.CSV.Differ.cs
│ │ ├── PAK.DDS.Differ.cs
│ │ ├── PAK.Hex.Differ.cs
│ │ ├── PAK.JSON.Differ.cs
│ │ ├── PAK.LUA.Differ.cs
│ │ ├── PAK.MBIN.Differ.cs
│ │ ├── PAK.SPV.Differ.cs
│ │ ├── PAK.TXT.Differ.cs
│ │ ├── PAK.VDF.Differ.cs
│ │ ├── PAK.WEM.Differ.cs
│ │ └── PAK.XML.Differ.cs
│ │ ├── PAK.File.Loader.cs
│ │ ├── PAK.Files.cs
│ │ ├── PAK.Item.Data.cs
│ │ ├── PAK.Item.Info.cs
│ │ ├── PAK.Item.Interfaces.cs
│ │ ├── PAK.Item.Path.cs
│ │ ├── PAK.Item.View.cs
│ │ └── Viewer
│ │ ├── PAK.BIN.Viewer.cs
│ │ ├── PAK.BNK.Viewer.cs
│ │ ├── PAK.CS.Viewer.cs
│ │ ├── PAK.CSV.Viewer.cs
│ │ ├── PAK.DDS.Viewer.cs
│ │ ├── PAK.Hex.Viewer.cs
│ │ ├── PAK.JSON.Viewer.cs
│ │ ├── PAK.LUA.Viewer.cs
│ │ ├── PAK.MBIN.EbinColorBackgroundRenderer.cs
│ │ ├── PAK.MBIN.Viewer.cs
│ │ ├── PAK.SPV.Viewer.cs
│ │ ├── PAK.TXT.Viewer.cs
│ │ ├── PAK.VDF.Viewer.cs
│ │ ├── PAK.WEM.Viewer.cs
│ │ └── PAK.XML.Viewer.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ └── Resources.resx
├── Resources
│ ├── About.png
│ ├── Avalon_csx.xshd
│ ├── Avalon_ebin.xshd
│ ├── Avalon_exml.xshd
│ ├── BaseComputer.png
│ ├── BinocsMod.png
│ ├── Black.png
│ ├── Build.png
│ ├── CSharp.png
│ ├── CaseSensitive.png
│ ├── Center.png
│ ├── CheckAll.png
│ ├── Checker.png
│ ├── Chromatic.png
│ ├── Clear.png
│ ├── CollapseAll.png
│ ├── Compile.png
│ ├── Configure.png
│ ├── Copy.png
│ ├── Cube.png
│ ├── Diff.png
│ ├── Egg.png
│ ├── Error.png
│ ├── ExpandAll.png
│ ├── FSlash.png
│ ├── FileCreate.png
│ ├── FileDelete.png
│ ├── FindInFile.png
│ ├── First.png
│ ├── FlagBrazil.png
│ ├── FlagCanada.png
│ ├── FlagChina.png
│ ├── FlagFrance.png
│ ├── FlagGermany.png
│ ├── FlagItaly.png
│ ├── FlagJapan.png
│ ├── FlagMexico.png
│ ├── FlagNetherlands.png
│ ├── FlagPoland.png
│ ├── FlagPortugal.png
│ ├── FlagRussia.png
│ ├── FlagSouthKorea.png
│ ├── FlagSpain.png
│ ├── FlagUSA.png
│ ├── Folder.png
│ ├── GOG.png
│ ├── GamePass.png
│ ├── GitHub.png
│ ├── Gray.png
│ ├── Grouping.png
│ ├── Image.png
│ ├── Last.png
│ ├── Launch.png
│ ├── MergeTabs.png
│ ├── Mirror.png
│ ├── NMS.ico
│ ├── NMS.png
│ ├── Next.png
│ ├── PakItemBin.png
│ ├── PakItemBnk.png
│ ├── PakItemCs.png
│ ├── PakItemCsv.png
│ ├── PakItemDds.png
│ ├── PakItemEbin.png
│ ├── PakItemExml.png
│ ├── PakItemHex.png
│ ├── PakItemJson.png
│ ├── PakItemLua.png
│ ├── PakItemSpv.png
│ ├── PakItemTxt.png
│ ├── PakItemWem.png
│ ├── PakItemXml.png
│ ├── Paste.png
│ ├── Prev.png
│ ├── RecipesFood.png
│ ├── RecipesRefiner.png
│ ├── Redo.png
│ ├── Regex.png
│ ├── Rename.png
│ ├── Run.png
│ ├── Save.png
│ ├── ScriptMod.png
│ ├── ScriptPlugin.png
│ ├── ScriptQuery.png
│ ├── ScriptUtil.png
│ ├── Search.png
│ ├── Settings.png
│ ├── Smiley_Green.png
│ ├── Smiley_Red.png
│ ├── Smiley_Yellow.png
│ ├── SplitTabs.png
│ ├── Steam.png
│ ├── Stop.png
│ ├── Stretch.png
│ ├── Text.png
│ ├── Tile.png
│ ├── TypeArray.png
│ ├── TypeEvent.png
│ ├── TypeField.png
│ ├── TypeProp.png
│ ├── UncheckAll.png
│ ├── Undo.png
│ ├── Viewer.ico
│ ├── Warning.png
│ ├── WarpCell.png
│ ├── White.png
│ └── WholeWord.png
├── Themes
│ └── Generic.xaml
├── Utility
│ ├── BitmapBuilder.cs
│ ├── Dialog.cs
│ ├── DialogWrapper.cs
│ ├── EndianBinaryReader.cs
│ ├── EndianBinaryWriter.cs
│ ├── FakeEnum.cs
│ ├── FrameworkElementFactory.cs
│ ├── GitHubReleases.cs
│ ├── IO.Item.cs
│ ├── IO.Path.cs
│ ├── IO.Stream.cs
│ ├── IPathNode.cs
│ ├── IPersistState.cs
│ ├── Log.cs
│ ├── LogItem.cs
│ ├── LogViewer.cs
│ ├── PInvoke.cs
│ ├── ReadWriteLock.cs
│ ├── Resource.cs
│ ├── ScopedCursor.cs
│ └── Steam.File.Loader.cs
├── cmkNMSCommon.csproj
├── cmkNMSCommon.csproj.user
├── cmkNMSReleases.txt
├── libMBIN.dll
└── spirv-cross.exe
├── Doc
├── About.png
├── Application.png
├── QuickStart
│ └── Readme.md
├── Script
│ └── Readme.md
├── Splash.png
└── Tab
│ ├── Application
│ ├── Application.png
│ ├── Download.png
│ ├── LoadedTabs.png
│ ├── Readme.md
│ ├── SelectGameFolder.png
│ ├── StartTabs.png
│ ├── Statusbar.png
│ └── Toolbar.png
│ ├── Build
│ ├── Build1.png
│ ├── Build2.png
│ └── Readme.md
│ ├── Items
│ ├── Products.png
│ ├── Readme.md
│ ├── Substances.png
│ └── Technologies.png
│ ├── Language
│ ├── LanguageEN.png
│ ├── LanguageKO.png
│ └── Readme.md
│ ├── MBINC
│ ├── MBINC_ChildClass.png
│ ├── MBINC_TopLevelClass.png
│ └── Readme.md
│ ├── PakConflicts
│ ├── PakConflicts.png
│ └── Readme.md
│ ├── PakItems
│ ├── PakItemDds.png
│ ├── PakItemMbin.png
│ ├── PakItemMbinColor.png
│ ├── PakItemMbinDiff.png
│ ├── PakItemMbinLanguage.png
│ ├── PakItemMbinPath1.png
│ ├── PakItemMbinPath2.png
│ ├── PakItemSpv.png
│ ├── PakItems.png
│ └── Readme.md
│ ├── Readme.md
│ ├── Recipes
│ ├── Readme.md
│ ├── RecipesCooking.png
│ └── RecipesRefiner.png
│ ├── ScriptMod
│ ├── Readme.md
│ └── ScriptMod.png
│ ├── ScriptQuery
│ ├── Readme.md
│ ├── ScriptQuery.png
│ └── ScriptQueryCompile.png
│ ├── ScriptUtil
│ ├── Readme.md
│ ├── ScriptQueryCompile.png
│ └── ScriptUtil.png
│ ├── SearchDds
│ ├── Dds.png
│ └── Readme.md
│ ├── SearchPaths
│ ├── Dds.png
│ └── Readme.md
│ └── SearchText
│ ├── Mbin1.png
│ ├── Mbin2.png
│ └── Readme.md
├── LICENSE
├── Plugins
└── Sample
│ ├── Sample.cs
│ ├── Sample.csproj
│ └── Sample.sln
├── change.log
└── readme.md
/Common/Controls/BitmapViewerSideBySide.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System.Windows.Media;
22 | using System.Windows.Media.Imaging;
23 | using System.Windows.Shapes;
24 |
25 | //=============================================================================
26 |
27 | namespace cmk
28 | {
29 | public class BitmapViewerSideBySide
30 | : System.Windows.Controls.Grid
31 | {
32 | public BitmapViewerSideBySide() : base()
33 | {
34 | ColumnDefinitions.AddStar();
35 | ColumnDefinitions.AddPixel(4);
36 | ColumnDefinitions.AddStar();
37 |
38 | SetColumn(ViewerLeft, 0);
39 | SetColumn(Splitter, 1);
40 | SetColumn(ViewerRight, 2);
41 |
42 | Children.Add(ViewerLeft);
43 | Children.Add(Splitter);
44 | Children.Add(ViewerRight);
45 | }
46 |
47 | //...........................................................
48 |
49 | public readonly Rectangle Splitter = new() { Fill = Brushes.Black };
50 | public readonly BitmapViewer ViewerLeft = new();
51 | public readonly BitmapViewer ViewerRight = new();
52 |
53 | //...........................................................
54 |
55 | public string LabelLeft {
56 | get { return ViewerLeft.LabelText; }
57 | set { ViewerLeft.LabelText = value; }
58 | }
59 |
60 | public string LabelRight {
61 | get { return ViewerRight.LabelText; }
62 | set { ViewerRight.LabelText = value; }
63 | }
64 |
65 | //...........................................................
66 |
67 | public BitmapSource SourceLeft {
68 | get { return ViewerLeft.Source; }
69 | set { ViewerLeft.Source = value; }
70 | }
71 |
72 | public BitmapSource SourceRight {
73 | get { return ViewerRight.Source; }
74 | set { ViewerRight.Source = value; }
75 | }
76 | }
77 | }
78 |
79 | //=============================================================================
80 |
--------------------------------------------------------------------------------
/Common/Controls/ComboBox.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System.Windows;
22 | using System.Windows.Controls;
23 | using System.Windows.Data;
24 |
25 | //=============================================================================
26 |
27 | namespace cmk
28 | {
29 | public class ComboBox
30 | : System.Windows.Controls.ComboBox
31 | {
32 | public delegate void VisualChildrenChangedEventHandler( DependencyObject ADDED, DependencyObject REMOVED );
33 | public event VisualChildrenChangedEventHandler VisualChildrenChanged;
34 |
35 | //...........................................................
36 |
37 | public ComboBox() : base()
38 | {
39 | Construct(true);
40 | }
41 |
42 | //...........................................................
43 |
44 | public ComboBox( bool IS_VIRTUALIZING ) : base()
45 | {
46 | Construct(IS_VIRTUALIZING);
47 | }
48 |
49 | //...........................................................
50 |
51 | public ListCollectionView ListCollectionView =>
52 | CollectionViewSource.GetDefaultView(ItemsSource) as ListCollectionView
53 | ;
54 |
55 | //...........................................................
56 |
57 | protected void Construct( bool IS_VIRTUALIZING )
58 | {
59 | Grid.SetIsSharedSizeScope(this, true);
60 |
61 | if( IS_VIRTUALIZING ) ItemsPanel = new() {
62 | VisualTree = new System.Windows.FrameworkElementFactory(typeof(VirtualizingStackPanel))
63 | };
64 | SetValue(VirtualizingStackPanel.IsVirtualizingProperty, IS_VIRTUALIZING);
65 | SetValue(VirtualizingStackPanel.IsVirtualizingWhenGroupingProperty, IS_VIRTUALIZING);
66 | SetValue(VirtualizingStackPanel.VirtualizationModeProperty, VirtualizationMode.Recycling);
67 |
68 | HorizontalContentAlignment = HorizontalAlignment.Stretch;
69 | VerticalAlignment = VerticalAlignment.Center;
70 | BorderThickness = new(0);
71 | Padding = new(2);
72 | Margin = new(2);
73 | IsEditable = false;
74 | IsReadOnly = true;
75 |
76 | ToolTipService.SetInitialShowDelay(this, 0);
77 | ToolTipService.SetShowDuration(this, 60000);
78 | }
79 |
80 | //...........................................................
81 |
82 | protected override void OnVisualChildrenChanged( DependencyObject ADDED, DependencyObject REMOVED )
83 | {
84 | base.OnVisualChildrenChanged(ADDED, REMOVED);
85 | VisualChildrenChanged?.Invoke(ADDED, REMOVED);
86 | }
87 | }
88 | }
89 |
90 | //=============================================================================
91 |
--------------------------------------------------------------------------------
/Common/Controls/GitHubButton.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System;
22 | using System.Diagnostics;
23 | using System.Windows.Controls;
24 |
25 | //=============================================================================
26 |
27 | namespace cmk
28 | {
29 | public class GitHubButton
30 | : cmk.ImageButton
31 | {
32 | public GitHubButton( string USER, string REPOSITORY ) : base()
33 | {
34 | Uri = Resource.Uri("GitHub.png");
35 | User = USER;
36 | Repository = REPOSITORY;
37 |
38 | ToolTipService.SetInitialShowDelay(this, 0);
39 | ToolTipService.SetShowDuration(this, 60000);
40 | }
41 |
42 | //...........................................................
43 |
44 | protected string m_user = "";
45 |
46 | public string User {
47 | get { return m_user; }
48 | set {
49 | if( m_user == value ) return;
50 | m_user = value;
51 | ToolTip = Url;
52 | }
53 | }
54 |
55 | //...........................................................
56 |
57 | protected string m_repository = "";
58 |
59 | public string Repository {
60 | get { return m_repository; }
61 | set {
62 | if( m_repository == value ) return;
63 | m_repository = value;
64 | ToolTip = Url;
65 | }
66 | }
67 |
68 | //...........................................................
69 |
70 | public string Url {
71 | get { return $"https://github.com/{User}/{Repository}"; }
72 | }
73 |
74 | //...........................................................
75 |
76 | protected override void OnClick()
77 | {
78 | base.OnClick();
79 | try {
80 | var info = new ProcessStartInfo {
81 | FileName = Url,
82 | UseShellExecute = true,
83 | };
84 | _ = Process.Start(info);
85 | }
86 | catch( Exception EX ) { Log.Default.AddFailure(EX); }
87 | }
88 | }
89 | }
90 |
91 | //=============================================================================
92 |
--------------------------------------------------------------------------------
/Common/Controls/HexDiffer.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System.IO;
22 | using System.Windows.Media;
23 | using System.Windows.Shapes;
24 |
25 | //=============================================================================
26 |
27 | namespace cmk
28 | {
29 | public class HexDiffer
30 | : System.Windows.Controls.Grid
31 | {
32 | public HexDiffer( Stream LHS, Stream RHS ) : base()
33 | {
34 | ColumnDefinitions.AddStar();
35 | ColumnDefinitions.AddPixel(4);
36 | ColumnDefinitions.AddStar();
37 |
38 | SetColumn(ViewerLeft, 0);
39 | SetColumn(Splitter, 1);
40 | SetColumn(ViewerRight, 2);
41 |
42 | Children.Add(ViewerLeft);
43 | Children.Add(Splitter);
44 | Children.Add(ViewerRight);
45 |
46 | StreamLeft = LHS;
47 | StreamRight = RHS;
48 | }
49 |
50 | //...........................................................
51 |
52 | public readonly Rectangle Splitter = new() { Fill = Brushes.Black };
53 | public readonly HexViewer ViewerLeft = new(null);
54 | public readonly HexViewer ViewerRight = new(null);
55 |
56 | //...........................................................
57 |
58 | public Stream StreamLeft {
59 | get { return ViewerLeft.Raw; }
60 | set { ViewerLeft.Raw = value; }
61 | }
62 |
63 | public Stream StreamRight {
64 | get { return ViewerRight.Raw; }
65 | set { ViewerRight.Raw = value; }
66 | }
67 | }
68 | }
69 |
70 | //=============================================================================
71 |
--------------------------------------------------------------------------------
/Common/Controls/HexViewer.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System.IO;
22 |
23 | //=============================================================================
24 |
25 | namespace cmk
26 | {
27 | public class HexViewer // todo
28 | : cmk.TextViewer
29 | {
30 | public HexViewer( Stream RAW = null ) : base()
31 | {
32 | Raw = RAW;
33 | }
34 |
35 | //...........................................................
36 |
37 | public Stream Raw {
38 | get;
39 | set;
40 | }
41 | }
42 | }
43 |
44 | //=============================================================================
45 |
--------------------------------------------------------------------------------
/Common/Controls/StackPanel.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System.Windows;
22 | using System.Windows.Controls;
23 | using System.Windows.Media;
24 |
25 | //=============================================================================
26 |
27 | namespace cmk
28 | {
29 | public class StackPanel
30 | : System.Windows.Controls.StackPanel
31 | {
32 | public delegate void VisualChildrenChangedEventHandler( DependencyObject ADDED, DependencyObject REMOVED );
33 | public event VisualChildrenChangedEventHandler VisualChildrenChanged;
34 |
35 | //...........................................................
36 |
37 | public StackPanel()
38 | {
39 | Background = Brushes.LightGray;
40 | Grid.SetIsSharedSizeScope(this, true);
41 | }
42 |
43 | //...........................................................
44 |
45 | protected override void OnVisualChildrenChanged( DependencyObject ADDED, DependencyObject REMOVED )
46 | {
47 | base.OnVisualChildrenChanged(ADDED, REMOVED);
48 | VisualChildrenChanged?.Invoke(ADDED, REMOVED);
49 | }
50 | }
51 | }
52 |
53 | //=============================================================================
54 |
--------------------------------------------------------------------------------
/Common/Controls/TextBoxDialog.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System.Windows;
22 | using System.Windows.Controls;
23 |
24 | //=============================================================================
25 |
26 | namespace cmk
27 | {
28 | public class TextBoxDialog
29 | : System.Windows.Window
30 | {
31 | public TextBoxDialog() : base()
32 | {
33 | Title = "Edit Text";
34 |
35 | WindowStartupLocation = WindowStartupLocation.CenterScreen;
36 | SizeToContent = SizeToContent.Width;
37 | Topmost = true;
38 | MinHeight = 105;
39 | MaxHeight = 105;
40 | MinWidth = 256;
41 |
42 | Grid.Children.Add(TextBox);
43 | Grid.Children.Add(OkButton);
44 | Grid.Children.Add(CancelButton);
45 |
46 | Content = Grid;
47 |
48 | OkButton.Click += OnOkClick;
49 | CancelButton.Click += OnCancelClick;
50 |
51 | Loaded += ( S, E ) => TextBox.Text = Text;
52 | }
53 |
54 | //...........................................................
55 |
56 | public readonly Grid Grid = new();
57 |
58 | public readonly TextBox TextBox = new() {
59 | HorizontalAlignment = HorizontalAlignment.Stretch,
60 | VerticalAlignment = VerticalAlignment.Top,
61 | TextWrapping = TextWrapping.NoWrap,
62 | Margin = new(10, 10, 10, 0),
63 | };
64 |
65 | public readonly Button OkButton = new() {
66 | HorizontalAlignment = HorizontalAlignment.Right,
67 | VerticalAlignment = VerticalAlignment.Bottom,
68 | Margin = new(0, 0, 90, 10),
69 | Width = 75,
70 | Content = "OK",
71 | };
72 | public readonly Button CancelButton = new() {
73 | HorizontalAlignment = HorizontalAlignment.Right,
74 | VerticalAlignment = VerticalAlignment.Bottom,
75 | Margin = new(0, 0, 10, 10),
76 | Width = 75,
77 | Content = "Cancel",
78 | };
79 |
80 | //...........................................................
81 |
82 | public string Text { get; set; }
83 |
84 | //...........................................................
85 |
86 | protected void OnOkClick( object SENDER, RoutedEventArgs ARGS )
87 | {
88 | Text = TextBox.Text;
89 | DialogResult = true;
90 | Close();
91 | }
92 |
93 | //...........................................................
94 |
95 | protected void OnCancelClick( object SENDER, RoutedEventArgs ARGS )
96 | {
97 | DialogResult = false;
98 | Close();
99 | }
100 | }
101 | }
102 |
103 | //=============================================================================
104 |
--------------------------------------------------------------------------------
/Common/Controls/TextSearchBackgroundRenderer.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System.Collections.Generic;
22 | using System.Linq;
23 | using System.Text.RegularExpressions;
24 | using System.Windows.Media;
25 | using avalon = ICSharpCode.AvalonEdit;
26 |
27 | //=============================================================================
28 |
29 | namespace cmk
30 | {
31 | public class TextSearchBackgroundRenderer
32 | : avalon.Rendering.IBackgroundRenderer
33 | {
34 | public List Results { get; set; }
35 | public Brush MarkerBrush { get; set; }
36 |
37 | //...........................................................
38 |
39 | public avalon.Rendering.KnownLayer Layer {
40 | get { return avalon.Rendering.KnownLayer.Selection; }
41 | }
42 |
43 | //...........................................................
44 |
45 | public void Draw( avalon.Rendering.TextView VIEW, DrawingContext CONTEXT )
46 | {
47 | var results = Results;
48 | if( VIEW == null || CONTEXT == null || results.IsNullOrEmpty() ) return;
49 |
50 | VIEW.EnsureVisualLines();
51 |
52 | var visible_lines = VIEW.VisualLines;
53 | var offset_start = visible_lines.First().FirstDocumentLine.Offset;
54 | var offset_end = visible_lines.Last() .LastDocumentLine .EndOffset;
55 |
56 | var brush = MarkerBrush ?? Brushes.Yellow;
57 |
58 | foreach( var match in results ) {
59 | var match_end = match.Index + match.Length;
60 | if( match_end <= offset_start ) continue;
61 | if( match.Index > offset_end ) break;
62 |
63 | var segment = new avalon.Document.TextSegment{
64 | StartOffset = match.Index,
65 | Length = match.Length,
66 | };
67 |
68 | foreach( var rect in avalon.Rendering.BackgroundGeometryBuilder.GetRectsForSegment(VIEW, segment) ) {
69 | CONTEXT.DrawRectangle(brush, null, rect);
70 | }
71 | }
72 | }
73 | }
74 | }
75 |
76 | //=============================================================================
77 |
--------------------------------------------------------------------------------
/Common/Controls/XmlViewer.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System.Windows;
22 | using avalon = ICSharpCode.AvalonEdit;
23 |
24 | //=============================================================================
25 |
26 | namespace cmk
27 | {
28 | public class XmlFoldingStrategyAdapter
29 | : cmk.ITextViewerFoldingStrategy
30 | {
31 | public static avalon.Folding.XmlFoldingStrategy XmlFoldingStrategy = new() {
32 | ShowAttributesWhenFolded = true
33 | };
34 |
35 | //...........................................................
36 |
37 | public void UpdateFoldings(
38 | avalon.Folding.FoldingManager MANAGER,
39 | avalon.Document.TextDocument DOCUMENT
40 | ){
41 | if( MANAGER != null && DOCUMENT != null ) {
42 | XmlFoldingStrategy.UpdateFoldings(MANAGER, DOCUMENT);
43 | }
44 | }
45 | }
46 |
47 | //=========================================================================
48 |
49 | public class XmlViewer
50 | : cmk.TextViewerFolding
51 | {
52 | public XmlViewer( string XML = "", string PAKFILENAME = "" )
53 | : base(XML, PAKFILENAME, new XmlFoldingStrategyAdapter())
54 | {
55 | LoadHighlighterExtension(".xml");
56 | }
57 |
58 | //...........................................................
59 |
60 | protected override void OnLoaded( object SENDER, RoutedEventArgs ARGS )
61 | {
62 | base.OnLoaded(SENDER, ARGS);
63 | FoldingsCollapseAll();
64 | }
65 | }
66 | }
67 |
68 | //=============================================================================
69 |
--------------------------------------------------------------------------------
/Common/Extensions/System.Array.x.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System;
22 |
23 | //=============================================================================
24 |
25 | namespace cmk
26 | {
27 | public static partial class Array_x
28 | {
29 | ///
30 | /// Use msvcrt memcmp to compare min length of LHS, RHS.
31 | /// If common length elements are equal then compare lengths.
32 | ///
33 | public static int MemCmp( byte[] LHS, byte[] RHS )
34 | {
35 | if( ReferenceEquals(LHS, RHS) ) return 0;
36 | if( LHS == null ) return -1;
37 | if( RHS == null ) return 1;
38 |
39 | var length = Math.Min(LHS.Length, RHS.Length);
40 | var compare = PInvoke.memcmp(LHS, RHS, length);
41 | if( compare != 0 ) return compare;
42 |
43 | if( LHS.Length > length ) return 1;
44 | if( RHS.Length > length ) return -1;
45 |
46 | return 0;
47 | }
48 | }
49 | }
50 |
51 | //=============================================================================
52 |
--------------------------------------------------------------------------------
/Common/Extensions/System.DateTime.x.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System;
22 |
23 | //=============================================================================
24 |
25 | namespace cmk
26 | {
27 | public static partial class _x_
28 | {
29 | ///
30 | /// hh:mm:ss.fff
31 | ///
32 | public static string ToTimeStamp( this DateTime DATE_TIME )
33 | {
34 | return DATE_TIME.ToString("hh:mm:ss.fff");
35 | }
36 | }
37 | }
38 |
39 | //=============================================================================
40 |
--------------------------------------------------------------------------------
/Common/Extensions/System.Delegate.x.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System;
22 | using System.Threading.Tasks;
23 | using System.Windows;
24 | using System.Windows.Threading;
25 |
26 | //=============================================================================
27 |
28 | namespace cmk
29 | {
30 | public static partial class _x_
31 | {
32 | ///
33 | /// Invoke DELEGATE using Application.Current?.Dispatcher.
34 | ///
35 | public static object DispatcherInvoke(
36 | this Delegate DELEGATE, params object[] ARGS
37 | )
38 | => Application.Current?.Dispatcher.Invoke(DELEGATE, ARGS);
39 |
40 | //...........................................................
41 |
42 | ///
43 | /// BeginInvoke DELEGATE using Application.Current?.Dispatcher.
44 | ///
45 | public static DispatcherOperation DispatcherBeginInvoke(
46 | this Delegate DELEGATE, params object[] ARGS
47 | )
48 | => Application.Current?.Dispatcher.BeginInvoke(DELEGATE, ARGS);
49 |
50 | //...........................................................
51 |
52 | ///
53 | /// DynamicInvoke each delegate in DELEGATE.GetInvocationList
54 | /// in parallel.
55 | ///
56 | public static void ParallelInvoke(
57 | this Delegate DELEGATE, params object[] ARGS
58 | ) {
59 | if( DELEGATE == null ) return;
60 |
61 | var list = DELEGATE.GetInvocationList();
62 |
63 | if( list == null || (
64 | list.Length == 1 && list[0] == DELEGATE
65 | ) ) {
66 | DELEGATE.DynamicInvoke(ARGS);
67 | }
68 | else {
69 | _ = Parallel.ForEach(list, SUB_DELEGATE =>
70 | ParallelInvoke(SUB_DELEGATE, ARGS)
71 | );
72 | }
73 | }
74 | }
75 | }
76 |
77 | //=============================================================================
78 |
--------------------------------------------------------------------------------
/Common/Extensions/System.Net.Http.HttpClient.x.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System;
22 | using System.IO;
23 | using System.Net.Http;
24 | using System.Threading;
25 | using System.Threading.Tasks;
26 |
27 | //=============================================================================
28 |
29 | namespace cmk
30 | {
31 | public static partial class _x_
32 | {
33 | ///
34 | /// Use HTTP to request URI content and copy to TARGET.
35 | /// Report % progress (0-100) to PROGRESS_PERCENT.
36 | ///
37 | public static async Task RecvAsync(
38 | this HttpClient HTTP,
39 | Uri URI,
40 | Stream TARGET,
41 | IProgress PROGRESS_PERCENT = null, // 0 - 100
42 | CancellationToken CANCEL = default,
43 | int BUFFER_SIZE = 65536
44 | ){
45 | if( HTTP == null ) throw new ArgumentNullException(nameof(HTTP));
46 | if( URI == null ) throw new ArgumentNullException(nameof(URI));
47 | if( TARGET == null ) throw new ArgumentNullException(nameof(TARGET));
48 |
49 | if( !TARGET.CanWrite ) throw new ArgumentException("Can't write to target.", nameof(TARGET));
50 |
51 | using( var response = await HTTP.GetAsync(URI, HttpCompletionOption.ResponseHeadersRead, CANCEL).ConfigureAwait(false) ) {
52 | if( !response.IsSuccessStatusCode ) throw new HttpRequestException(
53 | response.ReasonPhrase, null, response.StatusCode
54 | );
55 | var length = response.Content.Headers.ContentLength.GetValueOrDefault(0);
56 | using( var source = await response.Content.ReadAsStreamAsync(CANCEL).ConfigureAwait(false) ) {
57 | if( PROGRESS_PERCENT == null || length < 1 ) {
58 | await source.CopyToAsync(TARGET, CANCEL).ConfigureAwait(false);
59 | return;
60 | }
61 | var progress = new Progress(
62 | // forward progress to PROGRESS_PERCENT.
63 | // convert CopyToAsync total-bytes-copied to a % (0 - 100).
64 | TOTAL => PROGRESS_PERCENT.Report((byte)(100 * TOTAL / length))
65 | );
66 | await source.CopyToAsync(TARGET, progress, CANCEL, BUFFER_SIZE).ConfigureAwait(false);
67 | PROGRESS_PERCENT.Report(100);
68 | }
69 | }
70 | }
71 | }
72 | }
73 |
74 | //=============================================================================
75 |
--------------------------------------------------------------------------------
/Common/Extensions/System.Object.x.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System;
22 |
23 | //=============================================================================
24 |
25 | namespace cmk
26 | {
27 | public static partial class _x_
28 | {
29 | [Obsolete]
30 | public static WeakReference GetWeakReference( this object OBJECT )
31 | {
32 | return OBJECT == null ? null : new(OBJECT, trackResurrection: true);
33 | }
34 |
35 | //...........................................................
36 |
37 | public static WeakReference GetWeakReference( this TYPE_T OBJECT )
38 | where TYPE_T : class
39 | {
40 | return OBJECT == null ? null : new(OBJECT, trackResurrection: true);
41 | }
42 | }
43 | }
44 |
45 | //=============================================================================
46 |
--------------------------------------------------------------------------------
/Common/Extensions/System.Reflection.FieldInfo.x.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System.Reflection;
22 |
23 | //=============================================================================
24 |
25 | namespace cmk
26 | {
27 | public static partial class _x_
28 | {
29 | ///
30 | /// Build field name string, supports generic's, arrays, and libMBIN.NMSAttribute.
31 | ///
32 | public static string GenericName( this FieldInfo FIELD, bool FULL = false )
33 | {
34 | var generic_name = "";
35 | if( FULL ) generic_name = FIELD.FieldType.Namespace + ".";
36 |
37 | generic_name += RootName(FIELD.FieldType);
38 |
39 | var nms_attr = FIELD.GetCustomAttribute();
40 | var nms_size = nms_attr?.Size ?? 0;
41 | var nms_enum = nms_attr?.EnumType;
42 |
43 | if( FIELD.FieldType.IsGenericType ) {
44 | generic_name += "<";
45 | var generics = FIELD.FieldType.GetGenericArguments();
46 | if( generics.Length > 0 ) {
47 | generic_name += GenericName(generics[0], false);
48 | for( int i = 1; i < generics.Length; ++i ) {
49 | generic_name += "," + GenericName(generics[i], false);
50 | }
51 | }
52 | generic_name += ">";
53 | }
54 | if( FIELD.FieldType.IsArray ) {
55 | for( var i = 0; i < FIELD.FieldType.GetArrayRank(); ++i ) {
56 | generic_name += "[";
57 | if( nms_size > 0 ) generic_name += nms_size;
58 | if( nms_enum != null ) {
59 | if( nms_size < 1 ) generic_name += nms_enum.GetEnumValues().Length;
60 | generic_name += ":" + nms_enum.Name;
61 | }
62 | generic_name += "]";
63 | }
64 | }
65 | else if( nms_size > 0 ) {
66 | generic_name += "(" + nms_size + ")";
67 | }
68 | else if( nms_enum != null ) {
69 | generic_name += "(" + nms_enum.GetEnumValues().Length + ":" + nms_enum.Name + ")";
70 | }
71 |
72 | return generic_name;
73 | }
74 |
75 | //...........................................................
76 |
77 | ///
78 | /// FIELD.FieldType.GenericName(false) + " " + FIELD.Name
79 | ///
80 | public static string TypeAndName( this FieldInfo FIELD )
81 | {
82 | return FIELD.FieldType.GenericName(false) + " " + FIELD.Name;
83 | }
84 | }
85 | }
86 |
87 | //=============================================================================
88 |
--------------------------------------------------------------------------------
/Common/Extensions/System.Span.x.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System;
22 |
23 | //=============================================================================
24 |
25 | namespace cmk
26 | {
27 | public static partial class _x_
28 | {
29 | public static bool IsNullOrEmpty( this ReadOnlySpan SPAN )
30 | {
31 | return (SPAN == null) || (SPAN.Length < 1);
32 | }
33 | }
34 | }
35 |
36 | //=============================================================================
37 |
--------------------------------------------------------------------------------
/Common/Extensions/System.String.x.p.CompareNumeric.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System;
22 |
23 | //=============================================================================
24 |
25 | namespace cmk
26 | {
27 | public static partial class String
28 | {
29 | ///
30 | /// All embedded #'s are treated as positive and "01" > "1",
31 | /// i.e. in "blah-3blah" the '-' is a char, not part of the number.
32 | /// Does not handle decimals i.e. '.' is considered a char, not part of the number.
33 | ///
34 | public static int CompareNumeric( ReadOnlySpan LHS, ReadOnlySpan RHS, bool IGNORE_CASE = false )
35 | {
36 | if( LHS == null ) return -1;
37 | if( RHS == null ) return 1;
38 |
39 | var ll = LHS.Length;
40 | var lr = RHS.Length;
41 |
42 | for( int il = 0, ir = 0; il < ll && ir < lr; ++il, ++ir ) {
43 | var is_dl = char.IsDigit(LHS[il]);
44 | var is_dr = char.IsDigit(RHS[ir]);
45 | if( is_dl && is_dr ) {
46 | // skip leading 0's
47 | while( il < ll && LHS[il] == '0' ) ++il;
48 | while( ir < lr && RHS[ir] == '0' ) ++ir;
49 |
50 | // find end of digit string
51 | var idl = il; while( idl < ll && char.IsDigit(LHS[idl]) ) ++idl;
52 | var idr = ir; while( idr < lr && char.IsDigit(RHS[idr]) ) ++idr;
53 |
54 | // if diff # of digits then compare lengths
55 | var ldl = idl - il;
56 | var ldr = idr - ir;
57 | if( ldl < ldr ) return -1;
58 | if( ldl > ldr ) return 1;
59 |
60 | // parse digit strings, they have same # of char
61 | if( ldl > 0 ) {
62 | var sl = LHS.Slice(il, ldl);
63 | var sr = RHS.Slice(ir, ldr);
64 | var c = sl.CompareTo(sr, StringComparison.Ordinal);
65 | if( c < 0 ) return -1;
66 | if( c > 0 ) return 1;
67 | }
68 |
69 | il = idl - 1;
70 | ir = idr - 1;
71 | }
72 | else { // not both digits
73 | var cl = is_dl ? LHS[il] : char.ToUpper(LHS[il]);
74 | var cr = is_dr ? RHS[ir] : char.ToUpper(RHS[ir]);
75 | if( cl < cr ) return -1;
76 | if( cl > cr ) return 1;
77 | if( !IGNORE_CASE ) {
78 | cl = LHS[il];
79 | cr = RHS[ir];
80 | if( cl < cr ) return -1;
81 | if( cl > cr ) return 1;
82 | }
83 | }
84 | }
85 |
86 | if( ll < lr ) return -1;
87 | if( ll > lr ) return 1;
88 |
89 | return 0;
90 | }
91 | }
92 | }
93 |
94 | //=============================================================================
95 |
--------------------------------------------------------------------------------
/Common/Extensions/System.Threading.Tasks.Task.x.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System.Threading;
22 | using System.Threading.Tasks;
23 | using System.Windows.Threading;
24 |
25 | //=============================================================================
26 |
27 | namespace cmk
28 | {
29 | public static partial class _x_
30 | {
31 | ///
32 | /// Wait for TASK to complete while still pumping messages for thread.
33 | ///
34 | public static void Pump(
35 | this Task TASK,
36 | CancellationToken CANCEL = default
37 | ){
38 | // run TASK async, when TASK completes set nested.Continue = false
39 | var nested = new DispatcherFrame();
40 | TASK.ContinueWith(_ => nested.Continue = false, TaskScheduler.Default);
41 | Dispatcher.PushFrame(nested); // pump until nested.Continue = false
42 | TASK.Wait(CANCEL);
43 | }
44 |
45 | //...........................................................
46 |
47 | ///
48 | /// Wait for TASK to complete while still pumping messages for thread.
49 | ///
50 | public static T Pump(
51 | this Task TASK,
52 | CancellationToken CANCEL = default
53 | ){
54 | var nested = new DispatcherFrame();
55 | TASK.ContinueWith(_ => nested.Continue = false, TaskScheduler.Default);
56 | Dispatcher.PushFrame(nested);
57 | return TASK.Result(CANCEL);
58 | }
59 |
60 | //...........................................................
61 |
62 | ///
63 | /// Wait for TASK to complete.
64 | ///
65 | public static T Result( this Task TASK, CancellationToken CANCEL = default )
66 | {
67 | //TASK.Wait(CANCEL);
68 | return TASK.Result;
69 | }
70 | }
71 | }
72 |
73 | //=============================================================================
74 |
--------------------------------------------------------------------------------
/Common/Extensions/System.Version.x.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System;
22 |
23 | //=============================================================================
24 |
25 | namespace cmk
26 | {
27 | public static partial class _x_
28 | {
29 | ///
30 | /// All parts < 0.
31 | ///
32 | public static bool IsNull( this Version VERSION )
33 | {
34 | return
35 | VERSION == null || (
36 | VERSION.Major < 0 &&
37 | VERSION.Minor < 0 &&
38 | VERSION.Build < 0 &&
39 | VERSION.Revision < 0
40 | );
41 | }
42 |
43 | //...........................................................
44 |
45 | ///
46 | /// All parts <= 0.
47 | ///
48 | public static bool IsNullOrZero( this Version VERSION )
49 | {
50 | return
51 | VERSION == null || (
52 | VERSION.Major <= 0 &&
53 | VERSION.Minor <= 0 &&
54 | VERSION.Build <= 0 &&
55 | VERSION.Revision <= 0
56 | );
57 | }
58 |
59 | //...........................................................
60 |
61 | ///
62 | /// Convert any parts that are < 0 to 0.
63 | /// By default NET uses -1 to indicate part not used.
64 | ///
65 | public static Version Normalize( this Version VERSION )
66 | {
67 | if( VERSION == null ) return new();
68 |
69 | var major = VERSION.Major;
70 | var minor = VERSION.Minor;
71 | var build = VERSION.Build;
72 | var revision = VERSION.Revision;
73 |
74 | if( major < 1 ) major = 0;
75 | if( minor < 1 ) minor = 0;
76 | if( build < 1 ) build = 0;
77 | if( revision < 1 ) revision = 0;
78 |
79 | return new(major, minor, build, revision);
80 | }
81 |
82 | //...........................................................
83 |
84 | public static Version ClampLower( this Version VERSION, Version CLAMP )
85 | {
86 | return (VERSION < CLAMP) ? CLAMP : VERSION;
87 | }
88 |
89 | //...........................................................
90 |
91 | public static Version ClampUpper( this Version VERSION, Version CLAMP )
92 | {
93 | return (VERSION > CLAMP) ? CLAMP : VERSION;
94 | }
95 |
96 | //...........................................................
97 |
98 | public static Version Clamp( this Version VERSION, Version MIN, Version MAX )
99 | {
100 | return ClampUpper(ClampLower(VERSION, MIN), MAX);
101 | }
102 | }
103 | }
104 |
105 | //=============================================================================
106 |
--------------------------------------------------------------------------------
/Common/Extensions/System.WeakReference.cs:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | /*
3 | cmk NMS Common
4 | Copyright (C) 2021 Chris Kushnir
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU Affero General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU Affero General Public License for more details.
15 |
16 | You should have received a copy of the GNU Affero General Public License
17 | along with this program. If not, see .
18 | */
19 | //=============================================================================
20 |
21 | using System;
22 | using System.Runtime.CompilerServices;
23 |
24 | //=============================================================================
25 |
26 | namespace cmk
27 | {
28 | public static partial class _x_
29 | {
30 | ///
31 | /// The object passed to IS_ALIVE will be non-null.
32 | ///
33 | [Obsolete]
34 | [MethodImpl(MethodImplOptions.NoInlining)]
35 | public static bool WaitForPendingFinalizers(
36 | this WeakReference WEAK,
37 | Predicate