⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlhandler.cs

📁 这是一个小型的相片管理器
💻 CS
字号:


using System;
using System.IO;
using System.Xml;
using TXML;

namespace VirtualPhotoOrganizer.Util
{
	/// <summary>
	/// handles Xml file access for TommazzosPhotoAlbum
	/// </summary>
	internal class XmlHandler
	{
		// the files used for storing TPA settings
		private static string SettingsDir = Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData) + "\\VirtualPhotoOrganizer";
		private static string VPO_Settings = SettingsDir + "\\Settings.xml";
		private static string VPO_RootAlbum = SettingsDir + "\\RootAlbum.xml";
		private static string _LangFile = "English.xml";

		public XmlHandler() {
			// no ctor required - all methods are static
		}

		/// <summary>
		/// Returns a reference to a TXmlReader pointing to the VPO settings file
		/// </summary>
		internal static TXmlReader OpenSettingsReader() {
			if (!File.Exists(VPO_Settings))	// check if the file doesn't exist
			{
				// check if the directory exists
				if (!Directory.Exists(SettingsDir))
					Directory.CreateDirectory(SettingsDir);

				// create a new file with a TXmlWriter
				TXmlWriter writer = new TXmlWriter(VPO_Settings, "VPO_Settings", 4);
				writer.Close();
			}

			// open the file with a TXmlReader
			TXmlReader reader = new TXmlReader(VPO_Settings);
			return reader;
		}

		/// <summary>
		/// Returns a reference to a TXmlWriter pointing to the VPO settings file
		/// </summary>
		internal static TXmlWriter OpenSettingsWriter() {
			// check if directory exists
			if (!Directory.Exists(SettingsDir))
				Directory.CreateDirectory(SettingsDir);

			// create TXmlWriter
			TXmlWriter writer = new TXmlWriter(VPO_Settings, "VPO_Settings", 4);
			return writer;
		}

		/// <summary>
		/// Returns a reference to a TXmlReader pointing to the VPO RootAlbum file
		/// </summary>
		internal static TXmlReader OpenRootAlbumReader() {
			if (!File.Exists(VPO_RootAlbum))	// check if the file doesn't exist
			{
				// check if the directory exists
				if (!Directory.Exists(SettingsDir))
					Directory.CreateDirectory(SettingsDir);

				// create a new file with a TXmlWriter
				TXmlWriter writer = new TXmlWriter(VPO_RootAlbum, "VPO_RootAlbum", 4);
				writer.Close();
			}

			// open the file with a TXmlReader
			TXmlReader reader = new TXmlReader(VPO_RootAlbum);
			return reader;
		}

		/// <summary>
		/// Returns a reference to a TXmlWriter pointing to the VPO RootAlbum file
		/// </summary>
		internal static TXmlWriter OpenRootAlbumWriter() {
			// check if directory exists
			if (!Directory.Exists(SettingsDir))
				Directory.CreateDirectory(SettingsDir);

			// if the file already exists delete it
			if (File.Exists(VPO_RootAlbum))
				File.Delete(VPO_RootAlbum);

			// create TXmlWriter
			TXmlWriter writer = new TXmlWriter(VPO_RootAlbum, "VPO_RootAlbum", 4);
			return writer;
		}

		/// <summary>
		/// accessor for the Lang_File property
		/// </summary>
		internal static string LangFile {
			get { return _LangFile; }
			set { _LangFile = value; }
		}

		/// <summary>
		/// Returns a reference to a TXmlReader pointing to the currently selected language file
		/// </summary>
		internal static TXmlReader OpenLangFile() {
			// open the file with a TXmlReader
			TXmlReader reader = new TXmlReader(System.Windows.Forms.Application.StartupPath + "\\Lang\\" + _LangFile);
			return reader;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -