Beispiel #1
0
        public IArchiveContent GetArchiveContent(string filePath)
        {
            var archData = new ArchiveContent();

            using (FileStream fs = File.OpenRead(filePath))
            {
                var    reader = new RawDataReader(fs, Encoding.UTF8);
                byte[] sign   = Signature;

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

                archData.CreationTime = reader.ReadTime();
                int len = reader.ReadInt();
                archData.ArchiveHeader = reader.ReadBytes(len);
                archData.Files         = FilesBag.GetContent(fs);

                return(archData);
            }
        }
Beispiel #2
0
        void LoadDataAsync()
        {
            Func <ListViewItem[]> load = () =>
            {
                var items = new List <ListViewItem>();

                items.Add(CreateLVI("ID", m_update.ID.ToString("X")));
                items.Add(CreateLVI("Crée le", m_update.CreationTime.ToString()));
                items.Add(CreateLVI("Version", m_update.Version.ToString()));
                items.Add(CreateLVI("Architecture", AppArchitectures.GetArchitectureName(m_update.AppArchitecture)));
                items.Add(CreateLVI(""));
                items.Add(CreateLVI("Fichiers:"));

                string fileName = m_update.ID.ToString("X");
                string filePath = Path.Combine(AppPaths.AppUpdateFolder, fileName);

                foreach (string item in FilesBag.GetContent(filePath))
                {
                    items.Add(CreateLVI(item));
                }

                return(items.ToArray());
            };

            var waitDlg = new Waits.WaitClue(this);

            Action <Task <ListViewItem[]> > onSuccess = t =>
            {
                m_lvData.Items.AddRange(t.Result);
                m_lvData.AdjustColumnsSize();
                waitDlg.LeaveWaitMode();
            };

            Action <Task> onErr = t =>
            {
                waitDlg.LeaveWaitMode();
                MessageBox.Show(t.Exception.InnerException.Message, null,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            };

            var task = new Task <ListViewItem[]>(load, TaskCreationOptions.LongRunning);

            task.OnSuccess(onSuccess);
            task.OnError(onErr);
            task.Start();
            waitDlg.EnterWaitMode();
        }