Ejemplo n.º 1
0
        private static int HandleAppLaunch(ArgumentParser parser)
        {
            var app = new ClickOnce.Application();

            app.BasePath = parser.Path ?? ClickOnce.Tools.LibraryLocation;
            Console.WriteLine($" Using basepath: {app.BasePath}");

            app.Load(parser.AppRef);
            var depAsm = app.LastLoadedManifest;

            var deps = app.Dependencys;

            Console.WriteLine($" TotalSize: {app.TotalSizeByManifest} for total {deps.Count} dependencys");
            var entry = app.Entry;

            string baseLibName = app.BaseLibName;

            app.CopyDependencysLocal();

            foreach (var fi in entry.GetType().GetFields())
            {
                Console.WriteLine($" Entry: {fi.Name} val: {fi.GetValue(entry)}");
            }
            string entryPath = Path.Combine(app.BasePath, entry.LocalLibName());
            string entryExe  = Path.Combine(entryPath, entry.Executable);

            Console.WriteLine($" Run {entryExe} {entry.Parameters}");

            if (parser.NoLaunch)
            {
                return(0);
            }

            string arguments = entry.Parameters;

            if (parser.ExtraParams.Count > 0)
            {
                arguments = string.Join(" ", parser.ExtraParams.Select(a => a.Contains(" ") ? $"\"{a}\"" : a));
                Console.WriteLine($" Will use passthru arguments {arguments}");
            }

            var startInfo = new ProcessStartInfo(entryExe);

            startInfo.UseShellExecute  = false;
            startInfo.WorkingDirectory = entryPath;
            startInfo.WindowStyle      = ProcessWindowStyle.Normal;
            startInfo.Arguments        = arguments;

            using (var exeProcess = Process.Start(startInfo))
            {
                // we will only wait for a little bit
                // TODO add option for if we should wait or not
                exeProcess.WaitForExit(1000);
                if (exeProcess.HasExited)
                {
                    return(exeProcess.ExitCode);
                }
            }
            return(0);
        }
Ejemplo n.º 2
0
        public void ValidateDownloadIntegrationTest(string testfile)
        {
            var app = new ClickOnce.Application();

            app.BasePath = GetTempPath();
            app.Load(testfile);
            var depAsm = app.LastLoadedManifest;

            // always true in App
            Assert.True(app.LastLoadedApp.Install.HasValue);
            // but should still be false in Manifest
            Assert.False(app.LastLoadedManifest.Install.HasValue);

            // for now we don't have any tests where this is false
            Assert.True(app.LastLoadedApp.MapFileExtensions);
            // this should be propagated
            Assert.True(app.LastLoadedManifest.MapFileExtensions);

            var deps = app.Dependencys;

            Console.WriteLine($" TotalSize: {app.TotalSizeByManifest} for total {deps.Count} dependencys");
            var entry = app.Entry;

            string baseLibName = app.BaseLibName;

            foreach (var d in deps)
            {
                Assert.Contains(".", d.Codebase);
                string libName = d.LocalLibName() ?? baseLibName;
                Console.WriteLine($"  LibName: {libName} {d.Codebase}");

                Assert.NotNull(libName);
                Assert.NotEmpty(libName);
                string p = Path.Combine(app.BasePath, libName);

                string dstPath = Path.Combine(entry.LocalPath, d.Codebase);
                Console.WriteLine($"{dstPath}");
            }

            app.CopyDependencysLocal();

            foreach (var fi in entry.GetType().GetFields())
            {
                Console.WriteLine($" Entry: {fi.Name} val: {fi.GetValue(entry)}");
            }
            Console.WriteLine($" Entry {entry.LocalLibName()}");
            string entryPath = Path.Combine(app.BasePath, entry.LocalLibName());

            Console.WriteLine($" Path {entryPath}");

            Console.WriteLine(string.Join("\n", deps.Select(d => d.Codebase).Where(n => Path.GetExtension(n) == ".exe")));

            Assert.Contains(".manifest", deps.Select(d => Path.GetExtension(d.Codebase)));
            Assert.Contains(".application", deps.Select(d => Path.GetExtension(d.Codebase)));
            Assert.Contains(Path.GetFileName(testfile.Replace("%20", " ")), deps.Select(d => Path.GetFileName(d.Codebase)));
            Assert.Contains(".appref-ms", deps.Select(d => Path.GetExtension(d.Codebase)));
            Assert.Contains(entry.Product + ".appref-ms", deps.Select(d => Path.GetFileName(d.Codebase)));
            Assert.Contains(entry.Executable, deps.Select(d => Path.GetFileName(d.Codebase)));

            Assert.Equal(1, deps.Where(d => Path.GetExtension(d.Codebase) == ".manifest").Count());
            Assert.Equal(1, deps.Where(d => Path.GetExtension(d.Codebase) == ".application").Count());
            Assert.Equal(1, deps.Where(d => Path.GetFileName(d.Codebase) == entry.Executable).Count());
            Assert.Equal(1, deps.Where(d => Path.GetFileName(d.Codebase) == entry.Product + ".appref-ms").Count());
        }