Exemple #1
0
        public void Restore(string filePath, string destFolder)
        {
            Initializing?.Invoke();

            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);
                    }
                }

                reader.ReadTime();           //ignore creation time
                int headerLen = reader.ReadInt();
                reader.ReadBytes(headerLen); //ignore header

                Restoring?.Invoke();
                var bag = new FilesBag();

                Clean(destFolder);

                bag.Decompress(fs, destFolder);

                Done?.Invoke();
            }
        }
Exemple #2
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);
            }
        }
Exemple #3
0
        public void Backup(string filePath, string srcFolder, byte[] archHeader)
        {
            Initializing?.Invoke();

            FilesBag bag = CreateBag(srcFolder);

            FileStream fsDest = null;

            try
            {
                fsDest = File.Create(filePath);
                var writer = new RawDataWriter(fsDest, Encoding.UTF8);
                writer.Write(Signature);
                writer.Write(DateTime.Now);
                writer.Write(archHeader.Length);
                writer.Write(archHeader);

                Compressing?.Invoke();
                bag.Compress(fsDest);

                Done?.Invoke();
            }
            catch
            {
                if (fsDest != null)
                {
                    fsDest.Dispose();
                    File.Delete(filePath);
                }

                throw;
            }
        }
Exemple #4
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();
        }
Exemple #5
0
        static void AddFiles(FilesBag bag, string subFolder, string rootFolder)
        {
            string[] files  = Directory.GetFiles(subFolder);
            string   relDir = subFolder.Remove(0, rootFolder.Length + 1);

            foreach (string file in files)
            {
                bag.Add(file, relDir);
            }

            string[] folders = Directory.GetDirectories(subFolder);

            foreach (string folder in folders)
            {
                AddFiles(bag, folder, rootFolder);
            }
        }
Exemple #6
0
        FilesBag CreateBag(string srcFolder)
        {
            Initializing?.Invoke();

            var bag = new FilesBag();

            string[] files = Directory.GetFiles(srcFolder);

            foreach (string file in files)
            {
                bag.Add(file);
            }

            string[] folders = Directory.GetDirectories(srcFolder);

            foreach (string folder in folders)
            {
                AddFiles(bag, folder, srcFolder);
            }

            return(bag);
        }
Exemple #7
0
        private void AddPackage_Click(object sender, EventArgs e)
        {
            using (var dlg = new AppUpdateDialog())
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    IDatumProvider dp      = null;
                    var            waitDlg = new Jobs.ProcessingDialog();

                    Action buildUpdate = () =>
                    {
                        var bag = new FilesBag();

                        foreach (string file in dlg.Files)
                        {
                            waitDlg.Message = $"Préparation de {file}";
                            string relDir = Path.GetDirectoryName(file.Remove(0, dlg.RootFolder.Length + 1));

                            if (relDir.Length > 0)
                            {
                                bag.Add(file, relDir);
                            }
                            else
                            {
                                bag.Add(file);
                            }
                        }

                        waitDlg.Message = "Compression en cours...";
                        dp = AppContext.TableManager.AppUpdates.DataProvider;
                        dp.Connect();

                        var update = new AppUpdate(AppContext.TableManager.AppUpdates.CreateUniqID(), dlg.Version, dlg.AppArchitecture);
                        bag.Compress(Path.Combine(AppPaths.AppUpdateFolder, update.ID.ToString("X")));

                        NormalizeAppUpdates(update);
                        dp.Insert(update);
                    };


                    Action <Task> onErr = t =>
                    {
                        TextLogger.Error(t.Exception.InnerException.Message);
                        this.ShowError(t.Exception.InnerException.Message);

                        dp?.Dispose();
                        waitDlg.Dispose();
                    };

                    Action onSuccess = () =>
                    {
                        dp?.Dispose();
                        waitDlg.Dispose();
                    };


                    var task = new Task(buildUpdate, TaskCreationOptions.LongRunning);
                    task.OnSuccess(onSuccess);
                    task.OnError(onErr);
                    task.Start();

                    waitDlg.ShowDialog(this);
                }
        }