private void CreateUpdate(object state) { if (!_working) { return; } if (!(state is CreateUpdateStruct)) { return; } var stateList = (CreateUpdateStruct)state; string[] directories = Directory.GetDirectories(stateList.InFolder); foreach (string dir in directories) { if (CheckFolder(dir, stateList.FromDate, stateList.ToDate)) { var dirInfo = new DirectoryInfo(dir); string path = Path.Combine(stateList.OutFolder, dirInfo.Name); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var tempState = new CreateUpdateStruct { InFolder = dirInfo.FullName, OutFolder = path, FromDate = stateList.FromDate, ToDate = stateList.ToDate }; ThreadPool.QueueUserWorkItem(CreateUpdate, tempState); } else { UpdateProgress(FilesCount(dir)); } } string[] files = Directory.GetFiles(stateList.InFolder); foreach (string file in files) { var fileInfo = new FileInfo(file); if ((fileInfo.LastWriteTime >= stateList.FromDate) && (fileInfo.LastWriteTime <= stateList.ToDate)) { File.Copy(file, Path.Combine(stateList.OutFolder, fileInfo.Name), true); } UpdateProgress(1); } }
private void bCreate_Click(object sender, EventArgs e) { if (_working) { return; } try { string outputFolder = tbOutFolder.Text; DateTime fromDate = dtpFromDate.Value; DateTime toDate = dtpToDate.Value; if (string.IsNullOrEmpty(outputFolder)) { throw new InvalidDataException("The output folder specified not true."); } if (fromDate > toDate) { throw new InvalidTimeZoneException("The time period specified is not true."); } if (!Directory.Exists(_game.InstallDir)) { throw new DirectoryNotFoundException("The original game folder not found."); } if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } Settings.Default.OutFolder = outputFolder; Settings.Default.Save(); _working = true; bCreate.Enabled = false; pbProgress.Value = 0; pbProgress.Maximum = FilesCount(_game.InstallDir) + _game.MountedDepots.Count + 1; string outFolder = Path.Combine(outputFolder, string.Concat("Update_", new DirectoryInfo(_game.InstallDir).Name.Replace(' ', '_'), "_SteamRip")); if (!Directory.Exists(outFolder)) { Directory.CreateDirectory(outFolder); } string gameFolder = Path.Combine(outFolder, new DirectoryInfo(_game.InstallDir).Name); if (!Directory.Exists(gameFolder)) { Directory.CreateDirectory(gameFolder); } var createUpdateState = new CreateUpdateStruct() { InFolder = _game.InstallDir, OutFolder = gameFolder, FromDate = fromDate, ToDate = toDate, }; ThreadPool.QueueUserWorkItem(CreateUpdate, createUpdateState); var copySteamFilesState = new CopySteamFilesStruct() { OutFolder = Path.Combine(outFolder, "Steam"), ManifestFile = _game.Manifest, ManifestOutPath = Resources.SteamSteamAppsDefaultPath, Depotcache = _game.MountedDepots, DepotcacheOutPath = Resources.SteamDepotcachePath, FromDate = fromDate, ToDate = toDate }; ThreadPool.QueueUserWorkItem(CopySteamFiles, copySteamFilesState); } catch (DirectoryNotFoundException ex) { MessageBox.Show(ex.Message, @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } catch (InvalidTimeZoneException ex) { MessageBox.Show(ex.Message, @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } catch (InvalidDataException ex) { MessageBox.Show(ex.Message, @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }