Exemplo n.º 1
0
        public async static Task Update(Package package, Validator val, PackageOverview overview)
        {
            //Create tmp dir so files are gone after execution.
            using (TmpDir dir = new TmpDir("."))
                using (WebClient client = new WebClient())
                {
                    //Check if it exists
                    if (PackageUtil.DoesPackageExist(package))
                    {
                        string filename = Path.GetFileName(package.downloadLocation);
                        Console.WriteLine("Getting newest version of package " + package.name);
                        //Setup loading bar
                        client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(LoadingBar.DownloadProgressCallback);
                        //Get latest version
                        await client.DownloadFileTaskAsync(package.downloadLink, dir.dirName + filename);

                        Console.Write("\n\r");
                        //Compare. The && ! will make it so that it will always go to 2nd case if val.forceUpdate is ture.
                        if (FileCompare.CompareFiles(dir.dirName + filename, "../sm_plugins/" + package.downloadLocation) && !val.forceUpdate)
                        {
                            Console.WriteLine(package.name + " is up to date.");
                        }
                        else
                        {
                            File.Move(dir.dirName + filename, "../sm_plugins/" + package.downloadLocation, true);
                            Console.WriteLine(package.name + " was updated.");
                        }
                    }
                    else
                    {
                        Console.WriteLine(("WARNING: Package " + package.name + " is not installed. Skipping.").Pastel("ffff00"));
                    }
                }
        }
Exemplo n.º 2
0
 public void TestExecute_places_output_into_OutputDir()
 {
     using (var tmpDir = new TmpDir()) {
         var fooTask = MockBuildTasks.GenerateFile("createFoo", "foo", "42").Object;
         Builder.Execute(tmpDir.Path, tmpDir.CreateDir("out"), tmpDir.CreateDir(".bud"), fooTask);
         FileAssert.AreEqual(tmpDir.CreateFile("42"), tmpDir.CreatePath("out", "foo"));
     }
 }
Exemplo n.º 3
0
 public void SetUp()
 {
     dir         = new TmpDir();
     sourceDir1  = dir.CreateDir("sourceDir1");
     sourceDir2  = dir.CreateDir("sourceDir2");
     sourceFile1 = dir.CreateFile("foo", "sourceDir1", "file1");
     targetDir   = dir.CreatePath("target");
     storage     = new BuildStorage(targetDir, new Dictionary <Uri, byte[]>());
 }
Exemplo n.º 4
0
 public void TestExecute_name_clash_throws()
 {
     using (var tmpDir = new TmpDir()) {
         var fooTask1  = MockBuildTasks.NoOp("foo").WithSignature("1").Object;
         var fooTask2  = MockBuildTasks.NoOp("foo").WithSignature("2").Object;
         var exception = Assert.Throws <Exception>(() => Builder.Execute(tmpDir.Path, tmpDir.CreateDir("out"),
                                                                         tmpDir.CreateDir(".bud"), fooTask1, fooTask2));
         Assert.AreEqual("Detected multiple tasks with the name 'foo'. Tasks must have unique names.",
                         exception.Message);
     }
 }
Exemplo n.º 5
0
        public void TestExecute_executes_the_same_tasks_once()
        {
            using (var tmpDir = new TmpDir()) {
                var fooTaskMock = MockBuildTasks.GenerateFile("createFoo", "foo", "42");

                Builder.Execute(tmpDir.Path, tmpDir.CreateDir("out"), tmpDir.CreateDir(".bud"), fooTaskMock.Object);
                Builder.Execute(tmpDir.Path, tmpDir.CreateDir("out"), tmpDir.CreateDir(".bud"), fooTaskMock.Object);

                VerifyExecutedOnce(fooTaskMock);
            }
        }
Exemplo n.º 6
0
        public void TestExecute_executes_dependencies()
        {
            using (var tmpDir = new TmpDir()) {
                var fooTask = MockBuildTasks.GenerateFile("createFoo", "foo", "42").Object;
                var barTask = MockBuildTasks.GenerateFile("createBar", "bar", "9001", fooTask).Object;

                Builder.Execute(tmpDir.Path, tmpDir.CreateDir("out"), tmpDir.CreateDir(".bud"), barTask);

                FileAssert.AreEqual(tmpDir.CreateFile("42"), tmpDir.CreatePath("out", "foo"));
                FileAssert.AreEqual(tmpDir.CreateFile("9001"), tmpDir.CreatePath("out", "bar"));
            }
        }
Exemplo n.º 7
0
        public void TestExecute_same_dependencies_are_executed_once()
        {
            using (var tmpDir = new TmpDir()) {
                var fooTaskMock = MockBuildTasks.GenerateFile("createFoo", "foo", "42");
                var barTaskMock = MockBuildTasks.GenerateFile("createBar", "bar", "9001",
                                                              fooTaskMock.Object, fooTaskMock.Object);

                Builder.Execute(tmpDir.Path, tmpDir.CreateDir("out"), tmpDir.CreateDir(".bud"), barTaskMock.Object);

                VerifyExecutedOnce(fooTaskMock);
            }
        }
Exemplo n.º 8
0
 public void TestExecute_detects_cycles()
 {
     using (var tmpDir = new TmpDir()) {
         var fooTask1 = MockBuildTasks.NoOp("foo1").WithSignature("1");
         var fooTask2 = MockBuildTasks.NoOp("foo2").WithSignature("2").WithDependencies(new [] { fooTask1.Object });
         fooTask1.WithDependencies(new[] { fooTask2.Object });
         var exception = Assert.Throws <Exception>(() => Builder.Execute(tmpDir.Path, tmpDir.CreateDir("out"),
                                                                         tmpDir.CreateDir(".bud"), fooTask1.Object,
                                                                         fooTask2.Object));
         Assert.AreEqual("Detected a dependency cycle: 'foo1 depends on foo2 depends on foo1'.",
                         exception.Message);
     }
 }
Exemplo n.º 9
0
        public void TestExecute_dependency_results_reference_build_tasks()
        {
            using (var tmpDir = new TmpDir()) {
                var fooTask = MockBuildTasks.NoOp("foo").Object;
                var barTask = MockBuildTasks.NoOp("bar", fooTask)
                              .WithExecuteAction((sourceDir, outputDir, dependencyResults) => {
                    Assert.AreEqual(new [] { fooTask },
                                    dependencyResults.Select(result => result.BuildTask));
                }).Object;

                Builder.Execute(tmpDir.Path, tmpDir.CreateDir("out"), tmpDir.CreateDir(".bud"), barTask);
            }
        }
Exemplo n.º 10
0
        public void TestExecute_rebuilds_task_when_signature_of_dependency_changes()
        {
            using (var tmpDir = new TmpDir()) {
                var fooTaskMock = MockBuildTasks.GenerateFile("createFoo", "foo", "42");
                var barTaskMock = MockBuildTasks.GenerateFile("createBar", "bar", "9001", fooTaskMock.Object);
                Builder.Execute(tmpDir.Path, tmpDir.CreateDir("out"), tmpDir.CreateDir(".bud"), barTaskMock.Object);

                var changedFooTaskMock = MockBuildTasks.GenerateFile("createFoo", "foo", "changed");
                var barTaskMock2       = MockBuildTasks.GenerateFile("createBar", "bar", "9001", changedFooTaskMock.Object);
                Builder.Execute(tmpDir.Path, tmpDir.CreateDir("out"), tmpDir.CreateDir(".bud"), barTaskMock2.Object);

                VerifyExecutedOnce(barTaskMock2);
            }
        }
Exemplo n.º 11
0
        public async Task UpdatesLocalDB()
        {
            var svrDb = SampleDB1.CreateInTemp();
            var locDb = svrDb.MakeTempCopy(".LiteDB");
            var servr = FcServer.StartWith(svrDb, 5, out VersionKeeperSettings cfg);
            var chekr = await FcClient.StartWith(locDb, cfg);

            svrDb.AddRecords(1);
            await Task.Delay(1000 * 2);

            locDb.MustMatchMaxIdOf(svrDb);

            await TmpDir.Cleanup(servr, svrDb, chekr, locDb);
        }
Exemplo n.º 12
0
        public async Task UpdatesColdTarget()
        {
            var svrFile = CreateFile.WithRandomText();
            var locFile = svrFile.MakeTempCopy(".locFile1");
            var server  = FcServer.StartWith(svrFile, 1, out VersionKeeperSettings cfg);
            var client  = await FcClient.StartWith(locFile, cfg);

            FileChange.Trigger(svrFile);
            await Task.Delay(1000 * 2);

            locFile.MustMatchHashOf(svrFile);

            await TmpDir.Cleanup(server, svrFile, client, locFile);
        }
Exemplo n.º 13
0
        public void TestExecute_passes_the_source_dir_to_tasks()
        {
            using (var tmpDir = new TmpDir()) {
                var sourceDir  = tmpDir.CreateDir("src");
                var outputDir  = tmpDir.CreatePath("out");
                var metaDir    = tmpDir.CreatePath(".bud");
                var sourceFile = tmpDir.CreateFile("42", "src", "foo");
                var task1Mock  = MockBuildTasks.CopySourceFile("task1", "foo", "bar");

                Builder.Execute(sourceDir, outputDir, metaDir, task1Mock.Object);

                FileAssert.AreEqual(sourceFile, Path.Combine(outputDir, "bar"));
            }
        }
Exemplo n.º 14
0
        public void TestExecute_throws_when_two_tasks_produce_file_with_same_name()
        {
            using (var tmpDir = new TmpDir()) {
                var foo1TaskMock = MockBuildTasks.GenerateFile("createFoo1", "foo", "1");
                var foo2TaskMock = MockBuildTasks.GenerateFile("createFoo2", "foo", "2", foo1TaskMock.Object);

                var exception = Assert.Throws <Exception>(() => {
                    Builder.Execute(tmpDir.Path, tmpDir.CreateDir("out"), tmpDir.CreateDir(".bud"), foo2TaskMock.Object);
                });

                Assert.That(exception.Message,
                            Contains.Substring("Tasks 'createFoo1' and 'createFoo2' are clashing. " +
                                               "They produced the same file 'foo'."));
            }
        }
Exemplo n.º 15
0
 public void Signature_of_file()
 {
     using (var dir = new TmpDir()) {
         var fooFile = dir.CreateFile("9001", "foo.txt");
         var barFile = dir.CreateFile("42", "bar.txt");
         AreEqual(new Sha256Signer().Digest(fooFile)
                  .Digest(Encoding.UTF8.GetBytes("9001"))
                  .Digest(barFile)
                  .Digest(Encoding.UTF8.GetBytes("42"))
                  .Finish()
                  .Signature
                  .ToArray(),
                  new Sha256Signer().DigestSources(new[] { fooFile, barFile }).Finish().Signature.ToArray());
     }
 }
Exemplo n.º 16
0
        public void TestExecute_throws_when_two_tasks_have_the_same_signature()
        {
            using (var tmpDir = new TmpDir()) {
                var task1Mock = MockBuildTasks.NoOp("task1").WithSignature("foo");
                var task2Mock = MockBuildTasks.NoOp("task2", task1Mock.Object).WithSignature("foo");

                var exception = Assert.Throws <BuildTaskClashException>(() => {
                    Builder.Execute(tmpDir.Path, tmpDir.CreateDir("out"), tmpDir.CreateDir(".bud"), task2Mock.Object);
                });

                Assert.That(exception.Message,
                            Contains.Substring("Tasks 'task1' and 'task2' are clashing. " +
                                               "They have the same signature 'foo'."));
            }
        }
Exemplo n.º 17
0
        private void CreateInputArchive(string archiveName)
        {
            //Create Archive
            using (_outputDir = new TmpDir("output_tmp"))
            {
                CreateImageInfosAndResize();

                //Add info file
                using (var writer = new StreamWriter(_outputDir.GetCreateStream("info.json")))
                {
                    writer.Write(JsonConvert.SerializeObject(_infoFile));
                }

                _outputDir.CreateArchive(archiveName);
            }
        }
Exemplo n.º 18
0
        public async Task UpdatesSelf()
        {
            var svrExe = FcClient.GetDebugExe().MakeTempCopy(".dbgSvrExe");
            var server = FcServer.StartWith(svrExe, 4,
                                            out VersionKeeperSettings cfg,
                                            CheckerRelease.FileKey);
            var client = await FcClient.StartWith("", cfg, true);

            var updatr = client.MainModule.FileName;

            FileChange.Trigger(svrExe);
            await Task.Delay(1000 * 4);

            updatr.MustMatchHashOf(svrExe);

            var newProc = FcClient.FindRunningProcess();
            await TmpDir.Cleanup(server, svrExe, newProc, updatr);
        }
Exemplo n.º 19
0
        public async Task UpdatesRunningExe()
        {
            var svrExe = CreateFile.TempCopy("windirstat.exe");
            var locExe = svrExe.MakeTempCopy("locWds.exe");
            var server = FcServer.StartWith(svrExe, 3, out VersionKeeperSettings cfg);
            var client = await FcClient.StartWith(locExe, cfg);

            var locPrc = Process.Start(locExe);

            FileChange.Trigger(svrExe);
            await Task.Delay(1000 * 2);

            locExe.MustMatchHashOf(svrExe);

            locPrc.Kill(); locPrc.Dispose();

            await TmpDir.Cleanup(server, svrExe, client, locExe);
        }
Exemplo n.º 20
0
        public void TestExecute_executes_tasks_in_parallel()
        {
            using (var tmpDir = new TmpDir()) {
                var countdownLatch = new CountdownEvent(2);

                var buildTask1Mock = MockBuildTasks.Action("latch1", () => {
                    countdownLatch.Signal();
                    countdownLatch.Wait();
                });

                var buildTask2Mock = MockBuildTasks.Action("latch2", () => {
                    countdownLatch.Signal();
                    countdownLatch.Wait();
                });

                Builder.Execute(tmpDir.Path, tmpDir.CreateDir("out"), tmpDir.CreateDir(".bud"), buildTask1Mock.Object,
                                buildTask2Mock.Object);
            }
        }
Exemplo n.º 21
0
        public async Task UpdatesHotSource()
        {
            var svrFile = CreateFile.WithRandomText();
            var locFile = svrFile.MakeTempCopy(".locFile2");
            var server  = FcServer.StartWith(svrFile, 2, out VersionKeeperSettings cfg);

            FileChange.Trigger(svrFile);
            var fileRef = new FileStream(svrFile, FileMode.Open, FileAccess.ReadWrite);

            var client = await FcClient.StartWith(locFile, cfg);

            await Task.Delay(1000 * 2);

            fileRef.Dispose();

            locFile.MustMatchHashOf(svrFile);

            await TmpDir.Cleanup(server, svrFile, client, locFile);
        }
Exemplo n.º 22
0
        public void TestExecute_does_not_have_race_conditions()
        {
            for (int i = 0; i < 5; i++)
            {
                using (var tmpDir = new TmpDir()) {
                    var sourceDir = tmpDir.CreateDir("src");
                    var outputDir = tmpDir.CreatePath("out");
                    var metaDir   = tmpDir.CreatePath(".bud");

                    var generatedFiles = Enumerable.Range(0, 10).Select(idx => $"file_{idx}").ToList();
                    var fileGenerators = generatedFiles.Select(file => MockBuildTasks.GenerateFile(file, file, file).Object);

                    Builder.Execute(sourceDir, outputDir, metaDir, fileGenerators);

                    foreach (var generatedFile in generatedFiles)
                    {
                        FileAssert.AreEqual(tmpDir.CreateFile(generatedFile), Path.Combine(outputDir, generatedFile));
                    }
                }
            }
        }
Exemplo n.º 23
0
        public void TestExecute_cleans_unfinished_directories_before_starting_the_build()
        {
            using (var tmpDir = new TmpDir()) {
                var partialTask = MockBuildTasks.NoOp("task1")
                                  .WithExecuteAction((sourceDir, outputDir, deps) => {
                    File.WriteAllText(Path.Combine(outputDir, "foo"), "42");
                    throw new Exception("Test exception");
                });
                try {
                    Builder.Execute(tmpDir.Path, tmpDir.CreateDir("out"), tmpDir.CreateDir(".bud"), partialTask.Object);
                } catch (Exception) {
                    // ignored
                }
                var fullTask = MockBuildTasks.NoOp("task1")
                               .WithExecuteAction((sourceDir, outputDir, deps) =>
                                                  File.WriteAllText(Path.Combine(outputDir, "bar"), "9001"));
                Builder.Execute(tmpDir.Path, tmpDir.CreateDir("out"), tmpDir.CreateDir(".bud"), fullTask.Object);

                FileAssert.AreEqual(tmpDir.CreateFile("9001"), tmpDir.CreatePath("out", "bar"));
                FileAssert.DoesNotExist(tmpDir.CreatePath("out", "foo"));
            }
        }
Exemplo n.º 24
0
        public async static Task CreateServerWin()
        {
            if (!File.Exists("../steamcmd/steamcmd.exe"))
            {
                if (!Directory.Exists("../steamcmd/"))
                {
                    Directory.CreateDirectory("../steamcmd");
                }
                else
                {
                    TmpDir.CleanDirRecursive("../steamcmd/");
                }
                Console.WriteLine("Downloading steamcmd");
                using (TmpDir dir = new TmpDir("."))
                {
                    using (WebClient client = new WebClient())
                    {
                        client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(LoadingBar.DownloadProgressCallback);
                        await client.DownloadFileTaskAsync("https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip", dir.dirName + "steamcmd.zip");

                        Console.Write("\n\r");
                    }
                    ZipFile.ExtractToDirectory(dir.dirName + "steamcmd.zip", "../steamcmd/");
                }
            }
            using (Process process = new Process())
            {
                process.StartInfo.CreateNoWindow         = false;
                process.StartInfo.RedirectStandardError  = false;
                process.StartInfo.RedirectStandardInput  = false;
                process.StartInfo.RedirectStandardOutput = false;
                process.StartInfo.FileName  = "../steamcmd/steamcmd.exe";
                process.StartInfo.Arguments = "+login anonymous +force_install_dir \"../\" +app_update 786920 -beta beta validate +quit";
                process.Start();
                process.WaitForExit();
            }
        }