From 442458773e94c4c4c8567110e4a3c6a436330d7a Mon Sep 17 00:00:00 2001 From: Asnivor Date: Tue, 4 Dec 2018 14:13:52 +0000 Subject: [PATCH] bgimage opacity changes - #220 --- BuildTools/ChangeLog/default.md | 1 + MedLaunch/Classes/Scanning/DiscScan.cs | 325 +++++++++++++++++- MedLaunch/MainWindow.xaml.cs | 2 +- MedLaunch/Models/GSystem.cs | 12 +- MedLaunch/Windows/AccentStyleWindow.xaml | 2 +- .../output/SplashScreenUpdater.exe | Bin 7168 -> 7168 bytes 6 files changed, 332 insertions(+), 10 deletions(-) diff --git a/BuildTools/ChangeLog/default.md b/BuildTools/ChangeLog/default.md index da71079..162e6e8 100644 --- a/BuildTools/ChangeLog/default.md +++ b/BuildTools/ChangeLog/default.md @@ -8,6 +8,7 @@ title: Changelog ------------------------------------ * (Enhancement) - Added compatibility for mednafen v1.21.2 and v1.21.3 ([214](https://github.com/Asnivor/MedLaunch/issues/214)) * (BugFix) - Mitigated TimeSpan overflow exception ([215](https://github.com/Asnivor/MedLaunch/issues/215)) +* (Enhancement) - Background picture can now be hidden (Opacity set to 0) ([220](https://github.com/Asnivor/MedLaunch/issues/220)) ##### [0.5.25.3](https://medlaunch.info/releases/0-5-25-x) ###### 2018-03-22 diff --git a/MedLaunch/Classes/Scanning/DiscScan.cs b/MedLaunch/Classes/Scanning/DiscScan.cs index e484cfd..987db55 100644 --- a/MedLaunch/Classes/Scanning/DiscScan.cs +++ b/MedLaunch/Classes/Scanning/DiscScan.cs @@ -27,8 +27,311 @@ public DiscScan() _App = (App)Application.Current; } - // Start Disc scan and import process for specific system + /// + /// Newer attempt at this + /// This should allow for all games in all sub folders + /// + /// + /// public void BeginDiscImportImproved(int systemId, ProgressDialogController dialog) + { + // get path to root DISC folder + string discFolderPath = GetPath(systemId); + + dialog.SetMessage("Checking validity of current " + GSystem.GetSystemName(systemId) + " games in the database"); + + // get a list of games for this system currently already in the database + List presentGames = (from g in Games + where g.systemId == systemId + select g).ToList(); + + // check whether presentGames paths are valid - mark as hidden if not + foreach (var g in presentGames.Where(a => a.hidden == false)) + { + if (!File.Exists(g.gamePath)) + { + g.hidden = true; + DisksToUpdate.Add(g); + HiddenStats++; + } + } + + string strBase = "\nScanning Disc Folders and Enumerating Files: "; + dialog.SetMessage(strBase); + + // is the system path set actually valid? + if (!Directory.Exists(discFolderPath)) + return; + + // get all cue files in all subfolders + var cueFiles = (from a in Directory.EnumerateFiles(discFolderPath, "*.*", SearchOption.AllDirectories) + where Path.GetExtension(a.ToLower()) == ".cue" || + Path.GetExtension(a.ToLower()) == ".ccd" || + Path.GetExtension(a.ToLower()) == ".m3u" || + Path.GetExtension(a.ToLower()) == ".toc" + select a).ToList(); + + strBase += "\nValid Files Found: " + cueFiles.Count() + "\nFiles Still To Process: "; + dialog.SetMessage(strBase); + + int cnt = cueFiles.Count(); + + // master list to hold the different games found + List DetectedGames = new List(); + + // null check + if (cueFiles == null || cueFiles.Count() == 0) + return; + + // working list + var cueFTemp = cueFiles.ToList(); + + // do m3u detection first + foreach (string s in cueFTemp.Where(a => a.ToLower().EndsWith(".m3u"))) + { + bool m3uValid = true; + + // interogate the m3u to get referenced cue files + DiscGameFile d = new DiscGameFile(s, systemId); + var result = ParseTrackSheet(d, CueType.m3u, systemId); + + // check that the referenced cue files are present + foreach (var thing in result) + { + if (!File.Exists(thing.FullPath)) + { + // cuefile could not be found + m3uValid = false; + break; + } + else + { + // file is found - check that the referenced img file exists + if (!IsTrackSheetValid(thing, systemId)) + { + m3uValid = false; + + // remove the cuefiles as well as they are faulty + try + { + cueFiles.Remove(thing.FullPath); + } + catch (Exception) { } + } + } + } + + if (m3uValid == false) + { + // problem with this m3u - remove from cueFiles + cueFiles.Remove(d.FullPath); + continue; + } + + // if we get this far, all the referenced cue files in the m3u are valid - attempt to remove them from cuefiles + foreach (var thing in result) + { + try + { + cueFiles.Remove(thing.FullPath); + } + catch (Exception) { } + } + + // now add to detected games + DetectedGames.Add(d); + + // remove from cueFiles + cueFiles.Remove(d.FullPath); + } + + // cueFiles should now only contain sheets that are not referenced by m3us + // reinit the working list + cueFTemp = cueFiles.ToList(); + + // next attempt to identify multi-disc games that do not have an m3u file within the folder structure + // and separate them out into single and multi lists + List multiGames = new List(); + + foreach (string s in cueFTemp) + { + for (int disc = 1; disc < 10; disc++) + { + if (s.ToLower().Contains("disc " + disc) || + s.ToLower().Contains("cd " + disc) || + s.ToLower().Contains("d" + disc) || + s.ToLower().Contains("c" + disc) || + s.ToLower().Contains("cd" + disc) || + s.ToLower().Contains("disk" + disc) || + s.ToLower().Contains("disk " + disc) || + s.ToLower().Contains("cd" + disc) || + s.ToLower().Contains("disc" + disc)) + { + // add to multiGames to sort out later + multiGames.Add(s); + // remove from cueFiles + cueFiles.Remove(s); + break; + } + } + } + + // cueFiles should now contain single disc games + // process multi-disc games next - any multis that turn out to be singles can then + // be added back into cueFiles for processing as single later + List gamesWordSplit = new List(); + int maxLength = 0; + + // split the game titles up into arrays of words + foreach (var s in multiGames) + { + string[] work = s.Split(' '); + gamesWordSplit.Add(work); + if (work.Length >= maxLength) + maxLength = work.Length; + } + + Dictionary> matching = new Dictionary>(); + + // work backwards from the max word length (minus 1 - removing the last word) + for (int i = maxLength; i > -1; i--) + { + // build the test string + foreach (var str in gamesWordSplit) + { + // get full string + StringBuilder sb1 = new StringBuilder(); + for (int arry = 0; arry < str.Length; arry++) + { + if (arry > 0) + sb1.Append(" "); + + sb1.Append(str[arry]); + } + string full = sb1.ToString(); + + if (i == str.Length) + continue; + + StringBuilder sb = new StringBuilder(); + for (int arry = 0; arry < i; arry++) + { + if (arry > 0) + sb.Append(" "); + + sb.Append(str[arry]); + } + string part = sb.ToString(); + + if (matching.ContainsKey(part)) + { + // match found + List tmp = matching[part]; + tmp.Add(full); + matching[part] = tmp.Distinct().ToList(); + } + else + { + // check whether full name already exists in another value + bool found = false; + foreach (var v in matching) + { + var lookup = v.Value.Where(a => a == full).ToList().FirstOrDefault(); + if (lookup != null) + found = true; + } + + if (found == false) + { + // no match found - create new entry + List tmp = new List { full }; + matching[part] = tmp; + } + } + } + } + + // matching should now contain multidisc games divided up + foreach (var strGame in matching) + { + List dgList = new List(); + + List paths = strGame.Value; + var dist = (from a in paths + select a).OrderBy(a => a).Distinct().ToList(); + + // create a discgamefile for each cue + foreach (var s in dist) + { + DiscGameFile dgf3 = new DiscGameFile(s, systemId); + + // check whether referenced image files are valid + if (IsTrackSheetValid(dgf3, systemId)) + dgList.Add(dgf3); + } + + if (dgList.Count < 2) + { + // 1 or less discs found - skip it + continue; + } + + Dictionary> dupes = new Dictionary>(); + foreach (var g in dgList) + { + if (dupes.ContainsKey(Path.GetFileNameWithoutExtension(g.FileName))) + { + var t = dupes[Path.GetFileNameWithoutExtension(g.FileName)]; + t.Add(g); + dupes[Path.GetFileNameWithoutExtension(g.FileName)] = t; + } + else + { + dupes[Path.GetFileNameWithoutExtension(g.FileName)] = new List { g }; + } + } + + // dupes should now tell us about the duplicates + dgList = new List(); + foreach (var k in dupes) + { + if (k.Value.Count() == 1) + { + // one result + dgList.Add(k.Value.First()); + } + else if (k.Value.Count() > 1) + { + // duplicates found - prioritze ccd + var look = k.Value.Where(a => a.Extension.ToLower() == ".ccd").FirstOrDefault(); + + if (look != null) + dgList.Add(look); + + else + { + dgList.Add(k.Value.First()); + } + } + } + + // dglist should now have all required disc files to create an M3U. + List newDGList = dgList.OrderBy(a => a.FileName).ToList(); + + // create m3u + string m3uPath = newDGList.First().FolderPath + "\\" + newDGList.First().GameName + ".m3u"; + CreateM3uPlaylist(newDGList, m3uPath, true); + + // add m3u to detected games + DetectedGames.Add(new DiscGameFile(newDGList.First().FolderPath + "\\" + newDGList.First().GameName + ".m3u", systemId)); + } + + } + + #region OldDiskImport + + // Start Disc scan and import process for specific system + public void BeginDiscImportImprovedold(int systemId, ProgressDialogController dialog) { // get path to root DISC folder string discFolderPath = GetPath(systemId); @@ -83,10 +386,13 @@ public void BeginDiscImportImproved(int systemId, ProgressDialogController dialo foreach (var discGame in discGames) { InsertOrUpdateDisk(discGame, systemId); - } + } } } + #endregion + + /// /// Examine a folder and return a List List ( may contain singles or multiples depending on logic) /// @@ -109,6 +415,10 @@ public static List DetermineAllGamesInFolder(string folderPath, in a.ToLower().Contains(".toc") select a).ToList(); + // null check + if (cueFiles == null || cueFiles.Count() == 0) + return DetectedGames; + var cueFTemp = cueFiles.ToList(); // deal with m3u's first @@ -129,7 +439,6 @@ public static List DetermineAllGamesInFolder(string folderPath, in m3uValid = false; break; } - else { // file is found - check that the referenced img file exists @@ -390,8 +699,6 @@ public static List DetermineAllGamesInFolder(string folderPath, in } } - - // dupes should now tell us about the duplicates dgList = new List(); foreach (var k in dupes) @@ -1110,7 +1417,13 @@ public static List ParseTrackSheet(DiscGameFile trackSheet, CueTyp continue; // create a discgamefile - DiscGameFile dgf = new DiscGameFile(trackSheet.FolderPath + "\\" + l, systemId); + string filePath = ""; + if (l.Contains(":")) + filePath = l; + else + filePath = trackSheet.FolderPath + "\\" + l; + + DiscGameFile dgf = new DiscGameFile(filePath, systemId); // add it to working list working.Add(dgf); } diff --git a/MedLaunch/MainWindow.xaml.cs b/MedLaunch/MainWindow.xaml.cs index 2d30973..fa5c6af 100644 --- a/MedLaunch/MainWindow.xaml.cs +++ b/MedLaunch/MainWindow.xaml.cs @@ -957,7 +957,7 @@ private async void RescanSystemDiscs(int sysId) // Start ROM scan for this system - ds.BeginDiscImportImproved(s.systemId, controller); + ds.BeginDiscImportImprovedold(s.systemId, controller); //output += ".....Completed\n\n"; diff --git a/MedLaunch/Models/GSystem.cs b/MedLaunch/Models/GSystem.cs index 52e5432..6064173 100644 --- a/MedLaunch/Models/GSystem.cs +++ b/MedLaunch/Models/GSystem.cs @@ -417,8 +417,16 @@ public static HashSet GetAllowedFileExtensions(int systemId) char c = ','; string[] aSplit = archive.Split(c); string[] nSplit = nonArchive.Split(c); - foreach (string s in aSplit) { supported.Add(s); } - foreach (string s in nSplit) { supported.Add(s); } + foreach (string s in aSplit) + { + if (s.Trim() != "") + supported.Add(s); + } + foreach (string s in nSplit) + { + if (s.Trim() != "") + supported.Add(s); + } return supported; } diff --git a/MedLaunch/Windows/AccentStyleWindow.xaml b/MedLaunch/Windows/AccentStyleWindow.xaml index 6cf4a44..947aa1f 100644 --- a/MedLaunch/Windows/AccentStyleWindow.xaml +++ b/MedLaunch/Windows/AccentStyleWindow.xaml @@ -105,7 +105,7 @@ - diff --git a/SplashScreenUpdater/output/SplashScreenUpdater.exe b/SplashScreenUpdater/output/SplashScreenUpdater.exe index 97151937b93856ac71c605c3c4b1e63a8bf7c38f..e749ba61f8d224db36e1d7366e970af53b8d7046 100644 GIT binary patch delta 81 zcmZp$Xt0>j!Lp-;EoNiS2_AuoA4=z*x}f8|mo19-WpiQ4<`mv1j9}@>KKv45D?*pD k|C}D?w5RfJaiIj!Qvk`Giqbc2_AtSo*KWDJ5A18c)xFN7iZYFIfeHLBUpN}55I(5v)Hc- pGuS_SEtK-rJ2~O^dPW8Y1{bRsm!kZFr2LA>Rs6p;*9f$50|4q$B4z*p