using System.IO; using System.Windows; using System.Windows.Forms; using BetterPatchFileCreator.Code; namespace BetterPatchFileCreator.XAML.PageFuncs { /// /// Interaction logic for CreateNewConfigPageFunc.xaml /// public partial class CreateNewConfigPageFunc : ObjectPageFunc { private PatchConfig config; public CreateNewConfigPageFunc() { InitializeComponent(); } private void PathGotFocus(object sender, RoutedEventArgs e) { FolderBrowserDialog dialog = new FolderBrowserDialog(); if (dialog.ShowDialog() == DialogResult.OK) { tbPath.Text = dialog.SelectedPath; } } private void OkClick(object sender, RoutedEventArgs e) { CreatePatchConfig(); CreateDirectories(); IndexClient(); } private void CreatePatchConfig() { config = new PatchConfig { Name = tbName.Text, Description = tbDesc.Text, Version = 0, ClientPath = tbPath.Text, }; config.PatchFilePath = config.GetDataPath(); config.XmlPath = config.GetXmlPath(); } private void CreateDirectories() { CreateDirectory(config.GetBasePath()); CreateDirectory(config.PatchFilePath); CreateDirectory(config.XmlPath); } private static void CreateDirectory(string path) { DirectoryInfo info = new DirectoryInfo(path); if (!info.Exists) { info.Create(); } } private void IndexClient() { var page = new IndexingClientPageFunc(config); page.OnReturn += IndexingReturn; page.Start(); DataProvider.MainWindowInstance.Navigate(page); } private void IndexingReturn(object sender, PageFunctionEventArgs e) { DataProvider.MainWindowInstance.Navigate(this); DataProvider.PatchConfigs.Add(config); ReturnValue(null); } } }