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

📄 environment.cs

📁 POCKET PC,照片管理系统!提供了真正意义上的目录打开功能
💻 CS
字号:
using System;
using Addot.Win32;

namespace Addot
{
	/// <summary>
	/// Extension of the .Net framework "Environment" class.
    /// Please, refer to the .Net framework for the complete documentation.
    /// </summary>
	public sealed class Environment
	{
        #region --- Registry keys & values ---
        private static readonly string VAL_CACHE = @"CachePath";
        private static readonly string KEY_COOKIES = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Cookies";
        private static readonly string KEY_HISTORY = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\History";
        private static readonly string KEY_INTERNET_CACHE = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Content";
        #endregion

        /// <summary>
        /// All special folders supported by the Pocket PC platform.
        /// Some values are localized, so they are retrieved from the registry.
        /// Values not listed here are not supported.
        /// </summary>
        public enum SpecialFolder
        {
            Cookies,        // \Windows\Cookies
            Favorites,      // \Windows\Favorites
            History,        // \Windows\History
            InternetCache,  // \Windows\Temporary Internet Cache
            MyComputer,     // \
            Personal,       // \My Documents
            ProgramFiles,   // \Program Files
            Programs,       // \Windows\Programs
            StartMenu,      // \Windows\Start Menu
            Startup,        // \Windows\Startup
            System,         // \Windows\System
            Templates       // \My Documents\Templates
        };
        
        public static OperatingSystem OSVersion
        {
            get
            {
                return System.Environment.OSVersion;
            }
        }

        public static int TickCount
        {
            get
            {
                return System.Environment.TickCount;
            }
        }

        public static Version Version
        {
            get
            {
                return System.Environment.Version;
            }
        }
        public static string GetFolderPath(Environment.SpecialFolder folder)
        {
            string Folder = "";
            System.Resources.ResourceManager rm = new System.Resources.ResourceManager("Addot.Addot", System.Reflection.Assembly.GetExecutingAssembly());

            switch(folder)
            {
                case SpecialFolder.Cookies:
                    Folder = GetRegString(KEY_COOKIES, VAL_CACHE);
                    // Remove the last "\"
                    Folder = Folder.TrimEnd('\\');
                    break;
                case SpecialFolder.Favorites:
                    Folder = rm.GetString("FavoritesFolder");
                    break;
                case SpecialFolder.History:
                    Folder = GetRegString(KEY_HISTORY, VAL_CACHE);
                    // Remove the last "\"
                    Folder = Folder.TrimEnd('\\');
                    break;
                case SpecialFolder.InternetCache:
                    Folder = GetRegString(KEY_INTERNET_CACHE, VAL_CACHE);
                    // Remove the last "\"
                    Folder = Folder.TrimEnd('\\');
                    break;
                case SpecialFolder.MyComputer:
                    Folder = @"\";
                    break;
                case SpecialFolder.Personal:
                    Folder = @"\My Documents";
                    break;
                case SpecialFolder.ProgramFiles:
                    Folder = @"\Program Files";
                    break;
                case SpecialFolder.Programs:
                    Folder = rm.GetString("ProgramsFolder");
                    break;
                case SpecialFolder.StartMenu:
                    Folder = rm.GetString("StartMenuFolder");
                    break;
                case SpecialFolder.Startup:
                    Folder = rm.GetString("StartupFolder");
                    break;
                case SpecialFolder.System:
                    Folder = @"\Windows\System";
                    break;
                case SpecialFolder.Templates:
                    Folder = rm.GetString("TemplatesFolder");
                    break;
                default: throw new NotSupportedException(string.Format(rm.GetString("GetFolderPathException"), folder));
            }

            return Folder;
        }

        private static string GetRegString(string key, string val)
        {
            RegistryKey regKey = Registry.LocalMachine.OpenSubKey(key);
            return (string)regKey.GetValue(val);
        }
    }
}

⌨️ 快捷键说明

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