Ejemplo n.º 1
0
 private void Cleanup(DownloadData toProcess) {
     Console.WriteLine("Cleaning Up");
     foreach (var tuple in toProcess.ToProcess)
     {
         var oldZsFile = tuple.InstallPath.GetBrotherFileWithName(tuple.InstallPath + ".zs-old").GetAbsolutePathFrom(_folder);
         if(oldZsFile.Exists)
             oldZsFile.FileInfo.Delete();
         var oldControlFile = tuple.InstallPath.GetBrotherFileWithName(tuple.InstallPath + ".zsync").GetAbsolutePathFrom(_folder);
         if (oldControlFile.Exists)
             oldControlFile.FileInfo.Delete();
     }
 }
Ejemplo n.º 2
0
        private async Task UpdateFiles(DownloadData toProcess, int retries = 0)
        {
            int tries = 0;
            var queue = new Queue<ControlFileItem>(toProcess.ToProcess);
            while (tries <= retries)
            {
                tries++;
                var reProcess = new Queue<ControlFileItem>();

                while (queue.Any())
                {
                    var item = queue.Dequeue();
                    var uri = item.ContentUrl.ToString().Substring(0, item.ContentUrl.ToString().Length - 10);
                    Console.WriteLine("Processing: " + uri);

                    var arguments = "-u \"" + uri + "\" -o \"" + Path.GetFileNameWithoutExtension(item.InstallPath.FileName) + "\" -i \"" + Path.GetFileNameWithoutExtension(item.InstallPath.FileName) + "\" \"" +
                                       item.InstallPath.ToString() + "\"";
                    Console.WriteLine(arguments);
                    var resp = new Process().RunInlineAndWait(new ProcessStartInfo("bin\\zsync.exe",
                        arguments) {
                            UseShellExecute = false,
                            WorkingDirectory = item.InstallPath.ParentDirectoryPath.ToString()
                        });
                    if (resp != 0)
                    {
                        reProcess.Enqueue(item);
                    }
                }

                queue = reProcess;
                if (!reProcess.Any())
                    break;
                await Task.Delay(1000);

            }

            if (queue.Any())
            {
                Console.WriteLine("Failed to get all files!");
                throw new Exception("Failed to get all files!");
            }
        }
Ejemplo n.º 3
0
        private async Task<DownloadData> DownloadControlFiles()
        {
            string result;
            using (var client = new HttpClient())
            {
                result = await client.GetStringAsync(_url);
            }
            var data = new DownloadData(JsonConvert.DeserializeObject<MainControlFile>(result));
            Console.WriteLine("Downloading Control File");
            foreach (var item in data.ControlFile.Content)
            {
                using (var client = new HttpClient()) {
                    var childFileWithName = item.InstallPath.GetAbsolutePathFrom(_folder);
                    var realFile = item.GetUnzippedFileName().GetAbsolutePathFrom(_folder);

                    if (realFile.Exists &&
                        childFileWithName.ToString().GetFileHash(HashType.MD5) == item.FileHash)
                        continue;

                    if (realFile.Exists)
                    {
                        new Process().RunInlineAndWait(new ProcessStartInfo("bin\\gzip.exe",
                            "\"" + realFile + "\"") {
                                UseShellExecute = false,
                                WorkingDirectory = _folder.ParentDirectoryPath.ToString()
                            });
                        realFile.FileInfo.Rename(realFile.FileNameWithoutExtension + ".jar");
                    }

                    data.ToProcess.Add(item);
                    
                    var str = await client.GetByteArrayAsync(item.ContentUrl);
                    Directory.CreateDirectory(childFileWithName.ParentDirectoryPath.ToString());
                    File.WriteAllBytes(childFileWithName.GetBrotherFileWithName(Path.GetFileNameWithoutExtension(childFileWithName.FileName)).ToString(), str);
                }
            }
            return data;
        }