コード例 #1
0
ファイル: FilesBag.cs プロジェクト: Adel-dz/Hub
        public void Decompress(string filePath, string destFolder)
        {
            using (FileStream fs = File.OpenRead(filePath))
                using (var gzs = new GZipStream(fs, CompressionMode.Decompress))
                {
                    var reader = new RawDataReader(gzs, Encoding.UTF8);

                    foreach (byte b in Signature)
                    {
                        if (b != reader.ReadByte())
                        {
                            throw new CorruptedFileException(filePath);
                        }
                    }

                    int nbDir   = reader.ReadInt();
                    var folders = new List <string>(nbDir);

                    for (int i = 0; i < nbDir; ++i)
                    {
                        string dir = Path.Combine(destFolder, reader.ReadString());
                        folders.Add(dir);
                        Directory.CreateDirectory(dir);
                    }


                    int nbFile = reader.ReadInt();

                    for (int i = 0; i < nbFile; ++i)
                    {
                        string file   = reader.ReadString();
                        int    ndxDir = reader.ReadInt();

                        if (ndxDir == NDX_CUR_FOLDER)
                        {
                            file = Path.Combine(destFolder, file);
                        }
                        else
                        {
                            file = Path.Combine(folders[ndxDir], file);
                        }

                        long fileLen = reader.ReadLong();

                        CreateFile(gzs, file, fileLen);

                        FileDecompressed?.Invoke(file);
                    }
                }
        }
コード例 #2
0
ファイル: UpdateEngin.cs プロジェクト: Adel-dz/Hub
        public static IEnumerable <UpdateURI> ReadDataManifest(string filePath, uint startGeneration = 0)
        {
            using (FileStream fs = File.OpenRead(filePath))
            {
                var reader = new RawDataReader(fs, Encoding.UTF8);

                byte[] sign = Encoding.UTF8.GetBytes(DATA_MANIFEST_SIGNATURE);

                for (int i = 0; i < sign.Length; ++i)
                {
                    if (reader.ReadByte() != sign[i])
                    {
                        throw new CorruptedFileException(filePath);
                    }
                }

                int uriCount = reader.ReadInt();
                var lst      = new List <UpdateURI>();

                for (int i = 0; i < uriCount; ++i)
                {
                    uint   preGen  = reader.ReadUInt();
                    uint   postGen = reader.ReadUInt();
                    string uri     = reader.ReadString();

                    if (preGen >= startGeneration)
                    {
                        lst.Add(new UpdateURI(uri, preGen, postGen));
                    }
                }


                return(lst);
            }
        }
コード例 #3
0
ファイル: UpdateEngin.cs プロジェクト: Adel-dz/Hub
        public static Dictionary <AppArchitecture_t, string> ReadAppManifest(string filePath)
        {
            using (FileStream fs = File.OpenRead(filePath))
            {
                var    reader = new RawDataReader(fs, Encoding.UTF8);
                byte[] sign   = Encoding.UTF8.GetBytes(APP_MANIFEST_SIGNATURE);

                foreach (byte b in sign)
                {
                    if (b != reader.ReadByte())
                    {
                        throw new CorruptedFileException(filePath);
                    }
                }

                int nbKey = reader.ReadInt();
                var dict  = new Dictionary <AppArchitecture_t, string>(nbKey);

                for (int i = 0; i < nbKey; ++i)
                {
                    byte arch = reader.ReadByte();

                    if (!Enum.IsDefined(typeof(AppArchitecture_t), arch))
                    {
                        throw new CorruptedFileException(filePath);
                    }

                    string fileName = reader.ReadString();
                    dict[(AppArchitecture_t)arch] = fileName;
                }

                return(dict);
            }
        }
コード例 #4
0
ファイル: FilesBag.cs プロジェクト: Adel-dz/Hub
        public static IEnumerable <string> GetContent(string filePath)
        {
            using (FileStream fs = File.OpenRead(filePath))
                using (var gzs = new GZipStream(fs, CompressionMode.Decompress))
                {
                    var reader = new RawDataReader(gzs, Encoding.UTF8);

                    foreach (byte b in Signature)
                    {
                        if (b != reader.ReadByte())
                        {
                            throw new CorruptedFileException(filePath);
                        }
                    }

                    int nbDir   = reader.ReadInt();
                    var folders = new List <string>(nbDir);

                    for (int i = 0; i < nbDir; ++i)
                    {
                        string dir = reader.ReadString();
                        folders.Add(dir);
                    }


                    int nbFile = reader.ReadInt();
                    var files  = new List <string>(nbFile);

                    for (int i = 0; i < nbFile; ++i)
                    {
                        string file   = reader.ReadString();
                        int    ndxDir = reader.ReadInt();

                        if (ndxDir != NDX_CUR_FOLDER)
                        {
                            file = Path.Combine(folders[ndxDir], file);
                        }

                        files.Add(file);
                        long fileLen = reader.ReadLong();
                        reader.Skip((int)fileLen);
                    }

                    return(files);
                }
        }
コード例 #5
0
ファイル: SettingsManager.cs プロジェクト: Adel-dz/Hub
        void LoadUserSettings()
        {
            //if (!File.Exists(UserSettingsFilePath))
            //    return;

            using (FileStream fs = File.OpenRead(UserSettingsFilePath))
                using (var xs = new XorStream(fs))
                    using (var gzs = new GZipStream(xs, CompressionMode.Decompress))
                    {
                        var    reader = new RawDataReader(xs, Encoding.UTF8);
                        byte[] sign   = Encoding.UTF8.GetBytes(USER_SETTINGS_SIGNATURE);

                        for (int i = 0; i < sign.Length; ++i)
                        {
                            if (sign[i] != reader.ReadByte())
                            {
                                throw new CorruptedFileException(UserSettingsFilePath);
                            }
                        }

                        IsMaximized = reader.ReadBoolean();
                        int x = reader.ReadInt();
                        int y = reader.ReadInt();
                        int w = reader.ReadInt();
                        int h = reader.ReadInt();

                        FrameRectangle = new Rectangle(x, y, w, h);

                        UseCountryCode = reader.ReadBoolean();

                        int mruSize  = reader.ReadInt();
                        int mruCount = reader.ReadInt();
                        MRUSubHeading = new MRUList <SubHeading>(mruSize);

                        for (int i = 0; i < mruCount; ++i)
                        {
                            MRUSubHeading.Add(new SubHeading(reader.ReadULong()));
                        }

                        AutoDetectProxy = reader.ReadBoolean();
                        EnableProxy     = reader.ReadBoolean();
                        ProxyHost       = reader.ReadString();
                        ProxyPort       = reader.ReadUShort();
                    }
        }
コード例 #6
0
        Message ProcessLogMessage(Message msg, uint clID)
        {
            Dbg.Assert(msg.MessageCode == Message_t.Log);

            var ms     = new MemoryStream(msg.Data);
            var reader = new RawDataReader(ms, Encoding.UTF8);

            DateTime tm    = reader.ReadTime();
            bool     isErr = reader.ReadBoolean();
            string   txt   = reader.ReadString();

            if (isErr)
            {
                AppContext.LogManager.LogSysActivity($"Réception log d'erreur du client {ClientStrID(clID)}");
                AppContext.LogManager.LogClientError(clID, txt, tm);
            }
            else
            {
                AppContext.LogManager.LogSysActivity($"Réception d'un log d'activité du client {ClientStrID(clID)}");
                AppContext.LogManager.LogClientActivity(clID, txt, tm);
            }

            return(null);
        }