private void Import_Click(object sender, RoutedEventArgs e) { Mod mod = new Mod() { Name = remoteModList.SelectedValue.ToString(), ModStorePath = ModUtility.SelectModPath() }; if (mod.IsPathDefined) { ModSynchronizationWindow synchronizationWindow = new ModSynchronizationWindow(SynchronizationMode.Local, mod); synchronizationWindow.Show(); Close(); } }
private void SynchronizeModToLocal() { try { using (Session session = new Session()) { // Will continuously report progress of synchronization session.FileTransferred += FileTransferred; // Will continuously report progress of transfer session.FileTransferProgress += SessionFileTransferProgress; //string fp = "ssh-rsa 2048 iGUY6ftkfgyHQ+Qcz1ntutaiSed8CETlcVb6elUO/Zk=."; //string fingerprint = session.ScanFingerprint(sessionOptions, "ssh-rsa"); //sessionOptions.SshHostKeyFingerprint = fp; // Connect session.Open(_sessionOptions); if (!session.FileExists(_remoteModPath)) { MessageBox.Show(string.Format("The mod [{0}] doesn't exist in the remote repository [{1}].", Mod.Name, Settings.Default.RepositoryStoragePath)); return; } if (!Directory.Exists(_localModPath)) { Directory.CreateDirectory(_localModPath); } RemoteDirectoryInfo remoteDirectoryInfo = session.ListDirectory(_remoteModPath); _countFilesToSynchronize = remoteDirectoryInfo.Files.Count; SynchronizationResult synchronizationResult = session.SynchronizeDirectories(SynchronizationMode.Local, _localModPath, _remoteModPath, true); // Throw on any error synchronizationResult.Check(); StringBuilder failedFiles = new StringBuilder(); foreach (TransferEventArgs failedFile in synchronizationResult.Failures) { failedFiles.AppendLine(string.Format("{0}", failedFile.FileName)); } if (failedFiles.Length > 0) { MessageBox.Show(failedFiles.ToString(), "Error downloading files."); } if (synchronizationResult.IsSuccess) { Dispatcher.Invoke(new Action(() => { overallPercentage.Content = string.Format("{0:P0}", 1); overallProgress.Value = 100; statusText.Text = "Operation succeeded."; string modName = Path.GetFileName(_localModPath); Mod synchedMod = ModUtility.LoadFile(Path.Combine(_localModPath, string.Format("{0}.json", modName))); foreach (Window window in Application.Current.Windows) { if (window.GetType() == typeof(MainWindow)) { (window as MainWindow).Mod = synchedMod; (window as MainWindow).BindObject(); } } })); } } } catch (Exception ex) { Console.WriteLine("Error: {0}", ex); } }