├── .gitattributes ├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── img ├── example_bitmap.png ├── example_level.png └── example_tiles.png └── src ├── App.xaml ├── App.xaml.cs ├── GBAC.csproj ├── GBAC.sln ├── MVVM ├── AsyncRelayCommand.cs ├── BaseRelayCommand.cs ├── BaseViewModel.cs └── RelayCommand.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Properties └── AssemblyInfo.cs ├── Services ├── BrowseService.cs └── MessageService.cs ├── UI ├── AttachedProperties │ └── ButtonAssist.cs ├── Controls │ ├── InfoIcon.xaml │ ├── InfoIcon.xaml.cs │ └── NoResizeTextBox.cs ├── Converters │ ├── BaseValueConverter.cs │ ├── BooleanToVisibilityConverter.cs │ ├── BooleanToVisibilityHiddenConverter.cs │ ├── InvertedBooleanConverter.cs │ ├── InvertedBooleanToVisibilityConverter.cs │ ├── InvertedObjectNullToVisibilityConverter.cs │ ├── MultiplyIntConverter.cs │ └── UintToHexStringConverter.cs └── Resources │ ├── Resources.Margins.xaml │ ├── Styles.Button.xaml │ ├── Styles.ItemsControl.xaml │ ├── Styles.ScrollViewer.xaml │ ├── Styles.TextBlock.xaml │ ├── Styles.ToolTip.xaml │ └── Theme.RoundedCorners.xaml └── ViewModels ├── CompressedDataViewModel.cs ├── CompressionViewModel.cs ├── FileDataProvider.cs ├── InfoItemViewModel.cs └── MainWindowViewModel.cs /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.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/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 298 | *.vbp 299 | 300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 301 | *.dsw 302 | *.dsp 303 | 304 | # Visual Studio 6 technical files 305 | *.ncb 306 | *.aps 307 | 308 | # Visual Studio LightSwitch build output 309 | **/*.HTMLClient/GeneratedArtifacts 310 | **/*.DesktopClient/GeneratedArtifacts 311 | **/*.DesktopClient/ModelManifest.xml 312 | **/*.Server/GeneratedArtifacts 313 | **/*.Server/ModelManifest.xml 314 | _Pvt_Extensions 315 | 316 | # Paket dependency manager 317 | .paket/paket.exe 318 | paket-files/ 319 | 320 | # FAKE - F# Make 321 | .fake/ 322 | 323 | # CodeRush personal settings 324 | .cr/personal 325 | 326 | # Python Tools for Visual Studio (PTVS) 327 | __pycache__/ 328 | *.pyc 329 | 330 | # Cake - Uncomment if you are using it 331 | # tools/** 332 | # !tools/packages.config 333 | 334 | # Tabs Studio 335 | *.tss 336 | 337 | # Telerik's JustMock configuration file 338 | *.jmconfig 339 | 340 | # BizTalk build output 341 | *.btp.cs 342 | *.btm.cs 343 | *.odx.cs 344 | *.xsd.cs 345 | 346 | # OpenCover UI analysis results 347 | OpenCover/ 348 | 349 | # Azure Stream Analytics local run output 350 | ASALocalRun/ 351 | 352 | # MSBuild Binary and Structured Log 353 | *.binlog 354 | 355 | # NVidia Nsight GPU debugger configuration file 356 | *.nvuser 357 | 358 | # MFractors (Xamarin productivity tool) working folder 359 | .mfractor/ 360 | 361 | # Local History for Visual Studio 362 | .localhistory/ 363 | 364 | # Visual Studio History (VSHistory) files 365 | .vshistory/ 366 | 367 | # BeatPulse healthcheck temp database 368 | healthchecksdb 369 | 370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 371 | MigrationBackup/ 372 | 373 | # Ionide (cross platform F# VS Code tools) working folder 374 | .ionide/ 375 | 376 | # Fody - auto-generated XML schema 377 | FodyWeavers.xsd 378 | 379 | # VS Code files for those working on multiple tools 380 | .vscode/* 381 | !.vscode/settings.json 382 | !.vscode/tasks.json 383 | !.vscode/launch.json 384 | !.vscode/extensions.json 385 | *.code-workspace 386 | 387 | # Local History for Visual Studio Code 388 | .history/ 389 | 390 | # Windows Installer files from build outputs 391 | *.cab 392 | *.msi 393 | *.msix 394 | *.msm 395 | *.msp 396 | 397 | # JetBrains Rider 398 | *.sln.iml 399 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "submodules/BinarySerializer"] 2 | path = submodules/BinarySerializer 3 | url = https://github.com/BinarySerializer/BinarySerializer 4 | [submodule "submodules/BinarySerializer.Nintendo"] 5 | path = submodules/BinarySerializer.Nintendo 6 | url = https://github.com/BinarySerializer/BinarySerializer.Nintendo 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 RayCarrot 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GBAC - GBA Compressed Data Finder 2 | GBAC is a tool for easily finding compressed data in a GBA ROM. It allows searching the file for compressed data and visualizing the data as a palette, tiles and map. It can also be used to replace compressed data by importing it. 3 | 4 | Currently importing Huffman compressed data is not supported. If data is compressed multiple times, such as LZSS+Huffman, only the first compression layer will be decompressed. 5 | 6 | ## Screenshots 7 | ![Tiles](img/example_tiles.png) 8 | ![Level](img/example_level.png) 9 | ![Level](img/example_bitmap.png) 10 | -------------------------------------------------------------------------------- /img/example_bitmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayCarrot/GBAC/14c07b4e61250f57ebec826009e6769f85970879/img/example_bitmap.png -------------------------------------------------------------------------------- /img/example_level.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayCarrot/GBAC/14c07b4e61250f57ebec826009e6769f85970879/img/example_level.png -------------------------------------------------------------------------------- /img/example_tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayCarrot/GBAC/14c07b4e61250f57ebec826009e6769f85970879/img/example_tiles.png -------------------------------------------------------------------------------- /src/App.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace GBAC 4 | { 5 | /// 6 | /// Interaction logic for App.xaml 7 | /// 8 | public partial class App : Application 9 | { 10 | 11 | } 12 | } -------------------------------------------------------------------------------- /src/GBAC.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | net472 7 | WinExe 8 | 10.0 9 | true 10 | enable 11 | AnyCPU 12 | true 13 | 14 | true 15 | 16 | 17 | 18 | 19 | 20 | false 21 | 22 | 23 | GBAC 24 | GBAC 25 | 1.2.0.0 26 | RayCarrot 27 | GBAC 28 | 29 | 30 | 31 | 32 | none 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | runtime; build; native; contentfiles; analyzers; buildtransitive 58 | all 59 | 60 | 61 | 62 | 63 | 64 | all 65 | runtime; build; native; contentfiles; analyzers; buildtransitive 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/GBAC.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.32126.317 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GBAC", "GBAC.csproj", "{B7AD5EDA-D73B-4EE9-B75A-E58F6571D9AE}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Binary", "Binary", "{526A0025-6F08-423F-9263-A735F2A5E952}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BinarySerializer", "..\submodules\BinarySerializer\src\BinarySerializer.csproj", "{DFB46994-134B-4639-82AE-E4E91095B8C6}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BinarySerializer.Nintendo", "..\submodules\BinarySerializer.Nintendo\src\BinarySerializer.Nintendo.csproj", "{BE94CF4F-F63F-4A3A-BCC0-71C6C730D0E8}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {B7AD5EDA-D73B-4EE9-B75A-E58F6571D9AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {B7AD5EDA-D73B-4EE9-B75A-E58F6571D9AE}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {B7AD5EDA-D73B-4EE9-B75A-E58F6571D9AE}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {B7AD5EDA-D73B-4EE9-B75A-E58F6571D9AE}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {DFB46994-134B-4639-82AE-E4E91095B8C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {DFB46994-134B-4639-82AE-E4E91095B8C6}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {DFB46994-134B-4639-82AE-E4E91095B8C6}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {DFB46994-134B-4639-82AE-E4E91095B8C6}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {BE94CF4F-F63F-4A3A-BCC0-71C6C730D0E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {BE94CF4F-F63F-4A3A-BCC0-71C6C730D0E8}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {BE94CF4F-F63F-4A3A-BCC0-71C6C730D0E8}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {BE94CF4F-F63F-4A3A-BCC0-71C6C730D0E8}.Release|Any CPU.Build.0 = Release|Any CPU 32 | EndGlobalSection 33 | GlobalSection(SolutionProperties) = preSolution 34 | HideSolutionNode = FALSE 35 | EndGlobalSection 36 | GlobalSection(NestedProjects) = preSolution 37 | {DFB46994-134B-4639-82AE-E4E91095B8C6} = {526A0025-6F08-423F-9263-A735F2A5E952} 38 | {BE94CF4F-F63F-4A3A-BCC0-71C6C730D0E8} = {526A0025-6F08-423F-9263-A735F2A5E952} 39 | EndGlobalSection 40 | GlobalSection(ExtensibilityGlobals) = postSolution 41 | SolutionGuid = {86E73711-779D-430B-B111-7188FED80D96} 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /src/MVVM/AsyncRelayCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace GBAC; 5 | 6 | /// 7 | /// A RelayCommand to use for async Tasks 8 | /// 9 | public class AsyncRelayCommand : BaseRelayCommand 10 | { 11 | #region Constructors 12 | 13 | /// 14 | /// Constructor for a function with no parameters 15 | /// 16 | /// The function to associate with this RelayCommand 17 | public AsyncRelayCommand(Func func) 18 | { 19 | CommandFunction = async _ => await func(); 20 | } 21 | 22 | /// 23 | /// Constructor for a function with no parameters and a value indicating if it can execute 24 | /// 25 | /// The function to associate with this RelayCommand 26 | /// Determines if the command can be executed 27 | public AsyncRelayCommand(Func func, bool canExecute) : base(canExecute) 28 | { 29 | CommandFunction = async _ => await func(); 30 | } 31 | 32 | /// 33 | /// Constructor for a function with a parameter 34 | /// 35 | /// The function to associate with this RelayCommand 36 | public AsyncRelayCommand(Func func) 37 | { 38 | CommandFunction = func; 39 | } 40 | 41 | /// 42 | /// Constructor for a function with a parameter and a value indicating if it can execute 43 | /// 44 | /// The function to associate with this RelayCommand 45 | /// Determines if the command can be executed 46 | public AsyncRelayCommand(Func func, bool canExecute) : base(canExecute) 47 | { 48 | CommandFunction = func; 49 | } 50 | 51 | #endregion 52 | 53 | #region Public Properties 54 | 55 | /// 56 | /// The function associated with this RelayCommand 57 | /// 58 | public virtual Func CommandFunction { get; } 59 | 60 | #endregion 61 | 62 | #region Public Methods 63 | 64 | /// 65 | /// Execute the command 66 | /// 67 | /// Optional parameters to pass in 68 | public override async void Execute(object? parameter = null) => await ExecuteAsync(parameter); 69 | 70 | /// 71 | /// Execute the command async 72 | /// 73 | /// Optional parameters to pass in 74 | /// The task 75 | public async Task ExecuteAsync(object? parameter = null) 76 | { 77 | // Do not run if the command can not execute 78 | if (!CanExecuteCommand) 79 | return; 80 | 81 | // The command can not execute while running 82 | CanExecuteCommand = false; 83 | 84 | try 85 | { 86 | // Run the command 87 | await CommandFunction(parameter); 88 | } 89 | finally 90 | { 91 | // Flag that the command can now execute again 92 | CanExecuteCommand = true; 93 | } 94 | } 95 | 96 | #endregion 97 | } -------------------------------------------------------------------------------- /src/MVVM/BaseRelayCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Input; 3 | 4 | namespace GBAC; 5 | 6 | /// 7 | /// A base RelayCommand to use for RelayCommands 8 | /// 9 | public abstract class BaseRelayCommand : ICommand 10 | { 11 | #region Constructors 12 | 13 | /// 14 | /// Default constructor 15 | /// 16 | protected BaseRelayCommand() 17 | { 18 | _canExecute = true; 19 | } 20 | 21 | /// 22 | /// Default constructor 23 | /// 24 | /// Determines if the command can be executed 25 | protected BaseRelayCommand(bool canExecute) 26 | { 27 | _canExecute = canExecute; 28 | } 29 | 30 | #endregion 31 | 32 | #region Private Fields 33 | 34 | /// 35 | /// Determines if the command can execute 36 | /// 37 | private bool _canExecute; 38 | 39 | #endregion 40 | 41 | #region Public Properties 42 | 43 | /// 44 | /// True if the command can execute, false if not 45 | /// 46 | public virtual bool CanExecuteCommand 47 | { 48 | get => _canExecute; 49 | set => SetCanExecute(value); 50 | } 51 | 52 | #endregion 53 | 54 | #region Public Methods 55 | 56 | /// 57 | /// Changes the state determining if the command can execute 58 | /// 59 | /// True if the command can execute 60 | public virtual void SetCanExecute(bool value) 61 | { 62 | _canExecute = value; 63 | CanExecuteChanged?.Invoke(this, EventArgs.Empty); 64 | } 65 | 66 | /// 67 | /// Get a boolean determining if the command can execute 68 | /// 69 | /// Optional parameter to pass in 70 | /// 71 | public virtual bool CanExecute(object? parameter = null) => _canExecute; 72 | 73 | /// 74 | /// Execute the command 75 | /// 76 | /// Optional parameters to pass in 77 | public abstract void Execute(object? parameter = null); 78 | 79 | #endregion 80 | 81 | #region Events 82 | 83 | /// 84 | /// Fires when the state determining if the command can execute has changed 85 | /// 86 | public event EventHandler? CanExecuteChanged; 87 | 88 | #endregion 89 | } -------------------------------------------------------------------------------- /src/MVVM/BaseViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Runtime.CompilerServices; 3 | 4 | namespace GBAC; 5 | 6 | public class BaseViewModel : INotifyPropertyChanged 7 | { 8 | public event PropertyChangedEventHandler? PropertyChanged; 9 | 10 | protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) => 11 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 12 | } -------------------------------------------------------------------------------- /src/MVVM/RelayCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GBAC; 4 | 5 | /// 6 | /// A RelayCommand to use for standard commands 7 | /// 8 | public class RelayCommand : BaseRelayCommand 9 | { 10 | #region Constructors 11 | 12 | /// 13 | /// Constructor for an action with no parameters 14 | /// 15 | /// The action to associate with this RelayCommand 16 | public RelayCommand(Action action) 17 | { 18 | CommandAction = _ => action(); 19 | } 20 | 21 | /// 22 | /// Constructor for an action with no parameters and a value indicating if it can execute 23 | /// 24 | /// The action to associate with this RelayCommand 25 | /// Determines if the command can be executed 26 | public RelayCommand(Action action, bool canExecute) : base(canExecute) 27 | { 28 | CommandAction = _ => action(); 29 | } 30 | 31 | /// 32 | /// Constructor for an action with a parameter 33 | /// 34 | /// The action to associate with this RelayCommand 35 | public RelayCommand(Action action) 36 | { 37 | CommandAction = action; 38 | } 39 | 40 | /// 41 | /// Constructor for an action with a parameter and a value indicating if it can execute 42 | /// 43 | /// The action to associate with this RelayCommand 44 | /// Determines if the command can be executed 45 | public RelayCommand(Action action, bool canExecute) : base(canExecute) 46 | { 47 | CommandAction = action; 48 | } 49 | 50 | #endregion 51 | 52 | #region Public Properties 53 | 54 | /// 55 | /// The action associated with this RelayCommand 56 | /// 57 | public virtual Action CommandAction { get; } 58 | 59 | #endregion 60 | 61 | #region Public Methods 62 | 63 | /// 64 | /// Execute the command 65 | /// 66 | /// Optional parameters to pass in 67 | public override void Execute(object? parameter = null) 68 | { 69 | if (!CanExecuteCommand) 70 | return; 71 | 72 | // Run the command 73 | CommandAction(parameter); 74 | } 75 | 76 | #endregion 77 | } -------------------------------------------------------------------------------- /src/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 51 | 54 | 55 |