Example #1
0
    public static void UnZipScene()
    {
        string text  = SceneZip.unZipPath + "/Scene.bytes";
        int    count = SceneZip.sceneZipReader.ReadInt32();

        byte[]       array        = SceneZip.sceneZipReader.ReadBytes(count);
        MemoryStream memoryStream = new MemoryStream();

        memoryStream.Write(array, 0, array.Length);
        memoryStream.Position = 0L;
        MemoryStream memoryStream2 = new MemoryStream();

        StreamZip.Unzip(memoryStream, memoryStream2);
        string dirName = text.Substring(0, text.LastIndexOf("/"));

        if (!QFileUtils.ExistsDir(dirName))
        {
            QFileUtils.CreateDir(dirName);
        }
        if (!QFileUtils.Exists(text))
        {
            QFileUtils.CreateFile(text);
        }
        QFileUtils.WriteBytes(text, memoryStream2.ToArray());
    }
Example #2
0
    public static void MultiUnzip(byte[] zipbytes, string dir)
    {
        BinaryReader binaryReader = new BinaryReader(new MemoryStream(zipbytes));

        while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length)
        {
            string       str          = binaryReader.ReadString();
            int          count        = binaryReader.ReadInt32();
            byte[]       array        = binaryReader.ReadBytes(count);
            MemoryStream memoryStream = new MemoryStream();
            memoryStream.Write(array, 0, array.Length);
            memoryStream.Position = 0L;
            MemoryStream memoryStream2 = new MemoryStream();
            StreamZip.Unzip(memoryStream, memoryStream2);
            if (!QFileUtils.ExistsDir(dir))
            {
                QFileUtils.CreateDir(dir);
            }
            string fileName = dir + "//" + str;
            if (!QFileUtils.Exists(fileName))
            {
                QFileUtils.CreateFile(fileName);
            }
            QFileUtils.WriteBytes(fileName, memoryStream2.ToArray());
        }
    }
Example #3
0
 public static bool DeleteFile(string fileName)
 {
     if (QFileUtils.Exists(fileName))
     {
         File.Delete(fileName);
         return(true);
     }
     return(false);
 }
Example #4
0
    public static bool FindFile(string dir, string fileName)
    {
        if (dir == null || dir.Trim() == string.Empty || fileName == null || fileName.Trim() == string.Empty || !Directory.Exists(dir))
        {
            return(false);
        }
        DirectoryInfo dir2 = new DirectoryInfo(dir);

        return(QFileUtils.FindFile(dir2, fileName));
    }
Example #5
0
    public static string ReadLine(string fileName)
    {
        if (!QFileUtils.Exists(fileName))
        {
            return(null);
        }
        string result;

        using (FileStream fileStream = new FileStream(fileName, FileMode.Open))
        {
            result = new StreamReader(fileStream).ReadLine();
        }
        return(result);
    }
Example #6
0
 public static bool FindFile(DirectoryInfo dir, string fileName)
 {
     DirectoryInfo[] directories = dir.GetDirectories();
     for (int i = 0; i < directories.Length; i++)
     {
         DirectoryInfo directoryInfo = directories[i];
         if (File.Exists(directoryInfo.FullName + "\\" + fileName))
         {
             return(true);
         }
         QFileUtils.FindFile(directoryInfo, fileName);
     }
     return(false);
 }
Example #7
0
    public static void ZipScene()
    {
        string fileName = SceneZip.zipPath + "/Scene.bytes";

        byte[]       array        = QFileUtils.ReadBinary(fileName);
        MemoryStream memoryStream = new MemoryStream();

        memoryStream.Write(array, 0, array.Length);
        memoryStream.Position = 0L;
        MemoryStream memoryStream2 = new MemoryStream();

        StreamZip.Zip(memoryStream, memoryStream2);
        byte[] array2 = memoryStream2.ToArray();
        SceneZip.sceneZipWriter.Write(array2.Length);
        SceneZip.sceneZipWriter.Write(array2);
    }
Example #8
0
 public static void UnZip(string zipfile, int sceneID)
 {
     SceneZip.unZipPath = Application.persistentDataPath + "/Resources/Scenes/" + sceneID;
     LogSystem.Log(new object[]
     {
         "unzip scene file into ->" + SceneZip.unZipPath
     });
     byte[] buffer = QFileUtils.ReadBinary(zipfile);
     SceneZip.sceneZipReader = new BinaryReader(new MemoryStream(buffer));
     SceneZip.UnZipScene();
     SceneZip.UnZipLightmap();
     while (SceneZip.sceneZipReader.BaseStream.Position < SceneZip.sceneZipReader.BaseStream.Length)
     {
         SceneZip.UnZipRegion();
     }
 }
Example #9
0
 public static byte[] ReadBinary(string fileName)
 {
     if (!QFileUtils.Exists(fileName))
     {
         return(null);
     }
     byte[] result;
     using (FileStream fileStream = new FileStream(fileName, FileMode.Open))
     {
         byte[] array = new byte[fileStream.Length];
         fileStream.Read(array, 0, array.Length);
         fileStream.Seek(0L, SeekOrigin.Begin);
         result = array;
     }
     return(result);
 }
Example #10
0
    public static bool CopyDir(string fromDir, string toDir)
    {
        if (fromDir == null || toDir == null)
        {
            throw new NullReferenceException("参数为空");
        }
        if (fromDir == toDir)
        {
            throw new Exception("两个目录都是" + fromDir);
        }
        if (!Directory.Exists(fromDir))
        {
            throw new IOException("目录fromDir=" + fromDir + "不存在");
        }
        DirectoryInfo directoryInfo = new DirectoryInfo(fromDir);

        return(QFileUtils.CopyDir(directoryInfo, toDir, directoryInfo.FullName));
    }
Example #11
0
 public static void Zip(string scenePath, string zipfilePath)
 {
     SceneZip.zipPath        = scenePath;
     SceneZip.sceneZipStream = new MemoryStream();
     SceneZip.sceneZipWriter = new BinaryWriter(SceneZip.sceneZipStream);
     SceneZip.ZipScene();
     SceneZip.ZipLightmap();
     for (int i = SceneZip.startRegX; i <= SceneZip.endRegX; i++)
     {
         for (int j = SceneZip.startRegY; j <= SceneZip.endRegY; j++)
         {
             SceneZip.ZipRegion(i, j);
         }
     }
     if (!QFileUtils.Exists(zipfilePath))
     {
         QFileUtils.CreateFile(zipfilePath);
     }
     QFileUtils.WriteBytes(zipfilePath, SceneZip.sceneZipStream.ToArray());
 }
Example #12
0
 public static void DeleteDir(DirectoryInfo dir)
 {
     if (dir == null)
     {
         throw new NullReferenceException("目录不存在");
     }
     DirectoryInfo[] directories = dir.GetDirectories();
     for (int i = 0; i < directories.Length; i++)
     {
         DirectoryInfo dir2 = directories[i];
         QFileUtils.DeleteDir(dir2);
     }
     FileInfo[] files = dir.GetFiles();
     for (int j = 0; j < files.Length; j++)
     {
         FileInfo fileInfo = files[j];
         QFileUtils.DeleteFile(fileInfo.FullName);
     }
     dir.Delete();
 }
Example #13
0
    private static bool CopyDir(DirectoryInfo fromDir, string toDir, string rootDir)
    {
        string text = string.Empty;

        FileInfo[] files = fromDir.GetFiles();
        for (int i = 0; i < files.Length; i++)
        {
            FileInfo fileInfo = files[i];
            text = toDir + fileInfo.FullName.Substring(rootDir.Length);
            string dirName = text.Substring(0, text.LastIndexOf("\\"));
            QFileUtils.CreateDir(dirName);
            File.Copy(fileInfo.FullName, text, true);
        }
        DirectoryInfo[] directories = fromDir.GetDirectories();
        for (int j = 0; j < directories.Length; j++)
        {
            DirectoryInfo fromDir2 = directories[j];
            QFileUtils.CopyDir(fromDir2, toDir, rootDir);
        }
        return(true);
    }
Example #14
0
    public static bool Write(string fileName, string content)
    {
        if (!QFileUtils.Exists(fileName) || content == null)
        {
            return(false);
        }
        bool result;

        using (FileStream fileStream = new FileStream(fileName, FileMode.OpenOrCreate))
        {
            FileStream obj = fileStream;
            lock (obj)
            {
                if (!fileStream.CanWrite)
                {
                    throw new SecurityException("文件fileName=" + fileName + "是只读文件不能写入!");
                }
                byte[] bytes = Encoding.Default.GetBytes(content);
                fileStream.Write(bytes, 0, bytes.Length);
                result = true;
            }
        }
        return(result);
    }
Example #15
0
    public static bool DeleteDir(string dir, bool onlyDir)
    {
        if (dir == null || dir.Trim() == string.Empty)
        {
            throw new NullReferenceException("目录dir=" + dir + "不存在");
        }
        if (!Directory.Exists(dir))
        {
            return(false);
        }
        DirectoryInfo directoryInfo = new DirectoryInfo(dir);

        if (directoryInfo.GetFiles().Length == 0 && directoryInfo.GetDirectories().Length == 0)
        {
            Directory.Delete(dir);
            return(true);
        }
        if (!onlyDir)
        {
            return(false);
        }
        QFileUtils.DeleteDir(directoryInfo);
        return(true);
    }
Example #16
0
 public static bool CopyDir(DirectoryInfo fromDir, string toDir)
 {
     return(QFileUtils.CopyDir(fromDir, toDir, fromDir.FullName));
 }