Example #1
0
        /// <summary>
        /// delete files from previous update
        /// Unzip and copy files
        /// </summary>
        private static void UnzipFiles()
        {
            var destination = FilePath.RootDir;
            var zipPath     = FilePath.TempZipFile;
            var archive     = ZipFile.Open(zipPath, ZipArchiveMode.Read);

            //check the list of files if exists
            if (File.Exists(FilePath.UpdatedFiles))
            {
                //then delete all those files
                var updatedFilesJson = UpdatedFilesJson.Load();
                updatedFilesJson.UpdatedFiles.ForEach(File.Delete);
            }

            var updatedFiles = new List <string>();

            foreach (var file in archive.Entries)
            {
                var completeFileName = Path.Combine(destination, file.FullName);
                if (file.Name == "")
                {// Assuming Empty for Directory
                    Directory.CreateDirectory(Path.GetDirectoryName(completeFileName));
                    continue;
                }

                System.IO.Directory.CreateDirectory(Path.GetDirectoryName(completeFileName));

                updatedFiles.Add(file.FullName);
                file.ExtractToFile(completeFileName, true);
            }
            //save the list of files extracted
            new UpdatedFilesJson(updatedFiles).SaveJson();
        }
        public static UpdatedFilesJson Load()
        {
            var updatedFilesJson = new UpdatedFilesJson();

            updatedFilesJson.LoadJson();
            return(updatedFilesJson);
        }