├── .gitattributes ├── .github └── ISSUE_TEMPLATE │ └── bug_report.md ├── .gitignore ├── IMLCGui.sln ├── IMLCGui ├── App.config ├── App.xaml ├── App.xaml.cs ├── AutoUpdater.cs ├── CustomConfig.cs ├── DownloadManager.cs ├── FileUtils.cs ├── GitHubAPI.cs ├── IMLCGui.csproj ├── LatencyRow.xaml ├── LatencyRow.xaml.cs ├── Logger.cs ├── MLCProcess.cs ├── MLCProcessManager.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Resources │ └── ram.ico └── packages.config ├── LICENSE └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG] " 5 | labels: bug 6 | assignees: FarisR99 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behaviour: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. See error 18 | 19 | **Logs** 20 | If applicable, please paste and format the most recent output in the log file located in the same directory as the executable. 21 | 22 | **Screenshots** 23 | If applicable, add screenshots to help explain your problem. 24 | 25 | **Additional Information:** 26 | - Operating System: 27 | - CPU: 28 | - Software Version [e.g. 1.0.0]: 29 | -------------------------------------------------------------------------------- /.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 | *.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 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 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 LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd 364 | 365 | # IMLCGui files 366 | **/IMLCGui.exe 367 | **/IMLCGui.exe.config 368 | **/imlcgui.log 369 | **/mlc 370 | -------------------------------------------------------------------------------- /IMLCGui.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.31911.260 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IMLCGui", "IMLCGui\IMLCGui.csproj", "{C8AE79D9-F822-4495-8930-47027624D17A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C8AE79D9-F822-4495-8930-47027624D17A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {C8AE79D9-F822-4495-8930-47027624D17A}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {C8AE79D9-F822-4495-8930-47027624D17A}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {C8AE79D9-F822-4495-8930-47027624D17A}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {35CEAC3D-60E5-439C-8055-33D7D4A140D2} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /IMLCGui/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /IMLCGui/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /IMLCGui/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace IMLCGui 4 | { 5 | /// 6 | /// Interaction logic for App.xaml 7 | /// 8 | public partial class App : Application 9 | { 10 | /// 11 | /// Application Entry Point. 12 | /// 13 | [System.STAThreadAttribute()] 14 | [System.Diagnostics.DebuggerNonUserCodeAttribute()] 15 | public static void Main() 16 | { 17 | var application = new App(); 18 | application.InitializeComponent(); 19 | application.Run(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /IMLCGui/AutoUpdater.cs: -------------------------------------------------------------------------------- 1 | using IMLCGui.GitHub; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Reflection; 6 | using System.Threading.Tasks; 7 | 8 | namespace IMLCGui 9 | { 10 | internal class AutoUpdater 11 | { 12 | private readonly GitHubClient _client; 13 | public readonly Version CurrentVersion; 14 | 15 | public Release LatestRelease { get; private set; } = null; 16 | public volatile bool CheckingForUpdate = false; 17 | 18 | public AutoUpdater() 19 | { 20 | this._client = new GitHubClient("IMLCGui", (GetCurrentVersion() ?? new Version(1, 0, 0)).ToString()); 21 | this._client.SetRequestTimeout(TimeSpan.FromSeconds(2)); 22 | 23 | this.CurrentVersion = GetCurrentVersion(); 24 | } 25 | 26 | public async Task CheckForUpdates() 27 | { 28 | this.LatestRelease = null; 29 | this.CheckingForUpdate = true; 30 | 31 | List releases; 32 | try 33 | { 34 | releases = await this._client.GetReleases("FarisR99", "IMLCGui"); 35 | } 36 | catch (Exception ex) 37 | { 38 | Console.Error.WriteLine("Failed to check for updates: " + ex.Message); 39 | Console.Error.WriteLine(ex.StackTrace); 40 | 41 | this.CheckingForUpdate = false; 42 | return; 43 | } 44 | if (releases == null || releases.Count == 0) 45 | { 46 | this.CheckingForUpdate = false; 47 | return; 48 | } 49 | 50 | foreach (var release in releases) 51 | { 52 | if (!release.prerelease) 53 | { 54 | this.LatestRelease = release; 55 | break; 56 | } 57 | } 58 | this.CheckingForUpdate = false; 59 | } 60 | 61 | public bool HasUpdateAvailable() 62 | { 63 | if (this.CurrentVersion == null) return true; 64 | if (this.LatestRelease == null 65 | || this.LatestRelease.assets == null 66 | || this.LatestRelease.assets.Count == 0) return false; 67 | Version latestReleaseVersion = new Version(GetLatestReleaseVersion()); 68 | return latestReleaseVersion.CompareTo(this.CurrentVersion) > 0; 69 | } 70 | 71 | public string GetLatestReleaseVersion() 72 | { 73 | if (this.LatestRelease == null) return null; 74 | return this.LatestRelease.tag_name; 75 | } 76 | 77 | public async Task DownloadLatest(Logger logger) 78 | { 79 | string latestReleaseVersion = GetLatestReleaseVersion(); 80 | logger.Log($"Downloading latest IMLCGui version {FormatVersion(latestReleaseVersion)}..."); 81 | string outputFile = await DownloadService.DownloadFileAsync(null, this.LatestRelease.assets[0].browser_download_url, $"IMLCGui-{latestReleaseVersion}.exe", null); 82 | logger.Log($"Downloaded latest version to {outputFile}!"); 83 | } 84 | 85 | public static Version GetCurrentVersion() 86 | { 87 | Assembly assembly = Assembly.GetExecutingAssembly(); 88 | if (assembly == null) return null; 89 | FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); 90 | if (fileVersionInfo == null) return null; 91 | return fileVersionInfo.ProductVersion != null 92 | ? new Version(fileVersionInfo.ProductVersion) 93 | : (fileVersionInfo.FileVersion != null 94 | ? new Version(fileVersionInfo.FileVersion) 95 | : null); 96 | } 97 | 98 | public static string FormatVersion(string version) 99 | { 100 | if (version == null) return null; 101 | if (version.Split(new char[] { '.' }).Length == 3) 102 | { 103 | version += ".0"; 104 | } 105 | return version; 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /IMLCGui/CustomConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace IMLCGui 6 | { 7 | // Taken from https://stackoverflow.com/questions/485659/can-net-load-and-parse-a-properties-file-equivalent-to-java-properties-class 8 | internal class CustomConfig 9 | { 10 | private Dictionary list; 11 | private string filename; 12 | 13 | public CustomConfig(string file) 14 | { 15 | this.Reload(file); 16 | } 17 | 18 | public string Get(string field, string defValue) 19 | { 20 | string value = this.Get(field); 21 | return value != null ? value : defValue; 22 | } 23 | 24 | public string Get(string field) 25 | { 26 | return this.list.ContainsKey(field) ? this.list[field] : null; 27 | } 28 | 29 | public bool Has(string field) 30 | { 31 | return this.list.ContainsKey(field); 32 | } 33 | 34 | public void Set(string field, string value) 35 | { 36 | if (!this.list.ContainsKey(field)) 37 | { 38 | if (value != null) 39 | { 40 | this.list.Add(field, value.ToString()); 41 | } 42 | } 43 | else 44 | { 45 | if (value != null) 46 | { 47 | this.list[field] = value.ToString(); 48 | } else 49 | { 50 | this.list.Remove(field); 51 | } 52 | } 53 | } 54 | 55 | public void Save() 56 | { 57 | this.Save(this.filename); 58 | } 59 | 60 | public void Save(string filename) 61 | { 62 | this.filename = filename; 63 | 64 | if (!System.IO.File.Exists(filename)) 65 | System.IO.File.Create(filename).Close(); 66 | 67 | System.IO.StreamWriter file = new System.IO.StreamWriter(filename); 68 | 69 | foreach (string prop in list.Keys.ToArray()) 70 | if (!String.IsNullOrWhiteSpace(list[prop])) 71 | file.WriteLine(prop + "=" + list[prop]); 72 | 73 | file.Close(); 74 | } 75 | 76 | public void Reload() 77 | { 78 | Reload(this.filename); 79 | } 80 | 81 | public void Reload(string filename) 82 | { 83 | this.filename = filename; 84 | this.list = new Dictionary(); 85 | 86 | if (System.IO.File.Exists(filename)) 87 | this.LoadFromFile(filename); 88 | } 89 | 90 | private void LoadFromFile(string file) 91 | { 92 | foreach (string line in System.IO.File.ReadAllLines(file)) 93 | { 94 | if ((!String.IsNullOrEmpty(line)) && 95 | (!line.StartsWith(";")) && 96 | (!line.StartsWith("#")) && 97 | (!line.StartsWith("'")) && 98 | (line.Contains('='))) 99 | { 100 | int index = line.IndexOf('='); 101 | string key = line.Substring(0, index).Trim(); 102 | string value = line.Substring(index + 1).Trim(); 103 | 104 | if ((value.StartsWith("\"") && value.EndsWith("\"")) || 105 | (value.StartsWith("'") && value.EndsWith("'"))) 106 | { 107 | value = value.Substring(1, value.Length - 2); 108 | } 109 | 110 | try 111 | { 112 | this.list.Add(key, value); 113 | } 114 | catch { } 115 | } 116 | } 117 | } 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /IMLCGui/DownloadManager.cs: -------------------------------------------------------------------------------- 1 | using ICSharpCode.SharpZipLib.GZip; 2 | using ICSharpCode.SharpZipLib.Tar; 3 | using System; 4 | using System.IO; 5 | using System.Net; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace IMLCGui 10 | { 11 | // Taken from https://stackoverflow.com/questions/49034241/canceling-webclient-download-while-waiting-for-download-to-complete 12 | internal class DownloadService 13 | { 14 | public static async Task DownloadFileAsync(CancellationToken? cancellationToken, string url, string outputFileName, DownloadProgressChangedEventHandler handler) 15 | { 16 | using (var webClient = new WebClient()) 17 | { 18 | if (cancellationToken.HasValue) 19 | { 20 | cancellationToken.Value.Register(webClient.CancelAsync); 21 | } 22 | 23 | webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"); 24 | try 25 | { 26 | if (handler != null) 27 | { 28 | webClient.DownloadProgressChanged += handler; 29 | } 30 | var task = webClient.DownloadFileTaskAsync(url, outputFileName); 31 | await task; 32 | } 33 | catch (WebException ex) when (ex.Status == WebExceptionStatus.RequestCanceled) 34 | { 35 | throw new OperationCanceledException(); 36 | } 37 | catch (AggregateException ex) when (ex.InnerException is WebException exWeb && exWeb.Status == WebExceptionStatus.RequestCanceled) 38 | { 39 | throw new OperationCanceledException(); 40 | } 41 | catch (TaskCanceledException) 42 | { 43 | throw new OperationCanceledException(); 44 | } 45 | 46 | return outputFileName; 47 | } 48 | } 49 | 50 | public static async Task ExtractTGZ(CancellationToken cancellationToken, string gzArchiveName, string destFolder) 51 | { 52 | using (Stream inStream = File.OpenRead(gzArchiveName)) 53 | { 54 | using (Stream gzipStream = new GZipInputStream(inStream)) 55 | { 56 | using (TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream)) 57 | { 58 | cancellationToken.Register(tarArchive.Close); 59 | await Task.Run(() => tarArchive.ExtractContents(destFolder), cancellationToken); 60 | } 61 | } 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /IMLCGui/FileUtils.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace IMLCGui 4 | { 5 | internal class FileUtils 6 | { 7 | public static void Delete(string path) 8 | { 9 | if (File.Exists(path)) 10 | { 11 | File.Delete(path); 12 | } 13 | else if (Directory.Exists(path)) 14 | { 15 | Directory.Delete(path, true); 16 | } 17 | } 18 | 19 | public static bool DoesExist(string path) 20 | { 21 | return File.Exists(path) || Directory.Exists(path); 22 | } 23 | 24 | public static string GetCurrentPath(string path) 25 | { 26 | return Path.Combine(Directory.GetCurrentDirectory(), path); 27 | } 28 | 29 | public static string GetTempPath(string path) 30 | { 31 | return Path.Combine(Path.GetTempPath(), path); 32 | } 33 | 34 | public static void CopyAndMove(string source, string destination) 35 | { 36 | if (File.Exists(source)) 37 | { 38 | File.Copy(source, destination); 39 | File.Delete(source); 40 | } 41 | else if (Directory.Exists(source)) 42 | { 43 | DirectoryCopy(source, destination, true); 44 | Directory.Delete(source, true); 45 | } 46 | } 47 | 48 | public static void Move(string source, string destination) 49 | { 50 | FileInfo sourceInfo = new FileInfo(source); 51 | if (!sourceInfo.Exists) 52 | { 53 | return; 54 | } 55 | if (sourceInfo.Directory != null) 56 | { 57 | Directory.Move(source, destination); 58 | } 59 | else 60 | { 61 | File.Move(source, destination); 62 | } 63 | } 64 | 65 | // Taken from https://docs.microsoft.com/en-us/dotnet/standard/io/how-to-copy-directories 66 | private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs) 67 | { 68 | // Get the subdirectories for the specified directory. 69 | DirectoryInfo dir = new DirectoryInfo(sourceDirName); 70 | if (!dir.Exists) 71 | { 72 | throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " + sourceDirName); 73 | } 74 | DirectoryInfo[] dirs = dir.GetDirectories(); 75 | // If the destination directory doesn't exist, create it. 76 | Directory.CreateDirectory(destDirName); 77 | 78 | // Get the files in the directory and copy them to the new location. 79 | FileInfo[] files = dir.GetFiles(); 80 | foreach (FileInfo file in files) 81 | { 82 | string tempPath = Path.Combine(destDirName, file.Name); 83 | file.CopyTo(tempPath, false); 84 | } 85 | 86 | // If copying subdirectories, copy them and their contents to new location. 87 | if (copySubDirs) 88 | { 89 | foreach (DirectoryInfo subdir in dirs) 90 | { 91 | string tempPath = Path.Combine(destDirName, subdir.Name); 92 | DirectoryCopy(subdir.FullName, tempPath, copySubDirs); 93 | } 94 | } 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /IMLCGui/GitHubAPI.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Net.Http; 5 | using System.Net.Http.Headers; 6 | using System.Threading.Tasks; 7 | 8 | namespace IMLCGui 9 | { 10 | namespace GitHub 11 | { 12 | internal class GitHubClient 13 | { 14 | private HttpClient _httpClient; 15 | 16 | public GitHubClient(string clientName, string clientVersion) 17 | { 18 | this._httpClient = new HttpClient(); 19 | this._httpClient.BaseAddress = new Uri("https://api.github.com"); 20 | 21 | ProductInfoHeaderValue userAgent = new ProductInfoHeaderValue(clientName, clientVersion); 22 | this._httpClient.DefaultRequestHeaders.UserAgent.Add(userAgent); 23 | } 24 | 25 | public void SetRequestTimeout(TimeSpan timeout) 26 | { 27 | this._httpClient.Timeout = timeout; 28 | } 29 | 30 | public async Task> GetReleases(string author, string repositoryName) 31 | { 32 | string responseString; 33 | using (HttpResponseMessage apiResponse = await this._httpClient.GetAsync($"/repos/{author}/{repositoryName}/releases")) 34 | { 35 | apiResponse.EnsureSuccessStatusCode(); 36 | responseString = await apiResponse.Content.ReadAsStringAsync(); 37 | } 38 | return JsonConvert.DeserializeObject>(responseString); 39 | } 40 | } 41 | 42 | internal class Release 43 | { 44 | public string name; 45 | public string tag_name; 46 | public bool prerelease = false; 47 | public List assets = null; 48 | 49 | public override string ToString() 50 | { 51 | return "{" + 52 | "\"name\": \"" + name + "\", " + 53 | "\"tag_name\": \"" + tag_name + "\", " + 54 | "\"prerelease\": " + prerelease + "\", " + 55 | "\"assets\": " + (assets != null ? "[" + String.Join(",\n", assets) + "]" : "null") + 56 | "}"; 57 | } 58 | 59 | internal class Asset 60 | { 61 | public string name; 62 | public string browser_download_url; 63 | 64 | public override string ToString() 65 | { 66 | return "{" + 67 | "\"name\": \"" + name + "\", " + 68 | "\"browser_download_url\": \"" + browser_download_url + "\"" + 69 | "}"; 70 | } 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /IMLCGui/IMLCGui.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Debug 8 | AnyCPU 9 | {C8AE79D9-F822-4495-8930-47027624D17A} 10 | WinExe 11 | IMLCGui 12 | IMLCGui 13 | v4.6.2 14 | 512 15 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 16 | 4 17 | true 18 | true 19 | false 20 | 21 | 22 | 23 | publish\ 24 | true 25 | Disk 26 | false 27 | Foreground 28 | 7 29 | Days 30 | false 31 | false 32 | true 33 | 0 34 | 1.0.0.%2a 35 | false 36 | true 37 | 38 | 39 | AnyCPU 40 | true 41 | full 42 | false 43 | bin\Debug\ 44 | DEBUG;TRACE 45 | prompt 46 | 4 47 | 48 | 49 | AnyCPU 50 | pdbonly 51 | true 52 | bin\Release\ 53 | TRACE 54 | prompt 55 | 4 56 | 57 | 58 | IMLCGui.App 59 | 60 | 61 | Resources\ram.ico 62 | 63 | 64 | 65 | ..\packages\ControlzEx.4.4.0\lib\net462\ControlzEx.dll 66 | 67 | 68 | ..\packages\SharpZipLib.1.3.3\lib\net45\ICSharpCode.SharpZipLib.dll 69 | 70 | 71 | ..\packages\MahApps.Metro.2.4.9\lib\net46\MahApps.Metro.dll 72 | 73 | 74 | ..\packages\Microsoft.Xaml.Behaviors.Wpf.1.1.19\lib\net45\Microsoft.Xaml.Behaviors.dll 75 | 76 | 77 | ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 4.0 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | MSBuild:Compile 102 | Designer 103 | 104 | 105 | MSBuild:Compile 106 | Designer 107 | 108 | 109 | MSBuild:Compile 110 | Designer 111 | 112 | 113 | App.xaml 114 | Code 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | LatencyRow.xaml 123 | 124 | 125 | 126 | MainWindow.xaml 127 | Code 128 | 129 | 130 | 131 | 132 | 133 | 134 | Code 135 | 136 | 137 | True 138 | True 139 | Resources.resx 140 | 141 | 142 | True 143 | Settings.settings 144 | True 145 | 146 | 147 | PublicResXFileCodeGenerator 148 | Resources.Designer.cs 149 | 150 | 151 | 152 | SettingsSingleFileGenerator 153 | Settings.Designer.cs 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | False 162 | Microsoft .NET Framework 4.6 %28x86 and x64%29 163 | true 164 | 165 | 166 | False 167 | .NET Framework 3.5 SP1 168 | false 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 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}. 178 | 179 | 180 | 181 | 182 | 183 | 184 | -------------------------------------------------------------------------------- /IMLCGui/LatencyRow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 22 | 23 | -------------------------------------------------------------------------------- /IMLCGui/LatencyRow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Runtime.CompilerServices; 3 | using System.Windows; 4 | using System.Windows.Controls; 5 | 6 | namespace IMLCGui 7 | { 8 | /// 9 | /// Interaction logic for LatencyRow.xaml 10 | /// 11 | public partial class LatencyRow : UserControl, INotifyPropertyChanged 12 | { 13 | public bool ShowGridLines 14 | { 15 | get { return (bool)GetValue(ShowGridLinesProperty); } 16 | set 17 | { 18 | SetValue(ShowGridLinesProperty, value); 19 | } 20 | } 21 | public static readonly DependencyProperty ShowGridLinesProperty = DependencyProperty.Register( 22 | "ShowGridLinesProperty", 23 | typeof(bool), 24 | typeof(LatencyRow), 25 | new PropertyMetadata(false) 26 | ); 27 | 28 | public string InjectDelay 29 | { 30 | get { return (string)GetValue(InjectDelayProperty); } 31 | set 32 | { 33 | SetValue(InjectDelayProperty, value); 34 | OnPropertyChanged(); 35 | } 36 | } 37 | 38 | public static readonly DependencyProperty InjectDelayProperty = DependencyProperty.Register( 39 | "InjectDelayProperty", 40 | typeof(string), 41 | typeof(LatencyRow), 42 | new PropertyMetadata("") 43 | ); 44 | 45 | public string Latency 46 | { 47 | get { return (string)GetValue(LatencyProperty); } 48 | set 49 | { 50 | SetValue(LatencyProperty, value); 51 | OnPropertyChanged(); 52 | } 53 | } 54 | public static readonly DependencyProperty LatencyProperty = DependencyProperty.Register( 55 | "LatencyProperty", 56 | typeof(string), 57 | typeof(LatencyRow), 58 | new PropertyMetadata("") 59 | ); 60 | 61 | public string Bandwidth 62 | { 63 | get { return (string)GetValue(BandwidthProperty); } 64 | set 65 | { 66 | SetValue(BandwidthProperty, value); 67 | OnPropertyChanged(); 68 | } 69 | } 70 | public static readonly DependencyProperty BandwidthProperty = DependencyProperty.Register( 71 | "BandwidthProperty", 72 | typeof(string), 73 | typeof(LatencyRow), 74 | new PropertyMetadata("") 75 | ); 76 | 77 | public event PropertyChangedEventHandler PropertyChanged; 78 | 79 | public LatencyRow() 80 | { 81 | InitializeComponent(); 82 | } 83 | 84 | // Create the OnPropertyChanged method to raise the event 85 | // The calling member's name will be used as the parameter. 86 | protected void OnPropertyChanged([CallerMemberName] string name = null) 87 | { 88 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /IMLCGui/Logger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Threading; 5 | 6 | namespace IMLCGui 7 | { 8 | public class Logger 9 | { 10 | private static List PATHS_IN_USE = new List(); 11 | 12 | private string FilePath; 13 | private ReaderWriterLock locker = new ReaderWriterLock(); 14 | 15 | public Logger(string FilePath) 16 | { 17 | if (PATHS_IN_USE.Contains(FilePath)) 18 | { 19 | throw new Exception("Log file path already in use"); 20 | } 21 | PATHS_IN_USE.Add(FilePath); 22 | this.FilePath = FilePath; 23 | } 24 | 25 | public void Close() 26 | { 27 | PATHS_IN_USE.Remove(FilePath); 28 | } 29 | 30 | public void Debug(params string[] logMessages) 31 | { 32 | Log(LogLevel.DEBUG, logMessages); 33 | } 34 | 35 | public void Error(string errorMessage) 36 | { 37 | Log(LogLevel.ERROR, errorMessage); 38 | } 39 | 40 | public void Error(Exception ex) 41 | { 42 | Log(LogLevel.ERROR, ex.ToString()); 43 | } 44 | 45 | public void Error(string errorMessage, Exception ex) 46 | { 47 | Log(LogLevel.ERROR, errorMessage, ex.ToString()); 48 | } 49 | 50 | public void Log(params string[] logMessages) 51 | { 52 | Log(LogLevel.INFO, logMessages); 53 | } 54 | 55 | public void Warn(params string[] logMessages) 56 | { 57 | Log(LogLevel.WARN, logMessages); 58 | } 59 | 60 | public void Log(LogLevel level, params string[] logMessages) 61 | { 62 | try 63 | { 64 | try 65 | { 66 | this.locker.AcquireWriterLock(1000); 67 | using (StreamWriter w = File.AppendText(this.FilePath)) 68 | { 69 | foreach (string message in logMessages) 70 | { 71 | LogLine(w, level, message); 72 | } 73 | } 74 | } 75 | catch 76 | { 77 | foreach (string message in logMessages) 78 | { 79 | LogLine(null, level, message); 80 | } 81 | return; 82 | } 83 | } 84 | catch (Exception ex) 85 | { 86 | Console.Error.WriteLine(ex.Message); 87 | } 88 | finally 89 | { 90 | this.locker.ReleaseWriterLock(); 91 | } 92 | } 93 | 94 | private static void LogLine(TextWriter w, LogLevel level, object logMessage) 95 | { 96 | string formattedMsg = $"[{DateTime.Now.ToShortDateString()} {DateTime.Now.ToLongTimeString()}] [{level}]: {logMessage}"; 97 | if (level == LogLevel.ERROR) 98 | { 99 | Console.Error.WriteLine(formattedMsg); 100 | } 101 | else 102 | { 103 | Console.WriteLine(formattedMsg); 104 | } 105 | if (w != null) 106 | { 107 | w.WriteLine(formattedMsg); 108 | } 109 | } 110 | } 111 | 112 | public enum LogLevel 113 | { 114 | DEBUG, INFO, WARN, ERROR, PROCESS 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /IMLCGui/MLCProcess.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Threading.Tasks; 5 | 6 | namespace IMLCGui 7 | { 8 | internal class MLCProcess 9 | { 10 | private static readonly string VERSION_STRING_PREFIX = "Memory Latency Checker - "; 11 | private static readonly List NEW_VERSIONS = new List { "v3.10", "v3.11", "v3.11b" }; 12 | 13 | public static async Task GetMLCVersion(string processPath) 14 | { 15 | Process process = new Process 16 | { 17 | StartInfo = new ProcessStartInfo 18 | { 19 | FileName = processPath, 20 | Arguments = "--invalid_argument", // Use an invalid argument just to print the version 21 | UseShellExecute = false, 22 | RedirectStandardOutput = true, 23 | RedirectStandardError = true, 24 | CreateNoWindow = true, 25 | }, 26 | EnableRaisingEvents = true 27 | }; 28 | process.Start(); 29 | 30 | string version = null; 31 | while (!process.StandardOutput.EndOfStream) 32 | { 33 | string line; 34 | try 35 | { 36 | line = process.StandardOutput.ReadLine(); 37 | } 38 | catch (Exception ex) 39 | { 40 | Console.Error.WriteLine(ex.Message); 41 | break; 42 | } 43 | if (line.Contains(VERSION_STRING_PREFIX)) 44 | { 45 | version = line.Substring(line.LastIndexOf(VERSION_STRING_PREFIX) + VERSION_STRING_PREFIX.Length); 46 | break; 47 | } 48 | } 49 | if (!process.HasExited) 50 | { 51 | try 52 | { 53 | process.Kill(); 54 | } 55 | catch (Exception ex) 56 | { 57 | Console.Error.WriteLine(ex.Message); 58 | } 59 | } 60 | return version; 61 | } 62 | 63 | public static string GenerateBandwidthArguments(string mlcVersion, bool peakInjection) 64 | { 65 | return peakInjection ? "--peak_injection_bandwidth" : "--max_bandwidth"; 66 | } 67 | 68 | public static string GenerateCacheArguments(string mlcVersion) 69 | { 70 | string mlcArguments = "--c2c_latency"; 71 | if (NEW_VERSIONS.Contains(mlcVersion)) 72 | { 73 | mlcArguments += " -e0"; 74 | } 75 | return mlcArguments; 76 | } 77 | 78 | public static string GenerateLatencyArguments(string mlcVersion, string injectDelayOverride) 79 | { 80 | string mlcArguments = "--loaded_latency"; 81 | if (injectDelayOverride != null) 82 | { 83 | mlcArguments += " -d" + injectDelayOverride; 84 | } 85 | if (NEW_VERSIONS.Contains(mlcVersion)) 86 | { 87 | mlcArguments += " -e0"; 88 | } 89 | return mlcArguments; 90 | } 91 | 92 | public static string GenerateQuickBandwidthArguments(string mlcVersion) 93 | { 94 | return "--bandwidth_matrix"; 95 | } 96 | 97 | public static string GenerateQuickLatencyArguments(string mlcVersion) 98 | { 99 | string mlcArguments = "--latency_matrix"; 100 | if (NEW_VERSIONS.Contains(mlcVersion)) 101 | { 102 | mlcArguments += " -e0"; 103 | } 104 | return mlcArguments; 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /IMLCGui/MLCProcessManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | namespace IMLCGui 7 | { 8 | internal class MLCProcessManager 9 | { 10 | private Logger _logger; 11 | 12 | public string Path = ""; 13 | private string Version = null; 14 | 15 | public object ProcessLock { get; } = new object(); 16 | public CancellationTokenSource CancellationTokenSource; 17 | public int ProcessId { get; private set; } = -1; 18 | 19 | public MLCProcessManager(Logger logger, string path) 20 | { 21 | this._logger = logger; 22 | this.Path = path; 23 | } 24 | 25 | public void CancelToken() 26 | { 27 | if (this.CancellationTokenSource != null) 28 | { 29 | this.CancellationTokenSource.Cancel(); 30 | this.CancellationTokenSource = null; 31 | } 32 | } 33 | 34 | private Process CreateProcess(string arguments) 35 | { 36 | return new Process 37 | { 38 | StartInfo = new ProcessStartInfo 39 | { 40 | FileName = this.Path, 41 | Arguments = arguments, 42 | UseShellExecute = false, 43 | RedirectStandardOutput = true, 44 | RedirectStandardError = true, 45 | CreateNoWindow = true, 46 | }, 47 | EnableRaisingEvents = true 48 | }; 49 | } 50 | 51 | public void ConsumeOutput(Process process, CancellationToken cancelToken, Predicate shouldStartProcessing, Func processOutputLine) 52 | { 53 | bool shouldProcessLine = false; 54 | while (!process.StandardOutput.EndOfStream) 55 | { 56 | cancelToken.ThrowIfCancellationRequested(); 57 | string line; 58 | try 59 | { 60 | line = process.StandardOutput.ReadLine(); 61 | } 62 | catch (Exception ex) 63 | { 64 | Console.Error.WriteLine(ex.Message); 65 | return; 66 | } 67 | cancelToken.ThrowIfCancellationRequested(); 68 | if (this._logger != null) 69 | { 70 | this._logger.Log(LogLevel.PROCESS, line); 71 | } 72 | if (shouldProcessLine) 73 | { 74 | if (!processOutputLine(line)) 75 | { 76 | break; 77 | } 78 | } 79 | else if (shouldStartProcessing(line)) 80 | { 81 | shouldProcessLine = true; 82 | } 83 | } 84 | } 85 | 86 | public string GetVersion() 87 | { 88 | return this.Version; 89 | } 90 | 91 | public void FetchVersion() 92 | { 93 | if (this.Path == null) 94 | { 95 | this.Version = null; 96 | return; 97 | } 98 | string mlcPath = this.Path; 99 | if (mlcPath.Trim().Length == 0) 100 | { 101 | mlcPath = FileUtils.GetCurrentPath("mlc.exe"); 102 | if (!FileUtils.DoesExist(mlcPath)) 103 | { 104 | this.Version = null; 105 | return; 106 | } 107 | } 108 | Task.Run(async () => 109 | { 110 | this.Version = await MLCProcess.GetMLCVersion(mlcPath); 111 | if (this.Version != null) 112 | { 113 | this.Version = this.Version.Trim(); 114 | } 115 | Console.Out.WriteLine("Detected MLC version: " + this.Version); 116 | }); 117 | } 118 | 119 | public void Kill() 120 | { 121 | this.Kill(null); 122 | } 123 | 124 | public void Kill(Process process) 125 | { 126 | this.Kill(process, true); 127 | } 128 | 129 | public void Kill(Process process, bool destroyCancelTokenSource) 130 | { 131 | lock (this.ProcessLock) 132 | { 133 | if (process == null) 134 | { 135 | if (this.ProcessId == -1) 136 | { 137 | return; 138 | } 139 | process = Process.GetProcessById(this.ProcessId); 140 | if (process == null) 141 | { 142 | if (this._logger != null) 143 | { 144 | this._logger.Warn($"Process with ID {this.ProcessId} is not running."); 145 | } 146 | this.ProcessId = -1; 147 | if (destroyCancelTokenSource) 148 | { 149 | this.CancellationTokenSource = null; 150 | } 151 | return; 152 | } 153 | } 154 | if (!process.HasExited) 155 | { 156 | try 157 | { 158 | process.Kill(); 159 | } 160 | catch (Exception ex) 161 | { 162 | if (this._logger != null) 163 | { 164 | this._logger.Error($"Failed to kill {process.ProcessName}:", ex); 165 | } 166 | } 167 | } 168 | this.ProcessId = -1; 169 | if (destroyCancelTokenSource) 170 | { 171 | this.CancellationTokenSource = null; 172 | } 173 | } 174 | } 175 | 176 | public Process StartProcess(string arguments) 177 | { 178 | Process process = this.CreateProcess(arguments); 179 | lock (this.ProcessLock) 180 | { 181 | if (this.ProcessId != -1) 182 | { 183 | return null; 184 | } 185 | if (this._logger != null) 186 | { 187 | this._logger.Log($"Running \"mlc {arguments}\""); 188 | } 189 | process.Start(); 190 | this.ProcessId = process.Id; 191 | 192 | if (Process.GetCurrentProcess().PriorityClass.CompareTo(ProcessPriorityClass.AboveNormal) >= 0) 193 | { 194 | process.PriorityClass = ProcessPriorityClass.RealTime; 195 | } 196 | else 197 | { 198 | process.PriorityClass = ProcessPriorityClass.AboveNormal; 199 | } 200 | } 201 | return process; 202 | } 203 | 204 | public bool Stop() 205 | { 206 | bool stopped = false; 207 | if (this.CancellationTokenSource != null && !this.CancellationTokenSource.IsCancellationRequested) 208 | { 209 | this.CancellationTokenSource.Cancel(); 210 | this.CancellationTokenSource = null; 211 | stopped = true; 212 | try 213 | { 214 | Thread.Sleep(250); 215 | } 216 | catch 217 | { 218 | } 219 | } 220 | lock (this.ProcessLock) 221 | { 222 | if (this.ProcessId != -1) 223 | { 224 | try 225 | { 226 | if (this._logger != null) 227 | { 228 | this._logger.Debug("User requested cancellation, killing MLC..."); 229 | } 230 | Process runningProcess = Process.GetProcessById(this.ProcessId); 231 | if (runningProcess != null && !runningProcess.HasExited) 232 | { 233 | string processName = runningProcess.ProcessName; 234 | runningProcess.Kill(); 235 | runningProcess.WaitForExit(); 236 | if (this._logger != null) 237 | { 238 | this._logger.Log($"Killed process: {processName}"); 239 | } 240 | } 241 | else 242 | { 243 | if (this._logger != null) 244 | { 245 | this._logger.Log("Killed MLC."); 246 | } 247 | } 248 | } 249 | catch (Exception ex) 250 | { 251 | if (this._logger != null) 252 | { 253 | this._logger.Error("Failed to kill MLC process:", ex); 254 | } 255 | } 256 | finally 257 | { 258 | this.ProcessId = -1; 259 | } 260 | stopped = true; 261 | } 262 | } 263 | return stopped; 264 | } 265 | } 266 | } 267 | -------------------------------------------------------------------------------- /IMLCGui/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  13 | 14 | 15 |