├── .gitignore ├── AK.Abr ├── AK.Abr.csproj ├── AbrReader.cs ├── AbrReaderFactory.cs ├── BrushImageReadyEventArgs.cs ├── CachingAbrReader.cs ├── CachingAbrReaderFactory.cs ├── DiskBitmapCache.cs ├── FileAbrSource.cs ├── IAbrReader.cs ├── IAbrReaderFactory.cs ├── IAbrSource.cs ├── IBitmapCache.cs ├── MemoryBitmapCache.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings └── WritableBitmapImage.cs ├── AbrViewer.sln ├── AbrViewer.sln.DotSettings ├── AbrViewer ├── AboutWindow.xaml ├── AboutWindow.xaml.cs ├── AbrViewer.csproj ├── App.config ├── App.ico ├── App.xaml ├── App.xaml.cs ├── Behaviors │ ├── DoubleClickCommandBehavior.cs │ └── KeyCommandBehavior.cs ├── BrushPreviewWindow.xaml ├── BrushPreviewWindow.xaml.cs ├── Config.cs ├── FodyWeavers.xml ├── FodyWeavers.xsd ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Properties │ ├── Annotations.cs │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Services │ ├── ConfigService.cs │ ├── DialogService.cs │ ├── IConfigService.cs │ ├── IDialogService.cs │ └── IRootWindow.cs ├── Support │ ├── ApplicationInfo.cs │ ├── CommandReference.cs │ ├── Extensions.cs │ ├── Lazy.cs │ └── SynchronizeInvokeAdapter.cs ├── UnityConfiguration.xsd ├── ViewModels │ └── MainViewModel.cs └── packages.config ├── Library ├── MiscUtil.dll └── MiscUtil.xml ├── README.md └── UNLICENSE.txt /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | # tools/** 279 | # !tools/packages.config 280 | 281 | # Telerik's JustMock configuration file 282 | *.jmconfig 283 | 284 | # BizTalk build output 285 | *.btp.cs 286 | *.btm.cs 287 | *.odx.cs 288 | *.xsd.cs 289 | -------------------------------------------------------------------------------- /AK.Abr/AK.Abr.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {5BAEF14C-17BB-4E1C-8233-A2BA5ABDDD27} 9 | library 10 | Properties 11 | AK.Abr 12 | AK.Abr 13 | v4.0 14 | Client 15 | 512 16 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 17 | 4 18 | 19 | 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | true 28 | latest 29 | false 30 | 31 | 32 | pdbonly 33 | true 34 | bin\Release\ 35 | TRACE 36 | prompt 37 | 4 38 | false 39 | 40 | 41 | 42 | ..\Library\MiscUtil.dll 43 | 44 | 45 | 46 | 47 | 4.0 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | Code 71 | 72 | 73 | True 74 | True 75 | Resources.resx 76 | 77 | 78 | True 79 | Settings.settings 80 | True 81 | 82 | 83 | ResXFileCodeGenerator 84 | Resources.Designer.cs 85 | 86 | 87 | SettingsSingleFileGenerator 88 | Settings.Designer.cs 89 | 90 | 91 | 92 | 93 | 100 | -------------------------------------------------------------------------------- /AK.Abr/AbrReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.IO; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | using System.Windows.Media; 7 | using System.Windows.Media.Imaging; 8 | using MiscUtil.Conversion; 9 | using MiscUtil.IO; 10 | 11 | namespace AK.Abr 12 | { 13 | public class AbrReader : IAbrReader 14 | { 15 | public IAbrSource Source { get; } 16 | 17 | public AbrReader(IAbrSource source) { 18 | Source = source ?? throw new ArgumentNullException(nameof(source)); 19 | } 20 | 21 | private void ReadCore(CancellationToken cancellationToken) { 22 | var converter = new BigEndianBitConverter(); 23 | using (var fs = Source.OpenRead()) { 24 | var ebr = new EndianBinaryReader(converter, fs); 25 | 26 | int ver = ebr.ReadInt16(); 27 | switch (ver) { 28 | case 1: 29 | this.ReadVer12(ebr, ver, cancellationToken); 30 | break; 31 | 32 | case 2: 33 | this.ReadVer12(ebr, ver, cancellationToken); 34 | break; 35 | 36 | case 6: 37 | this.ReadVer6(ebr, cancellationToken); 38 | break; 39 | 40 | default: 41 | throw new NotSupportedException("Unsupported file version"); 42 | } 43 | } 44 | } 45 | 46 | private static byte[] Unpack(byte[] imgdata) { 47 | using (var input = new MemoryStream(imgdata)) 48 | using (var output = new MemoryStream(imgdata.Length)) { 49 | var reader = new BinaryReader(input); 50 | var writer = new BinaryWriter(output); 51 | 52 | var length = imgdata.Length - sizeof(byte); 53 | while (input.Position < length) { 54 | sbyte count = reader.ReadSByte(); 55 | if (count >= 0) { 56 | writer.Write(reader.ReadBytes(count + 1)); 57 | } 58 | else { 59 | byte value = reader.ReadByte(); 60 | while (count++ <= 0) 61 | writer.Write(value); 62 | } 63 | } 64 | return output.ToArray(); 65 | } 66 | } 67 | 68 | private static BitmapSource CreateImage(int width, int height, byte[] buffer, CancellationToken cancellationToken) { 69 | var bitmap = new WritableBitmapImage(width, height); 70 | bitmap.Lock(); 71 | 72 | try { 73 | int index = 0; 74 | for (int y = 0; y < height; y++) { 75 | cancellationToken.ThrowIfCancellationRequested(); 76 | for (int x = 0; x < width; x++) { 77 | bitmap[x, y] = new Color { A = buffer[index++] }; 78 | } 79 | } 80 | } 81 | finally { 82 | bitmap.Unlock(); 83 | } 84 | 85 | var source = bitmap.BitmapSource; 86 | source.Freeze(); 87 | 88 | return source; 89 | } 90 | 91 | private void ReadVer12(EndianBinaryReader ebr, int ver, CancellationToken cancellationToken) { 92 | int num = ebr.ReadInt16(); 93 | for (int i = 0; i < num; i++) { 94 | cancellationToken.ThrowIfCancellationRequested(); 95 | 96 | int num3 = ebr.ReadInt16(); 97 | int num4 = ebr.ReadInt32(); 98 | switch (num3) { 99 | case 1: 100 | if (ver == 1) { 101 | ebr.ReadBytes(14); 102 | } 103 | if (ver == 2) { 104 | ebr.ReadBytes(num4); 105 | } 106 | break; 107 | 108 | case 2: { 109 | ebr.ReadInt32(); 110 | ebr.ReadInt16(); 111 | if (ver == 1) { 112 | ebr.ReadByte(); 113 | } 114 | if (ver == 2) { 115 | int num5 = ebr.ReadInt32(); 116 | ebr.ReadBytes(num5 * 2); 117 | ebr.ReadBytes(1); 118 | } 119 | ebr.ReadInt16(); 120 | ebr.ReadInt16(); 121 | ebr.ReadInt16(); 122 | ebr.ReadInt16(); 123 | int num6 = ebr.ReadInt32(); 124 | int num7 = ebr.ReadInt32(); 125 | int num8 = ebr.ReadInt32(); 126 | int num9 = ebr.ReadInt32(); 127 | ebr.ReadInt16(); 128 | int num10 = ebr.ReadByte(); 129 | int width = num9 - num7; 130 | int height = num8 - num6; 131 | 132 | byte[] buffer; 133 | if (num10 == 0) { 134 | buffer = ebr.ReadBytes(width * height); 135 | } 136 | else { 137 | int num13 = 0; 138 | for (int k = 0; k < height; k++) { 139 | num13 += ebr.ReadInt16(); 140 | } 141 | 142 | byte[] imgdata = ebr.ReadBytes(num13); 143 | buffer = Unpack(imgdata); 144 | } 145 | 146 | var image = CreateImage(width, height, buffer, cancellationToken); 147 | OnBrushImageReady(image, i); 148 | 149 | break; 150 | } 151 | } 152 | } 153 | } 154 | 155 | private void ReadVer6(EndianBinaryReader ebr, CancellationToken cancellationToken) { 156 | int width = 0; 157 | int height = 0; 158 | int num3 = ebr.ReadInt16(); 159 | ebr.ReadBytes(8); 160 | int num5 = ebr.ReadInt32() + 12; 161 | int index = 0; 162 | while (ebr.BaseStream.Position < (num5 - 1)) { 163 | cancellationToken.ThrowIfCancellationRequested(); 164 | 165 | int num6 = ebr.ReadInt32(); 166 | int num7 = num6; 167 | while ((num7 % 4) != 0) 168 | num7++; 169 | 170 | int num8 = num7 - num6; 171 | ebr.ReadString(); 172 | 173 | switch (num3) { 174 | case 1: 175 | ebr.ReadInt16(); 176 | ebr.ReadInt16(); 177 | ebr.ReadInt16(); 178 | ebr.ReadInt16(); 179 | ebr.ReadInt16(); 180 | int num9 = ebr.ReadInt32(); 181 | int num10 = ebr.ReadInt32(); 182 | int num11 = ebr.ReadInt32(); 183 | width = ebr.ReadInt32() - num10; 184 | height = num11 - num9; 185 | break; 186 | case 2: 187 | ebr.ReadBytes(0x108); 188 | int num13 = ebr.ReadInt32(); 189 | int num14 = ebr.ReadInt32(); 190 | int num15 = ebr.ReadInt32(); 191 | width = ebr.ReadInt32() - num14; 192 | height = num15 - num13; 193 | break; 194 | } 195 | 196 | ebr.ReadInt16(); 197 | 198 | byte[] buffer; 199 | if (ebr.ReadByte() == 0) { 200 | buffer = ebr.ReadBytes(width * height); 201 | } 202 | else { 203 | int num18 = 0; 204 | for (int j = 0; j < height; j++) 205 | num18 += ebr.ReadInt16(); 206 | 207 | byte[] imgdata = ebr.ReadBytes(num18); 208 | buffer = Unpack(imgdata); 209 | } 210 | 211 | var image = CreateImage(width, height, buffer, cancellationToken); 212 | OnBrushImageReady(image, index); 213 | 214 | index++; 215 | 216 | switch (num3) { 217 | case 1: 218 | ebr.ReadBytes(num8); 219 | continue; 220 | case 2: 221 | ebr.ReadBytes(8); 222 | ebr.ReadBytes(num8); 223 | break; 224 | } 225 | } 226 | } 227 | 228 | public Task ReadAsync(CancellationToken cancellationToken) { 229 | return Task.Factory.StartNew( 230 | () => ReadCore(cancellationToken), 231 | cancellationToken, 232 | TaskCreationOptions.LongRunning, 233 | TaskScheduler.Default 234 | ); 235 | } 236 | 237 | public event EventHandler BrushImageReady; 238 | 239 | private void OnBrushImageReady(BitmapSource bitmap, int index) { 240 | BrushImageReady?.Invoke(this, new BrushImageReadyEventArgs(bitmap, index)); 241 | } 242 | } 243 | } -------------------------------------------------------------------------------- /AK.Abr/AbrReaderFactory.cs: -------------------------------------------------------------------------------- 1 | namespace AK.Abr 2 | { 3 | public class AbrReaderFactory : IAbrReaderFactory 4 | { 5 | public IAbrReader GetReader(IAbrSource source) { 6 | return new AbrReader(source); 7 | } 8 | 9 | public override string ToString() { 10 | return GetType().Name; 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /AK.Abr/BrushImageReadyEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Media.Imaging; 3 | 4 | namespace AK.Abr 5 | { 6 | public class BrushImageReadyEventArgs : EventArgs 7 | { 8 | public BitmapSource Bitmap { get; } 9 | public int Index { get; } 10 | 11 | public BrushImageReadyEventArgs(BitmapSource bitmap, int index) { 12 | Bitmap = bitmap; 13 | Index = index; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /AK.Abr/CachingAbrReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using System.Windows.Media.Imaging; 6 | 7 | namespace AK.Abr 8 | { 9 | public class CachingAbrReader : IAbrReader, IDisposable 10 | { 11 | private readonly IAbrReader _reader; 12 | private readonly IBitmapCache _cache; 13 | 14 | public IAbrSource Source => _reader.Source; 15 | 16 | public CachingAbrReader(IAbrReader reader, IBitmapCache cache) { 17 | _cache = cache ?? throw new ArgumentNullException(nameof(cache)); 18 | 19 | _reader = reader ?? throw new ArgumentNullException(nameof(reader)); 20 | _reader.BrushImageReady += _reader_BrushImageReady; 21 | } 22 | 23 | private void _reader_BrushImageReady(object sender, BrushImageReadyEventArgs e) 24 | { 25 | _cache.PutBitmap(Source.Name, Source.Timestamp, e.Index, e.Bitmap); 26 | OnBrushImageReady(e.Bitmap, e.Index); 27 | } 28 | 29 | public Task ReadAsync(CancellationToken cancellationToken) { 30 | if (_cache.ContainsKey(Source.Name, Source.Timestamp)) { 31 | return Task.Factory.StartNew( 32 | () => ReadCached(cancellationToken), 33 | cancellationToken 34 | ); 35 | } 36 | 37 | return _reader.ReadAsync(cancellationToken); 38 | } 39 | 40 | private void ReadCached(CancellationToken cancellationToken) { 41 | int index = 0; 42 | BitmapSource cachedImage; 43 | do { 44 | cancellationToken.ThrowIfCancellationRequested(); 45 | 46 | cachedImage = _cache.GetBitmap(Source.Name, Source.Timestamp, index); 47 | if (cachedImage != null) { 48 | OnBrushImageReady(cachedImage, index); 49 | index++; 50 | } 51 | } while (cachedImage != null); 52 | } 53 | 54 | public event EventHandler BrushImageReady; 55 | 56 | private void OnBrushImageReady(BitmapSource bitmap, int index) { 57 | BrushImageReady?.Invoke(this, new BrushImageReadyEventArgs(bitmap, index)); 58 | } 59 | 60 | public void Dispose() { 61 | if (_reader != null) { 62 | _reader.BrushImageReady -= _reader_BrushImageReady; 63 | } 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /AK.Abr/CachingAbrReaderFactory.cs: -------------------------------------------------------------------------------- 1 | namespace AK.Abr 2 | { 3 | public class CachingAbrReaderFactory : IAbrReaderFactory 4 | { 5 | private readonly IAbrReaderFactory _factory; 6 | private readonly IBitmapCache _cache; 7 | 8 | public CachingAbrReaderFactory(IAbrReaderFactory factory, IBitmapCache cache) { 9 | _factory = factory; 10 | _cache = cache; 11 | } 12 | 13 | public IAbrReader GetReader(IAbrSource source) { 14 | return new CachingAbrReader(_factory.GetReader(source), _cache); 15 | } 16 | 17 | public override string ToString() { 18 | return $"CachingAbrReaderFactory [Cache={_cache.ToString()}]"; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /AK.Abr/DiskBitmapCache.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Windows.Media.Imaging; 5 | 6 | namespace AK.Abr 7 | { 8 | public class DiskBitmapCache : IBitmapCache 9 | { 10 | private readonly string _cacheFolder; 11 | private readonly bool _isPersistent; 12 | private bool _isDisposed; 13 | private readonly object _sync = new object(); 14 | 15 | public string CachePath => _cacheFolder; 16 | 17 | public override string ToString() { 18 | return "DiskCache (" + CachePath + ")"; 19 | } 20 | 21 | public DiskBitmapCache(string cacheFolder = null, bool isPersistent = true) { 22 | _cacheFolder = ResolveCacheFolder(cacheFolder); 23 | _isPersistent = isPersistent; 24 | Directory.CreateDirectory(_cacheFolder); 25 | } 26 | 27 | private string ResolveCacheFolder(string cacheFolder) { 28 | if (String.IsNullOrWhiteSpace(cacheFolder)) 29 | return Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); 30 | 31 | if (cacheFolder.StartsWith(@".\")) 32 | return Path.Combine(Environment.CurrentDirectory, cacheFolder.Substring(2)); 33 | 34 | return cacheFolder; 35 | } 36 | 37 | private void ThrowIfDisposed() { 38 | lock (_sync) { 39 | if (_isDisposed) 40 | throw new ObjectDisposedException("DiskBitmapCache"); 41 | } 42 | } 43 | 44 | protected virtual BitmapEncoder CreateBitmapEncoder() { 45 | return new PngBitmapEncoder(); 46 | } 47 | 48 | protected virtual string GetIndexFileName(int index) { 49 | return index.ToString() + ".png"; 50 | } 51 | 52 | private string GetGroupDirectoryPath(string key) { 53 | var safeKey = Path.GetInvalidFileNameChars().Aggregate(key, (k, c) => k.Replace(c, '_')); 54 | return Path.Combine(_cacheFolder, safeKey); 55 | } 56 | 57 | public bool ContainsKey(string key, long timestamp) { 58 | ThrowIfDisposed(); 59 | 60 | var groupDir = GetGroupDirectoryPath(key); 61 | if (!Directory.Exists(groupDir)) 62 | return false; 63 | 64 | var cacheSlotTimestamp = Directory.GetCreationTime(groupDir).Ticks; 65 | if (cacheSlotTimestamp < timestamp) 66 | return false; 67 | 68 | return true; 69 | } 70 | 71 | public BitmapSource GetBitmap(string key, long timestamp, int index) { 72 | ThrowIfDisposed(); 73 | 74 | var groupDir = GetGroupDirectoryPath(key); 75 | if (!Directory.Exists(groupDir)) 76 | return null; 77 | 78 | var cacheSlotTimestamp = Directory.GetCreationTime(groupDir).Ticks; 79 | if (cacheSlotTimestamp < timestamp) 80 | return null; 81 | 82 | var imageFilePath = Path.Combine(groupDir, GetIndexFileName(index)); 83 | if (File.Exists(imageFilePath)) { 84 | var image = new BitmapImage(new Uri(imageFilePath, UriKind.Absolute)); 85 | image.Freeze(); 86 | return image; 87 | } 88 | 89 | return null; 90 | } 91 | 92 | public void PutBitmap(string key, long timestamp, int index, BitmapSource bitmap) { 93 | ThrowIfDisposed(); 94 | 95 | var groupDir = GetGroupDirectoryPath(key); 96 | if (Directory.Exists(groupDir)) { 97 | var cacheSlotTimestamp = Directory.GetCreationTime(groupDir).Ticks; 98 | if (cacheSlotTimestamp < timestamp) { 99 | Directory.Delete(groupDir); 100 | Directory.CreateDirectory(groupDir); 101 | } 102 | } 103 | else { 104 | Directory.CreateDirectory(groupDir); 105 | } 106 | 107 | var imageFilePath = Path.Combine(groupDir, GetIndexFileName(index)); 108 | var encoder = CreateBitmapEncoder(); 109 | encoder.Frames.Add(BitmapFrame.Create(bitmap)); 110 | using (var fs = File.OpenWrite(imageFilePath)) { 111 | encoder.Save(fs); 112 | } 113 | } 114 | 115 | public void Dispose() { 116 | lock (_sync) { 117 | if (!_isDisposed) { 118 | if (!_isPersistent) { 119 | try { 120 | Directory.Delete(_cacheFolder, true); 121 | } 122 | catch { } 123 | } 124 | _isDisposed = true; 125 | } 126 | } 127 | } 128 | } 129 | } -------------------------------------------------------------------------------- /AK.Abr/FileAbrSource.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace AK.Abr 4 | { 5 | public class FileAbrSource : IAbrSource 6 | { 7 | private readonly string _abrFilePath; 8 | 9 | public FileAbrSource(string abrFilePath) { 10 | if (!File.Exists(abrFilePath)) 11 | throw new FileNotFoundException("Can't find brush file", abrFilePath); 12 | 13 | _abrFilePath = abrFilePath; 14 | Timestamp = File.GetLastWriteTime(_abrFilePath).Ticks; 15 | } 16 | 17 | public string Name => _abrFilePath; 18 | 19 | public long Timestamp { get; } 20 | 21 | public Stream OpenRead() { 22 | return File.OpenRead(_abrFilePath); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /AK.Abr/IAbrReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | namespace AK.Abr 6 | { 7 | public interface IAbrReader 8 | { 9 | Task ReadAsync(CancellationToken cancellationToken); 10 | event EventHandler BrushImageReady; 11 | IAbrSource Source { get; } 12 | } 13 | } -------------------------------------------------------------------------------- /AK.Abr/IAbrReaderFactory.cs: -------------------------------------------------------------------------------- 1 | namespace AK.Abr 2 | { 3 | public interface IAbrReaderFactory 4 | { 5 | IAbrReader GetReader(IAbrSource source); 6 | } 7 | } -------------------------------------------------------------------------------- /AK.Abr/IAbrSource.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace AK.Abr 4 | { 5 | public interface IAbrSource 6 | { 7 | string Name { get; } 8 | long Timestamp { get; } 9 | Stream OpenRead(); 10 | } 11 | } -------------------------------------------------------------------------------- /AK.Abr/IBitmapCache.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Media.Imaging; 3 | 4 | namespace AK.Abr 5 | { 6 | public interface IBitmapCache : IDisposable 7 | { 8 | bool ContainsKey(string key, long timestamp); 9 | BitmapSource GetBitmap(string key, long timestamp, int index); 10 | void PutBitmap(string key, long timestamp, int index, BitmapSource bitmap); 11 | } 12 | } -------------------------------------------------------------------------------- /AK.Abr/MemoryBitmapCache.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Windows.Media.Imaging; 6 | 7 | namespace AK.Abr 8 | { 9 | public class MemoryBitmapCache : IBitmapCache 10 | { 11 | private class CacheItem 12 | { 13 | public long Timestamp { get; } 14 | public Dictionary Elements { get; } 15 | 16 | public CacheItem(long timestamp) { 17 | Timestamp = timestamp; 18 | Elements = new Dictionary(); 19 | } 20 | } 21 | 22 | private readonly Dictionary> _cache = 23 | new Dictionary>(); 24 | 25 | private readonly object _sync = new object(); 26 | private readonly int _capacity; 27 | private bool _isDisposed; 28 | 29 | public MemoryBitmapCache(int capacity) { 30 | _capacity = capacity; 31 | } 32 | 33 | private void ThrowIfDisposed() { 34 | if (_isDisposed) 35 | throw new ObjectDisposedException(nameof(MemoryBitmapCache)); 36 | } 37 | 38 | public bool ContainsKey(string key, long timestamp) { 39 | lock (_sync) { 40 | ThrowIfDisposed(); 41 | 42 | if (_cache.ContainsKey(key)) { 43 | var item = _cache[key]; 44 | return item.Timestamp >= timestamp; 45 | } 46 | return false; 47 | } 48 | } 49 | 50 | public BitmapSource GetBitmap(string key, long timestamp, int index) { 51 | BitmapSource image = null; 52 | lock (_sync) { 53 | ThrowIfDisposed(); 54 | 55 | if (_cache.ContainsKey(key)) { 56 | var item = _cache[key]; 57 | if (item.Timestamp >= timestamp) 58 | item.Elements.TryGetValue(index, out image); 59 | } 60 | } 61 | return image; 62 | } 63 | 64 | private void TrimCache() { 65 | var keyToRemove = _cache.Keys.OrderBy(k => _cache[k].Elements.Count).FirstOrDefault(); 66 | if (keyToRemove != null) { 67 | _cache.Remove(keyToRemove); 68 | } 69 | } 70 | 71 | public void PutBitmap(string key, long timestamp, int index, BitmapSource bitmap) { 72 | lock (_sync) { 73 | ThrowIfDisposed(); 74 | 75 | if (_cache.ContainsKey(key)) { 76 | var item = _cache[key]; 77 | if (item.Timestamp >= timestamp) { 78 | if (item.Elements.ContainsKey(index)) 79 | item.Elements[index] = bitmap; 80 | else 81 | item.Elements.Add(index, bitmap); 82 | } 83 | else { 84 | var newItem = new CacheItem(DateTime.Now.Ticks); 85 | newItem.Elements.Add(index, bitmap); 86 | _cache[key] = newItem; 87 | } 88 | } 89 | else { 90 | var cacheItemsCount = GetItemsCount(); 91 | if (cacheItemsCount + 1 > _capacity) { 92 | TrimCache(); 93 | } 94 | 95 | var newItem = new CacheItem(DateTime.Now.Ticks); 96 | newItem.Elements.Add(index, bitmap); 97 | _cache.Add(key, newItem); 98 | } 99 | } 100 | } 101 | 102 | private int GetItemsCount() { 103 | return _cache.Keys.Select(key => _cache[key].Elements.Count).Sum(); 104 | } 105 | 106 | public override string ToString() { 107 | lock (_sync) { 108 | return $"MemoryCache ({_cache.Keys.Count}:{GetItemsCount()}/{_capacity})"; 109 | } 110 | } 111 | 112 | public void Dispose() { 113 | lock (_sync) { 114 | if (!_isDisposed) { 115 | _cache.Clear(); 116 | _isDisposed = true; 117 | } 118 | } 119 | } 120 | } 121 | } -------------------------------------------------------------------------------- /AK.Abr/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("AK.Abr")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("AK.Abr")] 15 | [assembly: AssemblyCopyright("Copyright © 2012")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // Setting ComVisible to false makes the types in this assembly not visible 20 | // to COM components. If you need to access a type in this assembly from 21 | // COM, set the ComVisible attribute to true on that type. 22 | [assembly: ComVisible(false)] 23 | 24 | //In order to begin building localizable applications, set 25 | //CultureYouAreCodingWith in your .csproj file 26 | //inside a . For example, if you are using US english 27 | //in your source files, set the to en-US. Then uncomment 28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 29 | //the line below to match the UICulture setting in the project file. 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 36 | //(used if a resource is not found in the page, 37 | // or application resource dictionaries) 38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 39 | //(used if a resource is not found in the page, 40 | // app, or any theme specific resource dictionaries) 41 | )] 42 | 43 | 44 | // Version information for an assembly consists of the following four values: 45 | // 46 | // Major Version 47 | // Minor Version 48 | // Build Number 49 | // Revision 50 | // 51 | // You can specify all the values or you can default the Build and Revision Numbers 52 | // by using the '*' as shown below: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /AK.Abr/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace AK.Abr.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AK.Abr.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /AK.Abr/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /AK.Abr/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace AK.Abr.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /AK.Abr/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /AK.Abr/WritableBitmapImage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Windows; 4 | using System.Windows.Media; 5 | using System.Windows.Media.Imaging; 6 | 7 | namespace AK.Abr 8 | { 9 | public class WritableBitmapImage 10 | { 11 | private readonly WriteableBitmap _bitmap; 12 | private bool _locked; 13 | private IntPtr _backBuffer; 14 | private readonly int _bytesPerPixel; 15 | private int _backBufferStride; 16 | private readonly object _syncRoot = new object(); 17 | 18 | public WritableBitmapImage(int width, int height) { 19 | _bitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgra32, null); 20 | _bytesPerPixel = _bitmap.Format.BitsPerPixel / 8; 21 | Width = width; 22 | Height = height; 23 | } 24 | 25 | public int Width { get; } 26 | 27 | public int Height { get; } 28 | 29 | public void Lock() { 30 | lock (_syncRoot) { 31 | if (!_locked) { 32 | _locked = true; 33 | _bitmap.Lock(); 34 | _backBuffer = _bitmap.BackBuffer; 35 | _backBufferStride = _bitmap.BackBufferStride; 36 | } 37 | } 38 | } 39 | 40 | public void Unlock() { 41 | if (_locked) { 42 | lock (_syncRoot) { 43 | if (_locked) { 44 | _bitmap.AddDirtyRect(new Int32Rect(0, 0, Width, Height)); 45 | _bitmap.Unlock(); 46 | _locked = false; 47 | } 48 | } 49 | } 50 | } 51 | 52 | private byte[] ColorToBytes(Color color) { 53 | return new byte[] { color.B, color.G, color.R, color.A }; 54 | } 55 | 56 | private Color ColorFromBytes(params byte[] data) { 57 | return new Color { B = data[0], G = data[1], R = data[2], A = data[3] }; 58 | } 59 | 60 | private Color GetPixelColor(int x, int y) { 61 | if (_locked) { 62 | int offset = (int) (y * _backBufferStride + x * _bytesPerPixel); 63 | unsafe { 64 | byte* pbuff = (byte*) _backBuffer.ToPointer(); 65 | return ColorFromBytes(pbuff[offset], pbuff[offset + 1], pbuff[offset + 2], pbuff[offset + 3]); 66 | } 67 | } 68 | else { 69 | byte[] pixelBuffer = new byte[_bytesPerPixel]; 70 | Int32Rect rect = new Int32Rect(x, y, 1, 1); 71 | _bitmap.CopyPixels(rect, pixelBuffer, _bytesPerPixel, 0); 72 | return ColorFromBytes(pixelBuffer); 73 | } 74 | } 75 | 76 | private void SetPixelColor(int x, int y, Color color) { 77 | var colorBytes = ColorToBytes(color); 78 | if (_locked) { 79 | int offset = (int) (y * _backBufferStride + x * _bytesPerPixel); 80 | unsafe { 81 | byte* pbuff = (byte*) _backBuffer.ToPointer(); 82 | pbuff[offset] = colorBytes[0]; 83 | pbuff[offset + 1] = colorBytes[1]; 84 | pbuff[offset + 2] = colorBytes[2]; 85 | pbuff[offset + 3] = colorBytes[3]; 86 | } 87 | } 88 | else { 89 | Int32Rect rect = new Int32Rect(x, y, 1, 1); 90 | _bitmap.WritePixels(rect, colorBytes, _bytesPerPixel, 0); 91 | } 92 | } 93 | 94 | public Color this[int x, int y] { 95 | get => GetPixelColor(x, y); 96 | set => SetPixelColor(x, y, value); 97 | } 98 | 99 | public BitmapSource BitmapSource => _bitmap; 100 | 101 | public void Dispose() { } 102 | } 103 | } -------------------------------------------------------------------------------- /AbrViewer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.1267 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbrViewer", "AbrViewer\AbrViewer.csproj", "{6C502DE0-4D12-494C-90C7-58B7B22051AE}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AK.Abr", "AK.Abr\AK.Abr.csproj", "{5BAEF14C-17BB-4E1C-8233-A2BA5ABDDD27}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|Mixed Platforms = Debug|Mixed Platforms 14 | Release|Any CPU = Release|Any CPU 15 | Release|Mixed Platforms = Release|Mixed Platforms 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {6C502DE0-4D12-494C-90C7-58B7B22051AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {6C502DE0-4D12-494C-90C7-58B7B22051AE}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {6C502DE0-4D12-494C-90C7-58B7B22051AE}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 21 | {6C502DE0-4D12-494C-90C7-58B7B22051AE}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 22 | {6C502DE0-4D12-494C-90C7-58B7B22051AE}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {6C502DE0-4D12-494C-90C7-58B7B22051AE}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {6C502DE0-4D12-494C-90C7-58B7B22051AE}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 25 | {6C502DE0-4D12-494C-90C7-58B7B22051AE}.Release|Mixed Platforms.Build.0 = Release|Any CPU 26 | {5BAEF14C-17BB-4E1C-8233-A2BA5ABDDD27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {5BAEF14C-17BB-4E1C-8233-A2BA5ABDDD27}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {5BAEF14C-17BB-4E1C-8233-A2BA5ABDDD27}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 29 | {5BAEF14C-17BB-4E1C-8233-A2BA5ABDDD27}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 30 | {5BAEF14C-17BB-4E1C-8233-A2BA5ABDDD27}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {5BAEF14C-17BB-4E1C-8233-A2BA5ABDDD27}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {5BAEF14C-17BB-4E1C-8233-A2BA5ABDDD27}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 33 | {5BAEF14C-17BB-4E1C-8233-A2BA5ABDDD27}.Release|Mixed Platforms.Build.0 = Release|Any CPU 34 | EndGlobalSection 35 | GlobalSection(SolutionProperties) = preSolution 36 | HideSolutionNode = FALSE 37 | EndGlobalSection 38 | GlobalSection(ExtensibilityGlobals) = postSolution 39 | SolutionGuid = {BDC6B8A1-6474-4C9A-9801-2C47D64857C8} 40 | EndGlobalSection 41 | EndGlobal 42 | -------------------------------------------------------------------------------- /AbrViewer.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | True -------------------------------------------------------------------------------- /AbrViewer/AboutWindow.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | 10 | 11 | Version 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /AbrViewer/AboutWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Input; 3 | 4 | namespace AbrViewer 5 | { 6 | public partial class AboutWindow : Window 7 | { 8 | public AboutWindow() { 9 | InitializeComponent(); 10 | } 11 | 12 | private void Window_MouseDown(object sender, MouseButtonEventArgs e) { 13 | Close(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AbrViewer/AbrViewer.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x86 7 | 8.0.30703 8 | 2.0 9 | {6C502DE0-4D12-494C-90C7-58B7B22051AE} 10 | WinExe 11 | Properties 12 | AbrViewer 13 | AbrViewer 14 | v4.5.2 15 | 16 | 17 | 512 18 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 19 | 4 20 | 21 | 22 | 23 | 24 | AbrViewer.App 25 | 26 | 27 | App.ico 28 | 29 | 30 | AnyCPU 31 | bin\Debug\ 32 | latest 33 | false 34 | DEBUG 35 | 36 | 37 | AnyCPU 38 | bin\Release\ 39 | false 40 | 41 | 42 | 43 | ..\packages\CommonServiceLocator.2.0.2\lib\net45\CommonServiceLocator.dll 44 | 45 | 46 | ..\packages\MvvmLightLibs.5.4.1.1\lib\net45\GalaSoft.MvvmLight.dll 47 | 48 | 49 | ..\packages\MvvmLightLibs.5.4.1.1\lib\net45\GalaSoft.MvvmLight.Extras.dll 50 | 51 | 52 | ..\packages\MvvmLightLibs.5.4.1.1\lib\net45\GalaSoft.MvvmLight.Platform.dll 53 | 54 | 55 | ..\packages\PropertyChanged.Fody.2.6.1\lib\net452\PropertyChanged.dll 56 | 57 | 58 | 59 | 60 | ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll 61 | 62 | 63 | 64 | ..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll 65 | 66 | 67 | 68 | ..\packages\MvvmLightLibs.5.4.1.1\lib\net45\System.Windows.Interactivity.dll 69 | 70 | 71 | 72 | 73 | 4.0 74 | 75 | 76 | ..\packages\Unity.Abstractions.5.11.2\lib\net45\Unity.Abstractions.dll 77 | 78 | 79 | ..\packages\Unity.Configuration.5.11.2\lib\net45\Unity.Configuration.dll 80 | 81 | 82 | ..\packages\Unity.Container.5.11.5\lib\net45\Unity.Container.dll 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | MSBuild:Compile 91 | Designer 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | MSBuild:Compile 106 | Designer 107 | 108 | 109 | Designer 110 | MSBuild:Compile 111 | 112 | 113 | MSBuild:Compile 114 | Designer 115 | 116 | 117 | AboutWindow.xaml 118 | 119 | 120 | App.xaml 121 | Code 122 | 123 | 124 | 125 | BrushPreviewWindow.xaml 126 | 127 | 128 | 129 | 130 | 131 | MainWindow.xaml 132 | Code 133 | 134 | 135 | 136 | 137 | Code 138 | 139 | 140 | True 141 | True 142 | Resources.resx 143 | 144 | 145 | True 146 | Settings.settings 147 | True 148 | 149 | 150 | ResXFileCodeGenerator 151 | Resources.Designer.cs 152 | 153 | 154 | Designer 155 | 156 | 157 | Designer 158 | 159 | 160 | SettingsSingleFileGenerator 161 | Settings.Designer.cs 162 | 163 | 164 | 165 | 166 | 167 | {5BAEF14C-17BB-4E1C-8233-A2BA5ABDDD27} 168 | AK.Abr 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | Designer 177 | 178 | 179 | 180 | 181 | 182 | 183 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 184 | 185 | 186 | 187 | 188 | 195 | -------------------------------------------------------------------------------- /AbrViewer/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /AbrViewer/App.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alex-kabin/abr-viewer/2b968d495d35b8e9f6bbfe87dc493df324a1a4c5/AbrViewer/App.ico -------------------------------------------------------------------------------- /AbrViewer/App.xaml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /AbrViewer/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Linq; 5 | using System.Windows; 6 | using AbrViewer.Services; 7 | using AbrViewer.Support; 8 | using GalaSoft.MvvmLight.Threading; 9 | using Microsoft.Practices.Unity.Configuration; 10 | using Unity; 11 | using Unity.Lifetime; 12 | 13 | namespace AbrViewer 14 | { 15 | /// 16 | /// Interaction logic for App.xaml 17 | /// 18 | public partial class App : Application 19 | { 20 | private IUnityContainer _container; 21 | 22 | private void InitializeContainer() { 23 | _container = new UnityContainer() 24 | .EnableDiagnostic() 25 | .EnableLazy() 26 | .LoadConfiguration() 27 | .RegisterSingleton(typeof(IDialogService), typeof(DialogService)) 28 | .RegisterSingleton(typeof(IRootWindow), typeof(MainWindow)); 29 | _container.BuildUp(this); 30 | } 31 | 32 | protected override void OnStartup(StartupEventArgs e) { 33 | base.OnStartup(e); 34 | DispatcherHelper.Initialize(); 35 | try { 36 | InitializeContainer(); 37 | } 38 | catch (Exception ex) { 39 | MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); 40 | Shutdown(); 41 | return; 42 | } 43 | MainWindow?.Show(); 44 | } 45 | 46 | [Dependency] 47 | public IRootWindow RootWindow { 48 | set => MainWindow = (Window)value; 49 | } 50 | 51 | protected override void OnExit(ExitEventArgs e) { 52 | _container.Dispose(); 53 | base.OnExit(e); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /AbrViewer/Behaviors/DoubleClickCommandBehavior.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Input; 3 | using System.Windows.Interactivity; 4 | 5 | namespace AbrViewer.Behaviors 6 | { 7 | public class DoubleClickCommandBehavior : Behavior 8 | { 9 | public static readonly DependencyProperty CommandProperty = 10 | DependencyProperty.Register( 11 | "Command", 12 | typeof(ICommand), 13 | typeof(DoubleClickCommandBehavior), 14 | new FrameworkPropertyMetadata(default(ICommand)) 15 | ); 16 | 17 | public ICommand Command { 18 | get => (ICommand)GetValue(CommandProperty); 19 | set => SetValue(CommandProperty, value); 20 | } 21 | 22 | public static readonly DependencyProperty CommandParameterProperty = 23 | DependencyProperty.Register( 24 | "CommandParameter", 25 | typeof(object), 26 | typeof(DoubleClickCommandBehavior), 27 | new FrameworkPropertyMetadata(default) 28 | ); 29 | 30 | public object CommandParameter { 31 | get => (object)GetValue(CommandParameterProperty); 32 | set => SetValue(CommandParameterProperty, value); 33 | } 34 | 35 | protected override void OnAttached() { 36 | AssociatedObject.MouseLeftButtonDown += AssociatedObject_MouseLeftButtonDown; 37 | } 38 | 39 | protected override void OnDetaching() { 40 | AssociatedObject.MouseLeftButtonDown -= AssociatedObject_MouseLeftButtonDown; 41 | } 42 | 43 | private void AssociatedObject_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { 44 | if (e.ClickCount != 2) 45 | return; 46 | 47 | if (Command != null && Command.CanExecute(CommandParameter)) { 48 | Command.Execute(CommandParameter); 49 | } 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /AbrViewer/Behaviors/KeyCommandBehavior.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Input; 3 | using System.Windows.Interactivity; 4 | 5 | namespace AbrViewer.Behaviors 6 | { 7 | public class KeyCommandBehavior : Behavior 8 | { 9 | public static readonly DependencyProperty CommandProperty = 10 | DependencyProperty.Register( 11 | "Command", 12 | typeof(ICommand), 13 | typeof(KeyCommandBehavior), 14 | new FrameworkPropertyMetadata(default(ICommand)) 15 | ); 16 | 17 | public ICommand Command { 18 | get => (ICommand)GetValue(CommandProperty); 19 | set => SetValue(CommandProperty, value); 20 | } 21 | 22 | public static readonly DependencyProperty CommandParameterProperty = 23 | DependencyProperty.Register( 24 | "CommandParameter", 25 | typeof(object), 26 | typeof(KeyCommandBehavior), 27 | new FrameworkPropertyMetadata(default) 28 | ); 29 | 30 | public object CommandParameter { 31 | get => (object)GetValue(CommandParameterProperty); 32 | set => SetValue(CommandParameterProperty, value); 33 | } 34 | 35 | 36 | public static readonly DependencyProperty KeyProperty = 37 | DependencyProperty.Register( 38 | "Key", 39 | typeof(Key), 40 | typeof(KeyCommandBehavior), 41 | new PropertyMetadata(default(Key)) 42 | ); 43 | 44 | public Key Key { 45 | get => (Key)GetValue(KeyProperty); 46 | set => SetValue(KeyProperty, value); 47 | } 48 | 49 | protected override void OnAttached() { 50 | AssociatedObject.KeyUp += AssociatedObject_KeyUp; 51 | } 52 | 53 | protected override void OnDetaching() { 54 | AssociatedObject.KeyUp -= AssociatedObject_KeyUp; 55 | } 56 | 57 | private void AssociatedObject_KeyUp(object sender, KeyEventArgs e) { 58 | if(e.Key != Key) 59 | return; 60 | 61 | if (Command != null && Command.CanExecute(CommandParameter)) { 62 | Command.Execute(CommandParameter); 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /AbrViewer/BrushPreviewWindow.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /AbrViewer/BrushPreviewWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Windows; 6 | using System.Windows.Controls; 7 | using System.Windows.Data; 8 | using System.Windows.Documents; 9 | using System.Windows.Input; 10 | using System.Windows.Media; 11 | using System.Windows.Media.Imaging; 12 | using System.Windows.Shapes; 13 | 14 | namespace AbrViewer 15 | { 16 | /// 17 | /// Interaction logic for BrushPreviewWindow.xaml 18 | /// 19 | public partial class BrushPreviewWindow : Window 20 | { 21 | public BrushPreviewWindow() 22 | { 23 | InitializeComponent(); 24 | } 25 | 26 | private void Window_KeyDown(object sender, KeyEventArgs e) 27 | { 28 | if(e.Key == Key.Escape) 29 | Close(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /AbrViewer/Config.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Runtime.Serialization; 3 | using System.Windows; 4 | 5 | namespace AbrViewer 6 | { 7 | [DataContract] 8 | public class Config : INotifyPropertyChanged 9 | { 10 | public event PropertyChangedEventHandler PropertyChanged; 11 | 12 | [DataMember] public bool ExitOnEsc { get; set; } = true; 13 | 14 | [DataMember] public int ThumbnailSize { get; set; } = 120; 15 | 16 | [DataMember] public int WindowWidth { get; set; } = 800; 17 | 18 | [DataMember] public int WindowHeight { get; set; } = 600; 19 | 20 | [DataMember] public WindowState WindowState { get; set; } = WindowState.Normal; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /AbrViewer/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /AbrViewer/FodyWeavers.xsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Used to control if the On_PropertyName_Changed feature is enabled. 12 | 13 | 14 | 15 | 16 | Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form. 17 | 18 | 19 | 20 | 21 | Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project. 22 | 23 | 24 | 25 | 26 | Used to control if equality checks should use the Equals method resolved from the base class. 27 | 28 | 29 | 30 | 31 | Used to control if equality checks should use the static Equals method resolved from the base class. 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. 40 | 41 | 42 | 43 | 44 | A comma-separated list of error codes that can be safely ignored in assembly verification. 45 | 46 | 47 | 48 | 49 | 'false' to turn off automatic generation of the XML Schema file. 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /AbrViewer/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |