示例#1
0
		/// <summary>Loads a package database XML file as the current database</summary>
		/// <param name="Folder">The root database folder</param>
		/// <param name="File">The database file</param>
		/// <returns>Whether the loading succeded</returns>
		public static bool LoadDatabase(string Folder, string File)
		{
			currentDatabaseFolder = Folder;
			currentDatabaseFile = File;
			if (System.IO.File.Exists(currentDatabaseFile))
			{
				try
				{
					XmlSerializer listReader = new XmlSerializer(typeof(PackageDatabase));
					using (XmlReader reader = XmlReader.Create(currentDatabaseFile))
					{
						currentDatabase = (PackageDatabase) listReader.Deserialize(reader);
					}
				}
				catch
				{
					//Loading the DB failed, so just create a new one
					currentDatabase = null;
				}
			}
			if (currentDatabase == null)
			{
				currentDatabase = new PackageDatabase
				{
					InstalledRoutes = new List<Package>(),
					InstalledTrains = new List<Package>(),
					InstalledOther = new List<Package>()
				};
				return false;
			}
			return true;
		}