Exemplo n.º 1
0
		private void Q1_CheckedChanged(object sender, EventArgs e)
		{
			filesToPackage = null;
			filesToPackageBox.Text = String.Empty;
			if (radioButtonQ1Yes.Checked == true)
			{
				if (Database.currentDatabase.InstalledRoutes.Count == 0 && Database.currentDatabase.InstalledTrains.Count == 0 && Database.currentDatabase.InstalledOther.Count == 0)
				{
					//There are no packages available to replace....
					string test = Interface.GetInterfaceString("packages_replace_noneavailable");
					MessageBox.Show(test);
					radioButtonQ1No.Checked = true;
					return;
				}
				panelReplacePackage.Show();
				panelNewPackage.Hide();
				switch (newPackageType)
				{
					case PackageType.Route:
						PopulatePackageList(Database.currentDatabase.InstalledRoutes, dataGridViewReplacePackage, true, false, false);
						break;
					case PackageType.Train:
						PopulatePackageList(Database.currentDatabase.InstalledTrains, dataGridViewReplacePackage, true, false, false);
						break;
					case PackageType.Other:
						PopulatePackageList(Database.currentDatabase.InstalledOther, dataGridViewReplacePackage, true, false, false);
						break;
				}
				dataGridViewReplacePackage.ClearSelection();
			}
			else
			{
				panelReplacePackage.Hide();
				panelNewPackage.Show();
				panelNewPackage.Enabled = true;
				string GUID = Guid.NewGuid().ToString();
				currentPackage = new Package
				{
					Name = textBoxPackageName.Text,
					Author = textBoxPackageAuthor.Text,
					Description = textBoxPackageDescription.Text.Replace("\r\n", "\\r\\n"),
					//TODO:
					//Website = linkLabelPackageWebsite.Links[0],
					GUID = GUID,
					PackageVersion = new Version(0, 0, 0, 0),
					PackageType = newPackageType
				};
				textBoxGUID.Text = currentPackage.GUID;
				SaveFileNameButton.Enabled = true;
			}
		}
Exemplo n.º 2
0
		private void dataGridViewPackages2_SelectionChanged(object sender, EventArgs e)
		{
			if (dataGridViewPackages2.SelectedRows.Count == 0 || listPopulating == true)
			{
				buttonDepends.Enabled = false;
				buttonReccomends.Enabled = false;
				dependantPackage = null;
				return;
			}
			buttonDepends.Enabled = true;
			buttonReccomends.Enabled = true;
			var row = dataGridViewPackages2.SelectedRows[0].Index;
			var key = dataGridViewPackages2.Rows[row].Cells[dataGridViewPackages2.ColumnCount - 1].Value.ToString();
			switch (comboBoxDependancyType.SelectedIndex)
			{
				case 0:
					dependantPackage = new Package(Database.currentDatabase.InstalledRoutes.FirstOrDefault(x => x.GUID == key), true);
					break;
				case 1:
					dependantPackage = new Package(Database.currentDatabase.InstalledTrains.FirstOrDefault(x => x.GUID == key), true);
					break;
				case 2:
					dependantPackage = new Package(Database.currentDatabase.InstalledOther.FirstOrDefault(x => x.GUID == key), true);
					break;
			}
		}
Exemplo n.º 3
0
		private void createPackageButton_Click(object sender, EventArgs e)
		{
			currentPackage = null;
			HidePanels();
			buttonSelectPackage.Visible = false;
			buttonNext.Enabled = true;
			panelCreatePackage.Show();
		}
Exemplo n.º 4
0
		/// <summary>Checks to see if this package is currently installed, and if so whether there is another version installed</summary>
		/// <param name="currentPackage">The package to check</param>
		/// <param name="packageList">The list of currently installed packages</param>
		/// <param name="oldPackage">Returns via 'ref' the current package installed</param>
		/// <returns>Whether the package to check is installed, and if so whether it is an older, newer or identical version</returns>
		public static VersionInformation CheckVersion(Package currentPackage, List<Package> packageList, ref Package oldPackage)
		{
			if (packageList == null)
			{
				//List is null, so we can't possibly be in it
				return VersionInformation.NotFound;
			}
			foreach (var Package in packageList)
			{
				//Check GUID
				if (currentPackage.GUID == Package.GUID)
				{
					oldPackage = currentPackage;
					//GUID found, check versions
					if (currentPackage.PackageVersion == Package.PackageVersion)
					{
						//The versions are the same
						return VersionInformation.SameVersion;
					}
					if (currentPackage.PackageVersion > Package.PackageVersion)
					{
						//This is an older version, so update the ref with the found version number
						return VersionInformation.OlderVersion;
					}
					if (currentPackage.PackageVersion < Package.PackageVersion)
					{
						//This is a newer version, but it's good manners to point out that this will be replacing an older version
						return VersionInformation.NewerVersion;
					}
					
				}
			}
			//We didn't find our package as currently installed
			return VersionInformation.NotFound;
		}
Exemplo n.º 5
0
		private void dataGridViewReplacePackage_SelectionChanged(object sender, EventArgs e)
		{
			if (dataGridViewReplacePackage.SelectedRows.Count > 0 || listPopulating != true)
			{
				replacePackageButton.Enabled = true;
				var row = dataGridViewReplacePackage.SelectedRows[0].Index;
				var key = dataGridViewReplacePackage.Rows[row].Cells[dataGridViewReplacePackage.ColumnCount - 1].Value.ToString();
				switch (newPackageType)
				{
					case PackageType.Route:
						currentPackage = new Package(Database.currentDatabase.InstalledRoutes.FirstOrDefault(x => x.GUID == key), false)
						{
							PackageType = PackageType.Route
						};
						break;
					case PackageType.Train:
						currentPackage = new Package(Database.currentDatabase.InstalledTrains.FirstOrDefault(x => x.GUID == key), false)
						{
							PackageType = PackageType.Train
						};
						break;
					case PackageType.Other:
						currentPackage = new Package(Database.currentDatabase.InstalledOther.FirstOrDefault(x => x.GUID == key), false)
						{
							PackageType = PackageType.Other
						};
						break;
				}
			}
			else replacePackageButton.Enabled = false;
		}
Exemplo n.º 6
0
		/// <summary>This extracts a package, and returns the list of extracted files</summary>
		/// <param name="currentPackage">The package to extract</param>
		/// <param name="extractionDirectory">The directory to extract to</param>
		/// <param name="databaseFolder">The root package database folder</param>
		/// <param name="packageFiles">Returns via 'ref' a string containing a list of files in the package (Used to update the dialog)</param>
		public static void ExtractPackage(Package currentPackage, string extractionDirectory, string databaseFolder, ref string packageFiles)
		{
			int i = 0;
			int j = 0;
			string fp = String.Empty;
			try
			{
				using (Stream stream = File.OpenRead(currentPackage.PackageFile))
				{

					var reader = ArchiveFactory.Open(stream);
					List<string> PackageFiles = new List<string>();
					j = reader.Entries.Count();
					foreach (var archiveEntry in reader.Entries)
					{
						fp = archiveEntry.Key;
						if (archiveEntry.Key.ToLowerInvariant() == "package.xml" || archiveEntry.Key.ToLowerInvariant() == "package.png" ||
						    archiveEntry.Key.ToLowerInvariant() == "package.rtf" || archiveEntry.Key.ToLowerInvariant() == "thumbs.db")
						{
							//Skip package information files
						}
						else if (archiveEntry.Size == 0)
						{
							//Skip zero-byte files
						}
						else
						{
							//Extract everything else, preserving directory structure
							archiveEntry.WriteToDirectory(extractionDirectory, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
							//We don't want to add directories to the list of files
							if (!archiveEntry.IsDirectory)
							{
								PackageFiles.Add(OpenBveApi.Path.CombineFile(extractionDirectory, archiveEntry.Key));
							}
						}
						i++;
						OnProgressChanged(null, new ProgressReport((int) ((double) i / j * 100), archiveEntry.Key));
					}

					string Text = "";
					foreach (var FileName in PackageFiles)
					{
						Text += FileName + "\r\n";
					}
					packageFiles = Text;
					//Write out the package file list
					var fileListDirectory = OpenBveApi.Path.CombineDirectory(databaseFolder, "Installed");
					if (!Directory.Exists(fileListDirectory))
					{
						Directory.CreateDirectory(fileListDirectory);
					}
					var fileList = OpenBveApi.Path.CombineFile(fileListDirectory, currentPackage.GUID.ToUpper() + ".xml");
					using (StreamWriter sw = new StreamWriter(fileList))
					{
						XmlSerializer listWriter = new XmlSerializer(typeof(List<string>));
						listWriter.Serialize(sw, PackageFiles);
					}
				}

			}
			catch (Exception ex)
			{
				OnProblemReport(null, new ProblemReport((int)((double)i / j * 100), fp, ex));
			}
		}
Exemplo n.º 7
0
		/// <summary>Uninstalls a package</summary>
		/// <param name="currentPackage">The package to uninstall</param>
		/// <param name="databaseFolder">The package database folder</param>
		/// <param name="PackageFiles">Returns via 'ref' a list of files uninstalled</param>
		/// <returns>True if uninstall succeeded with no errors, false otherwise</returns>
		public static bool UninstallPackage(Package currentPackage, string databaseFolder, ref string PackageFiles)
		{
			var fileList = OpenBveApi.Path.CombineFile(OpenBveApi.Path.CombineDirectory(databaseFolder, "Installed"), currentPackage.GUID.ToUpper() + ".xml");
			if (!File.Exists(fileList))
			{
				PackageFiles = null;
				//The list of files installed by this package is missing
				return false;
			}
			XmlSerializer listReader = new XmlSerializer(typeof(List<string>));
			List<string> filesToDelete;
			using (FileStream readFileStream = new FileStream(fileList, FileMode.Open, FileAccess.Read, FileShare.Read))
			{
				filesToDelete = (List<string>)listReader.Deserialize(readFileStream);
			}
			File.Delete(fileList);
			bool noErrors = true;
			int errorCount = 0;
			int deletionCount = 0;
			string Result = "";
			foreach (var String in filesToDelete)
			{
				try
				{
					File.Delete(String);
					Result += String + " deleted successfully. \r\n ";
					deletionCount++;
				}
				catch (Exception ex)
				{
					//We have caught an error....
					//Set the return type to false, and add the exception to the results string
					noErrors = false;
					Result += String + "\r\n";
					Result += ex.Message + "\r\n";
					errorCount++;
				}
			}
			//Set the final results string to display
			PackageFiles = deletionCount + " files deleted successfully. \r\n" + errorCount + " errors were encountered. \r\n \r\n \r\n" + Result;
			return noErrors;
		}
Exemplo n.º 8
0
		internal void AddDependendsReccomends(Package packageToAdd, ref List<Package> DependsReccomendsList,
			bool recommendsOnly)
		{
			var row = dataGridViewPackages2.SelectedRows[0].Index;
			var key = dataGridViewPackages2.Rows[row].Cells[dataGridViewPackages2.ColumnCount - 1].Value.ToString();
			selectedDependacies.Add(key);
			dataGridViewPackages2.Rows.RemoveAt(row);
			if (DependsReccomendsList == null)
			{
				DependsReccomendsList = new List<Package>();
			}
			packageToAdd.PackageVersion = null;
			DependsReccomendsList.Add(packageToAdd);
			dataGridViewPackages2.ClearSelection();
			if (currentPackage.Dependancies != null)
				PopulatePackageList(currentPackage.Dependancies, dataGridViewPackages3, false, true, false);
			if (currentPackage.Reccomendations != null)
				PopulatePackageList(currentPackage.Reccomendations, dataGridViewPackages3, false, false, true);
		}
Exemplo n.º 9
0
		private void buttonInstall_Click(object sender, EventArgs e)
		{
			if (creatingPackage)
			{
				if (textBoxPackageName.Text == Interface.GetInterfaceString("packages_selection_none"))
				{
					MessageBox.Show(Interface.GetInterfaceString("packages_creation_name"));
					return;
				}
				if (textBoxPackageAuthor.Text == Interface.GetInterfaceString("packages_selection_none"))
				{
					MessageBox.Show(Interface.GetInterfaceString("packages_creation_author"));
					return;
				}
				//LINK: Doesn't need checking

				if (textBoxPackageDescription.Text == Interface.GetInterfaceString("packages_selection_none"))
				{
					MessageBox.Show(Interface.GetInterfaceString("packages_creation_description"));
					return;
				}
				if (!Version.TryParse(textBoxPackageVersion.Text, out currentPackage.PackageVersion))
				{
					MessageBox.Show(Interface.GetInterfaceString("packages_creation_version"));
					return;
				}
				//Only set properties after making the checks

				currentPackage.Name = textBoxPackageName.Text;
				currentPackage.Author = textBoxPackageAuthor.Text;
				currentPackage.Description = textBoxPackageDescription.Text.Replace("\r\n", "\\r\\n");
				HidePanels();
				comboBoxDependancyType.SelectedIndex = 0;
				panelPackageDependsAdd.Show();
				PopulatePackageList(Database.currentDatabase.InstalledRoutes, dataGridViewPackages2, true, false, false);
				return;
			}
			else
			{
				List<Package> Dependancies = Database.checkDependsReccomends(currentPackage.Dependancies);
				if (Dependancies != null)
				{
					//We are missing a dependancy

					labelDependancyErrorHeader.Text = Interface.GetInterfaceString("packages_install_dependancies_unmet_header");
					labelMissingDependanciesText1.Text = Interface.GetInterfaceString("packages_install_dependancies_unmet");
					PopulatePackageList(Dependancies, dataGridViewDependancies, false, false, false);
					HidePanels();
					panelDependancyError.Show();
					return;
				}
				List<Package> Reccomendations = Database.checkDependsReccomends(currentPackage.Reccomendations);
				if (Reccomendations != null)
				{
					//We are missing a reccomendation

					labelDependancyErrorHeader.Text = Interface.GetInterfaceString("packages_install_reccomends_unmet_header");
					labelMissingDependanciesText1.Text = Interface.GetInterfaceString("packages_install_reccomends_unmet");
					PopulatePackageList(Reccomendations, dataGridViewDependancies, false, false, false);
					HidePanels();
					panelDependancyError.Show();
					return;
				}
				VersionInformation Info;
				oldPackage = null;
				switch (currentPackage.PackageType)
				{
					case PackageType.Route:
						Info = Information.CheckVersion(currentPackage, Database.currentDatabase.InstalledRoutes, ref oldPackage);
						break;
					case PackageType.Train:
						Info = Information.CheckVersion(currentPackage, Database.currentDatabase.InstalledTrains, ref oldPackage);
						break;
					default:
						Info = Information.CheckVersion(currentPackage, Database.currentDatabase.InstalledOther, ref oldPackage);
						break;
				}
				if (Info == VersionInformation.NotFound)
				{
					panelPackageInstall.Hide();
					Extract();
				}
				else
				{
					switch (Info)
					{
						case VersionInformation.NewerVersion:
							labelVersionError.Text = Interface.GetInterfaceString("packages_install_version_new");
							labelCurrentVersionNumber.Text = oldPackage.PackageVersion.ToString();
							break;
						case VersionInformation.SameVersion:
							labelVersionError.Text = Interface.GetInterfaceString("packages_install_version_same");
							labelCurrentVersionNumber.Text = currentPackage.PackageVersion.ToString();
							break;
						case VersionInformation.OlderVersion:
							labelVersionError.Text = Interface.GetInterfaceString("packages_install_version_old");
							labelCurrentVersionNumber.Text = oldPackage.PackageVersion.ToString();
							break;
					}
					labelNewVersionNumber.Text = currentPackage.PackageVersion.ToString();
					if (currentPackage.Dependancies.Count != 0)
					{
						List<Package> brokenDependancies = OpenBveApi.Packages.Information.UpgradeDowngradeDependancies(currentPackage,
							Database.currentDatabase.InstalledRoutes, Database.currentDatabase.InstalledTrains);
						if (brokenDependancies != null)
						{
							PopulatePackageList(brokenDependancies, dataGridViewBrokenDependancies, false, false, false);
						}
					}
					HidePanels();
					panelVersionError.Show();
				}
			}
		}
Exemplo n.º 10
0
		private void Extract(Package packageToReplace = null)
		{
			ProblemEncountered = false;
			panelPleaseWait.Show();
			workerThread.DoWork += delegate
			{
				string ExtractionDirectory;
				switch (currentPackage.PackageType)
				{
					case PackageType.Route:
						ExtractionDirectory = Program.FileSystem.RouteInstallationDirectory;
						break;
					case PackageType.Train:
						ExtractionDirectory = Program.FileSystem.TrainInstallationDirectory;
						break;
					default:
						ExtractionDirectory = Program.FileSystem.OtherInstallationDirectory;
						break;
				}
				string PackageFiles = "";
				Manipulation.ExtractPackage(currentPackage, ExtractionDirectory, currentDatabaseFolder, ref PackageFiles);
				if (ProblemEncountered == false)
				{
					textBoxFilesInstalled.Invoke((MethodInvoker) delegate
					{
						textBoxFilesInstalled.Text = PackageFiles;
					});
				}
			};
			workerThread.RunWorkerCompleted += delegate
			{
				if (!ProblemEncountered)
				{

					switch (currentPackage.PackageType)
					{
						case PackageType.Route:
							if (packageToReplace != null)
							{
								for (int i = Database.currentDatabase.InstalledRoutes.Count; i > 0; i--)
								{
									if (Database.currentDatabase.InstalledRoutes[i - 1].GUID == currentPackage.GUID)
									{
										Database.currentDatabase.InstalledRoutes.Remove(Database.currentDatabase.InstalledRoutes[i - 1]);
									}
								}
							}
							Database.currentDatabase.InstalledRoutes.Add(currentPackage);
							break;
						case PackageType.Train:
							if (packageToReplace != null)
							{
								for (int i = Database.currentDatabase.InstalledTrains.Count; i > 0; i--)
								{
									if (Database.currentDatabase.InstalledTrains[i - 1].GUID == currentPackage.GUID)
									{
										Database.currentDatabase.InstalledTrains.Remove(Database.currentDatabase.InstalledTrains[i - 1]);
									}
								}
							}
							Database.currentDatabase.InstalledTrains.Add(currentPackage);
							break;
						default:
							if (packageToReplace != null)
							{
								for (int i = Database.currentDatabase.InstalledOther.Count; i > 0; i--)
								{
									if (Database.currentDatabase.InstalledOther[i - 1].GUID == currentPackage.GUID)
									{
										Database.currentDatabase.InstalledOther.Remove(Database.currentDatabase.InstalledOther[i - 1]);
									}
								}
							}
							Database.currentDatabase.InstalledOther.Add(currentPackage);
							break;
					}
					labelInstallSuccess1.Text = Interface.GetInterfaceString("packages_install_success");
					labelInstallSuccess2.Text = Interface.GetInterfaceString("packages_install_success_header");
					labelListFilesInstalled.Text = Interface.GetInterfaceString("packages_install_success_files");
				}
				panelPleaseWait.Hide();
				panelSuccess.Show();
			};
			workerThread.RunWorkerAsync();
		}
Exemplo n.º 11
0
		/// <summary>This method should be called to uninstall a package</summary>
		internal void UninstallPackage(Package packageToUninstall, ref List<Package> Packages)
		{

			string uninstallResults = "";
			List<Package> brokenDependancies = Database.CheckUninstallDependancies(packageToUninstall.Dependancies);
			if (brokenDependancies.Count != 0)
			{
				PopulatePackageList(brokenDependancies, dataGridViewBrokenDependancies, false, false, false);
				labelMissingDependanciesText1.Text = Interface.GetInterfaceString("packages_uninstall_broken");
				HidePanels();
				panelDependancyError.Show();
			}
			if (Manipulation.UninstallPackage(packageToUninstall, currentDatabaseFolder, ref uninstallResults))
			{
				Packages.Remove(packageToUninstall);
				switch (packageToUninstall.PackageType)
				{
					case PackageType.Other:
						DatabaseFunctions.cleanDirectory(Program.FileSystem.OtherInstallationDirectory, ref uninstallResults);
						break;
					case PackageType.Route:
						DatabaseFunctions.cleanDirectory(Program.FileSystem.RouteInstallationDirectory, ref uninstallResults);
						break;
					case PackageType.Train:
						DatabaseFunctions.cleanDirectory(Program.FileSystem.TrainInstallationDirectory, ref uninstallResults);
						break;
				}
				labelUninstallSuccess.Text = Interface.GetInterfaceString("packages_uninstall_success");
				labelUninstallSuccessHeader.Text = Interface.GetInterfaceString("packages_uninstall_success_header");
				textBoxUninstallResult.Text = uninstallResults;
				HidePanels();
				panelUninstallResult.Show();
			}
			else
			{
				labelUninstallSuccess.Text = Interface.GetInterfaceString("packages_uninstall_success");
				labelUninstallSuccessHeader.Text = Interface.GetInterfaceString("packages_uninstall_success_header");
				if (uninstallResults == null)
				{
					//Uninstall requires an XML list of files, and these were missing.......
					textBoxUninstallResult.Text = Interface.GetInterfaceString("packages_uninstall_missing_xml");
					currentPackage = packageToUninstall;
					RemoveFromDatabase = false;
				}
				else
				{
					//Something went wrong in the uninstallation process, so show the log
					//TODO: This doesn't log anything other than a list of files at the minute
					textBoxUninstallResult.Text = uninstallResults;
				}
			}
			HidePanels();
			panelUninstallResult.Show();
		}
Exemplo n.º 12
0
		private void buttonSelectPackage_Click(object sender, EventArgs e)
		{
			if (openPackageFileDialog.ShowDialog() == DialogResult.OK)
			{
				currentPackage = Manipulation.ReadPackage(openPackageFileDialog.FileName);
				if (currentPackage != null)
				{
					buttonNext.Enabled = true;
					textBoxPackageName.Text = currentPackage.Name;
					textBoxPackageAuthor.Text = currentPackage.Author;
					if (currentPackage.Description != null)
					{
						textBoxPackageDescription.Text = currentPackage.Description.Replace("\\r\\n", "\r\n");
					}
					textBoxPackageVersion.Text = currentPackage.PackageVersion.ToString();
					if (currentPackage.Website != null)
					{
						linkLabelPackageWebsite.Links.Clear();
						linkLabelPackageWebsite.Text = currentPackage.Website;
						LinkLabel.Link link = new LinkLabel.Link {LinkData = currentPackage.Website};
						linkLabelPackageWebsite.Links.Add(link);
					}
					else
					{
						linkLabelPackageWebsite.Text = Interface.GetInterfaceString("packages_selection_none_website");
					}
					if (currentPackage.PackageImage != null)
					{
						pictureBoxPackageImage.Image = currentPackage.PackageImage;
					}
					else
					{
						TryLoadImage(pictureBoxPackageImage, currentPackage.PackageType == 0 ? "route_unknown.png" : "train_unknown.png");
					}
				}
				else
				{
					//ReadPackage returns null if the file is not a package.....

					MessageBox.Show(Interface.GetInterfaceString("packages_install_invalid"));
				}
			}
		}
Exemplo n.º 13
0
		//This method resets the package installer to the default panels when clicking away, or when a creation/ install has finished
		private void ResetInstallerPanels()
		{
			HidePanels();
			panelPackageList.Show();
			creatingPackage = false;
			//Reset radio buttons in the installer
			radioButtonQ1Yes.Checked = false;
			radioButtonQ1No.Checked = false;
			radioButtonQ2Route.Checked = false;
			radioButtonQ2Train.Checked = false;
			radioButtonQ2Other.Checked = false;
			//Reset picturebox
			TryLoadImage(pictureBoxPackageImage, "route_unknown.png");
			TryLoadImage(pictureBoxProcessing, "logo.png");
			//Reset enabled boxes & panels
			textBoxGUID.Text = string.Empty;
			textBoxGUID.Enabled = false;
			SaveFileNameButton.Enabled = false;
			panelReplacePackage.Hide();
			panelNewPackage.Enabled = false;
			panelNewPackage.Show();
			textBoxPackageDescription.ReadOnly = true;
			textBoxPackageName.ReadOnly = true;
			textBoxPackageVersion.ReadOnly = true;
			textBoxPackageAuthor.ReadOnly = true;
			//Set variables to uninitialised states
			creatingPackage = false;
			currentPackage = null;
			dependantPackage = null;
			newPackageType = PackageType.NotFound;
			ImageFile = null;
			RemoveFromDatabase = true;
			selectedDependacies = new List<string>();
			filesToPackage = null;
			//Reset package lists
			dataGridViewPackages2.Rows.Clear();
			dataGridViewPackages3.Rows.Clear();
			//Reset text
			textBoxPackageAuthor.Text = Interface.GetInterfaceString("packages_selection_none");
			textBoxPackageName.Text = Interface.GetInterfaceString("packages_selection_none");
			textBoxPackageDescription.Text = Interface.GetInterfaceString("packages_selection_none");
			textBoxPackageVersion.Text = Interface.GetInterfaceString("packages_selection_none");
			buttonSelectPackage.Text = Interface.GetInterfaceString("packages_install_select");
			labelNewGUID.Text = Interface.GetInterfaceString("packages_creation_new_id");
			linkLabelPackageWebsite.Links.Clear();
			linkLabelPackageWebsite.Text = Interface.GetInterfaceString("packages_selection_none_website");
			LinkLabel.Link link = new LinkLabel.Link { LinkData = null };
			linkLabelPackageWebsite.Links.Add(link);
			buttonBack2.Text = Interface.GetInterfaceString("packages_button_back");
			buttonNext.Enabled = false;
			buttonSelectPackage.Visible = true;
			//Reset the worker thread
			while (workerThread.IsBusy)
			{
				Thread.Sleep(10);
			}
			workerThread = null;
			workerThread = new BackgroundWorker();
		}	
Exemplo n.º 14
0
		private void comboBoxPackageType_SelectedIndexChanged(object sender, EventArgs e)
		{
			switch (comboBoxPackageType.SelectedIndex)
			{
				case 0:
					PopulatePackageList(Database.currentDatabase.InstalledRoutes, dataGridViewPackages, true, false, false);
					break;
				case 1:
					PopulatePackageList(Database.currentDatabase.InstalledTrains, dataGridViewPackages, true, false, false);
					break;
				case 2:
					PopulatePackageList(Database.currentDatabase.InstalledOther, dataGridViewPackages, true, false, false);
					break;
			}
			currentPackage = null;
			dataGridViewPackages.ClearSelection();
		}
Exemplo n.º 15
0
		private void Q2_CheckedChanged(object sender, EventArgs e)
		{
			filesToPackage = null;
			filesToPackageBox.Text = string.Empty;
			radioButtonQ1Yes.Enabled = true;
			radioButtonQ1No.Enabled = true;
			labelReplacePackage.Enabled = true;
			if (radioButtonQ2Route.Checked)
			{
				newPackageType = PackageType.Route;
			}
			else if (radioButtonQ2Train.Checked)
			{
				newPackageType = PackageType.Train;
			}
			else
			{
				newPackageType = PackageType.Other;
			}
			if (radioButtonQ1Yes.Checked == true)
			{
				panelReplacePackage.Show();
				panelNewPackage.Hide();
				switch (newPackageType)
				{
					case PackageType.Route:
						PopulatePackageList(Database.currentDatabase.InstalledRoutes, dataGridViewReplacePackage, true, false, false);
						break;
					case PackageType.Train:
						PopulatePackageList(Database.currentDatabase.InstalledTrains, dataGridViewReplacePackage, true, false, false);
						break;
					case PackageType.Other:
						PopulatePackageList(Database.currentDatabase.InstalledOther, dataGridViewReplacePackage, true, false, false);
						break;
				}
				dataGridViewReplacePackage.ClearSelection();
			}
			else
			{
				panelReplacePackage.Hide();
				panelNewPackage.Show();
				panelNewPackage.Enabled = false;
				if (radioButtonQ1Yes.Checked || radioButtonQ1No.Checked)
				{
					//Don't generate a new GUID if we haven't decided whether this is a new/ replacement package
					//Pointless & confusing UI update otherwise
					string GUID = Guid.NewGuid().ToString();
					currentPackage = new Package
					{
						Name = textBoxPackageName.Text,
						Author = textBoxPackageAuthor.Text,
						Description = textBoxPackageDescription.Text.Replace("\r\n", "\\r\\n"),
						//TODO:
						//Website = linkLabelPackageWebsite.Links[0],
						GUID = GUID,
						PackageVersion = new Version(0, 0, 0, 0),
						PackageType = newPackageType
					};
					textBoxGUID.Text = currentPackage.GUID;
					SaveFileNameButton.Enabled = true;
				}
			}


		}
Exemplo n.º 16
0
		private void dataGridViewPackages_SelectionChanged(object sender, EventArgs e)
		{
			if (dataGridViewPackages.SelectedRows.Count == 0 || listPopulating == true)
			{
				currentPackage = null;
				return;
			}
			var row = dataGridViewPackages.SelectedRows[0].Index;
			var key = dataGridViewPackages.Rows[row].Cells[dataGridViewPackages.ColumnCount - 1].Value.ToString();
			switch (comboBoxPackageType.SelectedIndex)
			{
				case 0:
					currentPackage = Database.currentDatabase.InstalledRoutes.FirstOrDefault(x => x.GUID == key);
					break;
				case 1:
					currentPackage = Database.currentDatabase.InstalledTrains.FirstOrDefault(x => x.GUID == key);
					break;
				case 2:
					currentPackage = Database.currentDatabase.InstalledOther.FirstOrDefault(x => x.GUID == key);
					break;
			}
		}
Exemplo n.º 17
0
		/// <summary>Creates a clone of the specified package</summary>
		/// <param name="packageToClone">The package to clone</param>
		/// <param name="dependancy">Whether this package is part of a dependancy list</param>
		public Package(Package packageToClone, bool dependancy)
		{
			Name = packageToClone.Name;
			Author = packageToClone.Author;
			GUID = packageToClone.GUID;
			Website = packageToClone.Website;
			PackageType = packageToClone.PackageType;
			Description = packageToClone.Description;
			Dependancies = packageToClone.Dependancies;
			Reccomendations = packageToClone.Reccomendations;
			Version = packageToClone.Version;
			/*
			 * If we are cloning a package, we can assume that the image will change, as these are only currently stored in archives TODO: Serialize to XML? Bad idea?
			 */

		}
Exemplo n.º 18
0
		private void buttonUninstallFinish_Click(object sender, EventArgs e)
		{
			if (currentPackage != null)
			{
				//If we were unable to uninstall the package
				//prompt as to whether the user would like to remove the broken package
				if (RemoveFromDatabase == false)
				{
					if (MessageBox.Show(Interface.GetInterfaceString("packages_uninstall_database_remove"), Interface.GetInterfaceString("program_title"), MessageBoxButtons.YesNo) == DialogResult.Yes)
					{
						RemoveFromDatabase = true;
					}
				}
				if (RemoveFromDatabase)
				{
					switch (currentPackage.PackageType)
					{
						case PackageType.Other:
							Database.currentDatabase.InstalledOther.Remove(currentPackage);
							break;
						case PackageType.Route:
							Database.currentDatabase.InstalledRoutes.Remove(currentPackage);
							break;
						case PackageType.Train:
							Database.currentDatabase.InstalledTrains.Remove(currentPackage);
							break;
					}
				}
				currentPackage = null;
			}
			RefreshPackages();
			ResetInstallerPanels();
		}
Exemplo n.º 19
0
		/// <summary>Creates a new packaged archive</summary>
		/// <param name="currentPackage">The package data we wish to compress into an archive</param>
		/// <param name="compressionType">The compression type to use for this archive</param>
		/// <param name="packageFile">The filename to save the package as</param>
		/// <param name="packageImage">The path to the image for this package, if applicable</param>
		/// <param name="packageFiles">The list of files to save within the package</param>
		public static void CreatePackage(Package currentPackage, CompressionType compressionType, string packageFile, string packageImage, List<PackageFile> packageFiles)
		{
			int cf = 0;
			
			string fp = String.Empty;
			try
			{
				using (var zip = File.OpenWrite(packageFile))
				{
					SharpCompress.Common.ArchiveType type;
					SharpCompress.Common.CompressionType compression;
					switch (compressionType)
					{
						case CompressionType.Zip:
							type = ArchiveType.Zip;
							compression = SharpCompress.Common.CompressionType.LZMA;
							break;
						case CompressionType.BZ2:
							type = ArchiveType.Zip;
							compression = SharpCompress.Common.CompressionType.BZip2;
							break;
						case CompressionType.TarGZ:
							type = ArchiveType.Tar;
							compression = SharpCompress.Common.CompressionType.GZip;
							break;
						default:
							type = ArchiveType.Zip;
							compression = SharpCompress.Common.CompressionType.LZMA;
							break;
					}
					using (var zipWriter = WriterFactory.Open(zip, type, compression))
					{
						for (int fileToAdd = 0; fileToAdd < packageFiles.Count; fileToAdd++)
						{
							cf = fileToAdd;
							PackageFile currentFile = packageFiles[fileToAdd];
							fp = currentFile.absolutePath;
							if (currentFile.absolutePath.EndsWith("thumbs.db", StringComparison.InvariantCultureIgnoreCase))
							{
								//Skip thumbs.db files, as they're often locked when creating or extracting
								//Pointless too.....
								continue;
							}
							if (new FileInfo(currentFile.absolutePath).Length == 0)
							{
								//Don't archive zero-byte files, as Sharpcompress doesn't like them.....
								continue;
							}
							//Add file to archive
							zipWriter.Write(currentFile.relativePath, currentFile.absolutePath);
							OnProgressChanged(null,
								new ProgressReport((int) ((double) fileToAdd/packageFiles.Count*100), currentFile.absolutePath));
						}
						//Create temp directory and XML file
						var tempXML = System.IO.Path.GetTempPath() + System.IO.Path.GetRandomFileName() + "package.xml";
						Directory.CreateDirectory(System.IO.Path.GetDirectoryName(tempXML));
						using (StreamWriter sw = new StreamWriter(tempXML))
						{
							//TODO: Let's see if we can get the serializer working everywhere in the solution.....
							//Haven't checked whether these are read by the reader yet.
							XmlSerializer listWriter = new XmlSerializer(typeof(SerializedPackage));
							listWriter.Serialize(sw, new SerializedPackage {Package = currentPackage});
						}
						//Write out XML
						zipWriter.Write("Package.xml", tempXML);
						//Write out image
						if (System.IO.File.Exists(packageImage))
						{
							zipWriter.Write("Package.png", packageImage);
						}
					}
				}
			}
			catch (Exception ex)
			{
				OnProblemReport(null, new ProblemReport((int)((double)cf / packageFiles.Count * 100), fp, ex));
			}
		}
Exemplo n.º 20
0
		private void buttonInstallPackage_Click(object sender, EventArgs e)
		{
			currentPackage = null;
			labelInstallText.Text = Interface.GetInterfaceString("packages_install_header");
			buttonBack2.Text = Interface.GetInterfaceString("packages_button_cancel");
			TryLoadImage(pictureBoxPackageImage, "route_error.png");
			HidePanels();
			panelPackageInstall.Show();
		}
Exemplo n.º 21
0
		/// <summary>Reads the information of the selected package</summary>
		public static Package ReadPackage(string packageFile)
		{
			bool InfoFound = false;
			//Create a random temp directory
			string TempDirectory = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetRandomFileName());

			Package currentPackage = new Package();
			Directory.CreateDirectory(TempDirectory);
			//Load the selected package file into a stream
			using (Stream stream = File.OpenRead(packageFile))
			{
				
				var reader = ReaderFactory.Open(stream);
				while (reader.MoveToNextEntry())
				{

					//Search for the package.xml file- This must be located in the archive root
					if (reader.Entry.Key.ToLowerInvariant() == "package.xml")
					{
						reader.WriteEntryToDirectory(TempDirectory, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
						//Load the XML file
						InfoFound = true;
						XmlSerializer listReader = new XmlSerializer(typeof(SerializedPackage));
						SerializedPackage newPackage = (SerializedPackage)listReader.Deserialize(XmlReader.Create(OpenBveApi.Path.CombineFile(TempDirectory, "package.xml")));
						currentPackage = newPackage.Package;
					}
					if (reader.Entry.Key.ToLowerInvariant() == "package.png")
					{
						//Extract the package.png to the uniquely assigned temp directory
						reader.WriteEntryToDirectory(TempDirectory, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
						try
						{
							currentPackage.PackageImage = Image.FromFile(Path.CombineFile(TempDirectory, "package.png"));
						}
						catch
						{
							//Image loading failed
							currentPackage.PackageImage = null;
						}
					}
					/*
					 * May have to change to plaintext-
					 * No way of easily storing a RTF object....
					 * 
					 */
					if (reader.Entry.Key.ToLowerInvariant() == "package.rtf")
					{
						//Extract the package.rtf description file to the uniquely assigned temp directory
						reader.WriteEntryToDirectory(TempDirectory, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
						//PackageDescription.LoadFile(OpenBveApi.Path.CombineFile(TempDirectory, "package.rtf"));
					}

				}
			}
			if (!InfoFound)
			{
				//No info found, return null.....
				return null;
			}
			//Read the info

			if (currentPackage.Equals(new Package()))
			{
				//Somewhat hacky way to quickly check if all elements are null....
				return null;
			}
			currentPackage.PackageFile = packageFile;
			return currentPackage;
		}
Exemplo n.º 22
0
		private void buttonReccomends_Click(object sender, EventArgs e)
		{
			switch (dependantPackage.PackageType)
			{
				case PackageType.Route:
					if (ShowVersionDialog(ref dependantPackage.MinimumVersion, ref dependantPackage.MaximumVersion, dependantPackage.Version, Interface.GetInterfaceString("packages_creation_reccomends_add")) == DialogResult.OK)
					{
						AddDependendsReccomends(dependantPackage, ref currentPackage.Reccomendations, true);
						dependantPackage = null;
					}
					break;
				case PackageType.Train:
					if (ShowVersionDialog(ref dependantPackage.MinimumVersion, ref dependantPackage.MaximumVersion, dependantPackage.Version, Interface.GetInterfaceString("packages_creation_reccomends_add")) == DialogResult.OK)
					{
						AddDependendsReccomends(dependantPackage, ref currentPackage.Reccomendations, true);
						dependantPackage = null;
					}
					break;
				case PackageType.Other:
					if (ShowVersionDialog(ref dependantPackage.MinimumVersion, ref dependantPackage.MaximumVersion, dependantPackage.Version, Interface.GetInterfaceString("packages_creation_reccomends_add")) == DialogResult.OK)
					{
						AddDependendsReccomends(dependantPackage, ref currentPackage.Reccomendations, true);
						dependantPackage = null;
					}
					break;
			}
		}
Exemplo n.º 23
0
		/// <summary>Checks to see if upgrading or downgrading this package will break any dependancies</summary>
		public static List<Package> UpgradeDowngradeDependancies(Package currentPackage, List<Package> installedRoutes, List<Package> installedTrains)
		{
			List<Package> Dependancies = new List<Package>();
			if (installedRoutes != null)
			{
				foreach (Package routePackage in installedRoutes)
				{
					//Itinerate through the routes list
					foreach (Package Package in routePackage.Dependancies)
					{
						if (Package.GUID == currentPackage.GUID)
						{
							if (Package.MinimumVersion > currentPackage.PackageVersion ||
								Package.MaximumVersion < currentPackage.PackageVersion)
							{
								Dependancies.Add(Package);
							}
						}
					}

				}
			}
			if (installedTrains != null)
			{
				foreach (Package trainPackage in installedTrains)
				{
					//Itinerate through the routes list
					foreach (Package Package in trainPackage.Dependancies)
					{
						if (Package.GUID == currentPackage.GUID)
						{
							if (Package.MinimumVersion > currentPackage.PackageVersion ||
								Package.MaximumVersion < currentPackage.PackageVersion)
							{
								Dependancies.Add(Package);
							}
						}
					}

				}
			}
			if (Dependancies.Count == 0)
			{
				//Return null if there are no unmet dependancies
				return null;
			}
			return Dependancies;
		}
Exemplo n.º 24
0
		/// <summary>Checks whether a dependancy is met by a member of a list of packages</summary>
		/// <param name="dependancy">The dependancy</param>
		/// <param name="currentList">The package list to check</param>
		public static bool DependancyMet(Package dependancy, List<Package> currentList)
		{
			if (currentList == null)
			{
				return false;
			}
			foreach (Package Package in currentList)
			{
				//Check GUID
				if (Package.GUID == dependancy.GUID)
				{
					if ((dependancy.MinimumVersion == null || dependancy.MinimumVersion <= Package.PackageVersion) &&
						(dependancy.MaximumVersion == null || dependancy.MaximumVersion >= Package.PackageVersion))
					{
						//If the version is OK, remove
						return true;
					}
				}
			}
			return false;
		}