/// <summary> /// Converts a Game to a GameIndex. *Narrowing conversion, so make sure the game has been checked for convertibility first! /// </summary> /// <param name="game"></param> public static GameIndex GameToGameIndex(Game game) { Misc.AssertR(GameIsKnownAndSupported(game), nameof(game) + " was out of range: " + game); return(game switch { Game.Thief1 => GameIndex.Thief1, Game.Thief2 => GameIndex.Thief2, Game.Thief3 => GameIndex.Thief3, _ => GameIndex.SS2 });
internal static void CreateOrClearTempPath(string path) { #region Safety check // Make sure we never delete any paths that are not safely tucked in our temp folder string baseTemp = _baseTemp.TrimEnd(CA_BS_FS_Space); // @DIRSEP: getting rid of this concat is more trouble than it's worth // This method is called rarely and only once in a row bool pathIsInTempDir = path.PathStartsWithI(baseTemp + "\\"); Misc.AssertR(pathIsInTempDir, "Path '" + path + "' is not in temp dir '" + baseTemp + "'"); if (!pathIsInTempDir) { return; } #endregion if (Directory.Exists(path)) { try { foreach (string f in Directory.GetFiles(path, "*", SearchOption.AllDirectories)) { new FileInfo(f).IsReadOnly = false; } foreach (string d in Directory.GetDirectories(path, "*", SearchOption.AllDirectories)) { Misc.Dir_UnSetReadOnly(d); } } catch (Exception ex) { Log("Exception setting temp path subtree to all non-readonly.\r\n" + "path was: " + path, ex); } try { foreach (string f in FastIO.GetFilesTopOnly(path, "*")) { File.Delete(f); } foreach (string d in FastIO.GetDirsTopOnly(path, "*")) { Directory.Delete(d, recursive: true); } } catch (Exception ex) { Log("Exception clearing temp path " + path, ex); } } else { try { Directory.CreateDirectory(path); } catch (Exception ex) { Log("Exception creating temp path " + path, ex); } } }