コード例 #1
0
        public Dictionary <string, object> GetEntity(string _lng)
        {
            string text = DirFile.ReadFile("~/data/languages/" + _lng + ".js");

            text = Strings.GetHtml(text, "//<!--语言包begin", "//-->语言包end");
            return((Dictionary <string, object>)JSON.Instance.ToObject(text));
        }
コード例 #2
0
        public static bool DownloadFile(HttpRequest _Request, HttpResponse _Response, string _fullPath, long _speed)
        {
            string fileName = DirFile.GetFileName(false, _fullPath);

            try
            {
                FileStream   fileStream   = new FileStream(_fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                BinaryReader binaryReader = new BinaryReader((Stream)fileStream);
                try
                {
                    _Response.AddHeader("Accept-Ranges", "bytes");
                    _Response.Buffer = false;
                    long   length = fileStream.Length;
                    long   offset = 0;
                    double num1   = 10240.0;
                    int    millisecondsTimeout = (int)Math.Floor(1000.0 * num1 / (double)_speed) + 1;
                    if (_Request.Headers["Range"] != null)
                    {
                        _Response.StatusCode = 206;
                        offset = Convert.ToInt64(_Request.Headers["Range"].Split(new char[2]
                        {
                            '=',
                            '-'
                        })[1]);
                    }
                    _Response.AddHeader("Content-Length", (length - offset).ToString());
                    _Response.AddHeader("Connection", "Keep-Alive");
                    _Response.ContentType = "application/octet-stream";
                    _Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8));
                    binaryReader.BaseStream.Seek(offset, SeekOrigin.Begin);
                    int num2 = (int)Math.Floor((double)(length - offset) / num1) + 1;
                    for (int index = 0; index < num2; ++index)
                    {
                        if (_Response.IsClientConnected)
                        {
                            _Response.BinaryWrite(binaryReader.ReadBytes(int.Parse(num1.ToString())));
                            Thread.Sleep(millisecondsTimeout);
                        }
                        else
                        {
                            index = num2;
                        }
                    }
                }
                catch
                {
                    return(false);
                }
                finally
                {
                    binaryReader.Close();
                    fileStream.Close();
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
コード例 #3
0
        public static void CopyDir(string OldDir, string NewDir)
        {
            DirectoryInfo oldDirectory = new DirectoryInfo(OldDir);
            DirectoryInfo newDirectory = new DirectoryInfo(NewDir);

            DirFile.CopyDir(oldDirectory, newDirectory);
        }
コード例 #4
0
 public static void SaveFile(string TxtStr, string tempDir, bool noBom)
 {
     try
     {
         DirFile.CreateDir(DirFile.GetFolderPath(true, tempDir));
         StreamWriter streamWriter = !noBom ? new StreamWriter(HttpContext.Current.Server.MapPath(tempDir), false, Encoding.UTF8) : new StreamWriter(HttpContext.Current.Server.MapPath(tempDir), false, (Encoding) new UTF8Encoding(false));
         streamWriter.Write(TxtStr);
         streamWriter.Close();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #5
0
        private static void CopyDir(DirectoryInfo OldDirectory, DirectoryInfo NewDirectory)
        {
            string path = NewDirectory.FullName + "\\" + OldDirectory.Name;

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            foreach (FileInfo file in OldDirectory.GetFiles())
            {
                File.Copy(file.FullName, path + "\\" + file.Name, true);
            }
            foreach (DirectoryInfo directory in OldDirectory.GetDirectories())
            {
                DirFile.CopyDir(directory, new DirectoryInfo(path));
            }
        }
コード例 #6
0
 public static string ReadFile(string file)
 {
     if (!DirFile.FileExists(file))
     {
         return("");
     }
     try
     {
         StreamReader streamReader = new StreamReader(HttpContext.Current.Server.MapPath(file), Encoding.UTF8);
         string       end          = streamReader.ReadToEnd();
         streamReader.Close();
         return(end);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #7
0
        private static void CopyDir(DirectoryInfo OldDirectory, DirectoryInfo NewDirectory)
        {
            string text = NewDirectory.FullName + "\\" + OldDirectory.Name;

            if (!Directory.Exists(text))
            {
                Directory.CreateDirectory(text);
            }
            FileInfo[] files = OldDirectory.GetFiles();
            FileInfo[] array = files;
            for (int i = 0; i < array.Length; i++)
            {
                FileInfo fileInfo = array[i];
                File.Copy(fileInfo.FullName, text + "\\" + fileInfo.Name, true);
            }
            DirectoryInfo[] directories = OldDirectory.GetDirectories();
            DirectoryInfo[] array2      = directories;
            for (int j = 0; j < array2.Length; j++)
            {
                DirectoryInfo oldDirectory = array2[j];
                DirectoryInfo newDirectory = new DirectoryInfo(text);
                DirFile.CopyDir(oldDirectory, newDirectory);
            }
        }
コード例 #8
0
 public static void SaveFile(string TxtStr, string tempDir)
 {
     DirFile.SaveFile(TxtStr, tempDir, true);
 }
コード例 #9
0
 public static void CopyAndDelDir(string OldDirectory, string NewDirectory)
 {
     DirFile.CopyDir(OldDirectory, NewDirectory);
     DirFile.DelDir(OldDirectory);
 }
コード例 #10
0
 public static void CopyDir(string OldDir, string NewDir)
 {
     DirFile.CopyDir(new DirectoryInfo(OldDir), new DirectoryInfo(NewDir));
 }
コード例 #11
0
 public static string GetFileName(string filePath)
 {
     return(DirFile.GetFileName(false, filePath));
 }
コード例 #12
0
 public static string GetFolderPath(string filePath)
 {
     return(DirFile.GetFolderPath(false, filePath));
 }