Exemplo n.º 1
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());
        }
    }
Exemplo n.º 2
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());
    }
Exemplo n.º 3
0
 public static bool DeleteFile(string fileName)
 {
     if (QFileUtils.Exists(fileName))
     {
         File.Delete(fileName);
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
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);
    }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
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());
 }
Exemplo n.º 7
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);
    }