Esempio n. 1
0
        static int Main(string[] args)
        {
            Console.WriteLine("Fox Installer");
            Console.WriteLine("");
            if (args.Length < 2)
            {
                Help();
                return(1);
            }

            ComputerCertificate ccert = new ComputerCertificate();

            if (ccert.GetCertificate() == false)
            {
                Console.WriteLine("Cannot load computer certificate from Fox SDC");
#if DEBUG
                Console.WriteLine("Press any key . . .");
                Console.ReadKey(true);
#endif
                return(2);
            }

            PackageInstaller pkgi      = new PackageInstaller();
            PKGStatus        pkgres    = PKGStatus.NotNeeded;
            PKGRecieptData   reciept   = null;
            string           ErrorText = "";
            bool             res       = false;
            List <byte[]>    cer       = new List <byte[]>();

            switch (args[0].ToLower().Trim())
            {
            case "-install":
                Console.WriteLine("Installing " + args[1].Trim());
                cer = LoadCERFiles(args);
                res = pkgi.InstallPackage(args[1].Trim(), cer, PackageInstaller.InstallMode.Install, false, out ErrorText, out pkgres, out reciept);
                break;

            case "-test":
                Console.WriteLine("Testing " + args[1].Trim());
                cer = LoadCERFiles(args);
                res = pkgi.InstallPackage(args[1].Trim(), cer, PackageInstaller.InstallMode.Test, false, out ErrorText, out pkgres, out reciept);
                break;

            case "-info":
                cer = LoadCERFiles(args);
                res = pkgi.PackageInfo(args[1].Trim(), cer, out ErrorText);
                Console.WriteLine(ErrorText);
#if DEBUG
                Console.WriteLine("Press any key . . .");
                Console.ReadKey(true);
#endif
                return(res == true ? 0 : 1);

            default:
                Console.WriteLine("Invalid argurments");
#if DEBUG
                Console.WriteLine("Press any key . . .");
                Console.ReadKey(true);
#endif
                return(1);
            }

            Console.WriteLine("Status: " + pkgres.ToString());

            if (res == false)
            {
                Console.WriteLine(ErrorText);
            }
            else
            {
                if (reciept != null)
                {
                    string recppath = Path.GetDirectoryName(args[1].Trim());
                    if (recppath.EndsWith("\\") == false)
                    {
                        recppath += "\\";
                    }
                    string recieptfile     = recppath + Path.GetFileNameWithoutExtension(args[1].Trim()) + ".foxrecp";
                    string recieptfilesign = recppath + Path.GetFileNameWithoutExtension(args[1].Trim()) + ".sign";
#if DEBUG
                    string recps = JsonConvert.SerializeObject(reciept, Formatting.Indented);
#else
                    string recps = JsonConvert.SerializeObject(reciept);
#endif
                    File.WriteAllText(recieptfile, recps, Encoding.UTF8);
                    byte[] sign = ccert.Sign(Encoding.UTF8.GetBytes(recps));
                    File.WriteAllBytes(recieptfilesign, sign);
                }
            }
#if DEBUG
            Console.WriteLine("Press any key . . .");
            Console.ReadKey(true);
#endif
            return(0);
        }
Esempio n. 2
0
        public static bool InvokeInstallPackage(string Filename, List <byte[]> CerCertificates, InstallMode Mode, bool ZipIsMetaOnly,
                                                out string ErrorText, out PKGStatus res, out PKGRecieptData Reciept, string OtherDLL = "")
        {
            ErrorText = "Internal issues";
            res       = PKGStatus.Failed;
            Reciept   = null;

            DataHInstallPackageTODO inst = new DataHInstallPackageTODO();

            inst.Filename        = Filename;
            inst.CerCertificates = CerCertificates;
            inst.Mode            = Mode;
            inst.ZipIsMetaOnly   = ZipIsMetaOnly;
            inst.OtherDLL        = OtherDLL;

            Process2ProcessComm p2p = new Process2ProcessComm();

            p2p.SetTODO("INSTALL", inst);
            if (p2p.StartPipe() == false)
            {
                FoxEventLog.WriteEventLog("Cannot start P2PC for INSTALL " + p2p.GetGUID(), EventLogEntryType.Error);
                return(false);
            }

            Process p = new Process();

            p.StartInfo.Arguments       = "-pipeaction " + p2p.GetGUID();
            p.StartInfo.FileName        = Assembly.GetExecutingAssembly().Location;
            p.StartInfo.UseShellExecute = false;
            if (p.Start() == false)
            {
                FoxEventLog.WriteEventLog("Cannot start P2PC Process for INSTALL " + p2p.GetGUID(), EventLogEntryType.Error);
                p2p.ClosePipe();
                return(false);
            }
            p.WaitForExit();

            DataHInstallPackageResult ores = p2p.GetResult <DataHInstallPackageResult>();

            p2p.ClosePipe();
            if (ores == null)
            {
                FoxEventLog.WriteEventLog("P2PC didn't return any data for INSTALL " + p2p.GetGUID(), EventLogEntryType.Error);
                return(false);
            }

            ErrorText = ores.ErrorText;
            res       = ores.res;
            Reciept   = ores.Reciept;
            if (ores.TempDLLFilename != null)
            {
                try
                {
                    File.Delete(ores.TempDLLFilename);
                }
                catch
                {
                }
            }

            return(ores.Return);
        }