예제 #1
0
        public static string GetDataTime()
        {
            string str;
            IsolatedStorageFile isf = IsolatedStorageFile.GetStore(IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain | IsolatedStorageScope.User, (Type)null, (Type)null);

            if (isf.GetDirectoryNames(UIConstants.IsolatedStorageDirectoryName).Length == 0)
            {
                return(string.Empty);
            }
            if (isf.GetFileNames(UIConstants.IsolatedStorage).Length == 0)
            {
                return(string.Empty);
            }
            using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(UIConstants.IsolatedStorage, FileMode.OpenOrCreate, isf))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    str = reader.ReadLine();
                }
            }
            if (!string.IsNullOrEmpty(str))
            {
                try
                {
                    str = EncodeHelper.DesDecrypt(str, UIConstants.IsolatedStorageEncryptKey);
                }
                catch
                {
                }
            }
            return(str);
        }
        /// <summary>
        /// 从"独立存贮空间"取程序第一次运行的时间并解密
        /// </summary>
        /// <returns></returns>
        public static string GetDataTime()
        {
            string fromDataTime;

            //按用户、域、程序集获取独立存储区
            IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User
                                                                        | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null);

            string[] myusername = isoStore.GetDirectoryNames(UIConstants.IsolatedStorageDirectoryName);
            if (myusername.Length == 0) //没有文件夹
            {
                return(string.Empty);   //域中没有他的目录
            }

            myusername = isoStore.GetFileNames(UIConstants.IsolatedStorage);
            if (myusername.Length == 0) //没有文件
            {
                return(string.Empty);   //域中没有他的用户名
            }
            else
            {
                using (IsolatedStorageFileStream isoStream1 = new IsolatedStorageFileStream(UIConstants.IsolatedStorage, FileMode.OpenOrCreate, isoStore))
                {
                    using (StreamReader reader = new StreamReader(isoStream1))
                    {
                        fromDataTime = reader.ReadLine();
                    }
                }
                if (!string.IsNullOrEmpty(fromDataTime)) //解密
                {
                    try
                    {
                        fromDataTime = EncodeHelper.DesDecrypt(fromDataTime, UIConstants.IsolatedStorageEncryptKey);
                    }
                    catch
                    {
                    }
                }
                return(fromDataTime);
            }
        }