示例#1
0
        private static NetworkFile PackFileData(string path)
        {
            NetworkFile file = new NetworkFile(Path.GetFileName(path), FileType.File);

            file.FillData(File.ReadAllBytes(path));
            return(file);
        }
示例#2
0
        private static NetworkFile PackFolder(string path)
        {
            try
            {
                NetworkFile folderData = new NetworkFile(Path.GetFileName(path), FileType.Directory);

                string[] files = Directory.GetFiles(path).Where(name => !name.EndsWith(".ini")).ToArray(); //exclude .ini files (these are invisible  system files)
                foreach (var file in files)
                {
                    folderData.FillData(PackFile(file));
                }

                string[] folders = Directory.GetDirectories(path);
                foreach (var folder in folders)
                {
                    folderData.FillData(PackFile(folder));
                }

                return(folderData);
            }
            catch (Exception e)
            {
                TgenLog.Log(e.ToString());
                throw e;
            }
        }
示例#3
0
 public void FillData(NetworkFile file)
 {
     if (fileType != FileType.Directory)
     {
         throw new Exception("This file is of type " + fileType);
     }
     files.Add(file);
 }
示例#4
0
        private static void UnpackFolder(string header, NetworkFile file)
        {
            DirectoryInfo directory = Directory.CreateDirectory(Path.Combine(header, file.name));

            foreach (var fileData in file.files)
            {
                UnpackFile(directory.FullName, fileData);
            }
        }
示例#5
0
 public static void UnpackFile(string header, NetworkFile file)
 {
     try
     {
         if (file.fileType == FileType.Directory) //Path is a folder
         {
             UnpackFolder(header, file);
             return;
         }
         else //Path is a file
         {
             UnpackFileData(header, file);
             return;
         }
     }
     catch (Exception e)
     {
         TgenLog.Log(e.ToString());
         throw e;
     }
 }
示例#6
0
        private static void UnpackFileData(string header, NetworkFile file)
        {
            FileStream stream = File.Create(Path.Combine(header, file.name));

            stream.Write(file.data, 0, file.data.Length);
        }