/// <summary> /// The StartTime property should be set before calling Run() (unless IgnoreTimer is set to true). /// </summary> public void Run(IEnumerable <RawCellData> cells) { /* Determine file paths: */ string exeFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); BinaryGameStateFilePath = Path.Combine(exeFolder, "GameState.bin"); XmlGameStateFilePath = Path.Combine(exeFolder, "GameState.xml"); /* Determine previous game state (this will be saved when a new game starts): */ if (File.Exists(BinaryGameStateFilePath)) { LastGameStateOfPreviousGame = GameState.LoadGameState(BinaryGameStateFilePath, FileType.Binary); } else if (File.Exists(XmlGameStateFilePath)) { LastGameStateOfPreviousGame = GameState.LoadGameState(XmlGameStateFilePath, FileType.Xml); } else { LastGameStateOfPreviousGame = null; } /* Backup existing files: */ if (IsInDebugMode) { if (File.Exists(BinaryGameStateFilePath)) { string backupFileName = Path.ChangeExtension(BinaryGameStateFilePath, ".bak.bin"); File.Copy(BinaryGameStateFilePath, backupFileName, true /*overWrite*/); } if (File.Exists(XmlGameStateFilePath)) { string backupFileName = Path.ChangeExtension(XmlGameStateFilePath, ".bak.xml"); File.Copy(XmlGameStateFilePath, backupFileName, true /*overWrite*/); } } /* Create the initial game state: */ CurrentGameState = LastGameStateOfPreviousGame == null ? new GameState() : LastGameStateOfPreviousGame.Clone(); /* Run the solver: */ CurrentGameState.NewGameDetected += ArchiveGameStateOfPreviousGame; try { /* Set up the new game state: */ CurrentGameState.LoadRawCellData(cells); Run(); } finally { /* Ensure no memory leaks due to dangling events: */ CurrentGameState.NewGameDetected -= ArchiveGameStateOfPreviousGame; } }