Пример #1
0
        static void Main(string[] args)
        {
            ALFADeployerTool DeployerTool = new ALFADeployerTool();
            try
            {
                // Delete the old deployment logs.
                if (File.Exists(Program.LogFilename)) File.Delete(Program.LogFilename);
                if (File.Exists(SevenzipExtractor.LogFilename)) File.Delete(SevenzipExtractor.LogFilename);
                if (File.Exists("DeploymentStager_Recompile.log")) File.Delete("DeploymentStager_Recompile.log");


                // Make sure that we have the 7-zip extractor.
                if (!File.Exists(SevenZipFilename)) throw new Exception(string.Format("{0} not found!", SevenZipFilename));

                // Verify that we have the Advanced Script Compiler.
                if (!File.Exists(ScriptCompilerFilename)) throw new Exception(string.Format("{0} not found!", ScriptCompilerFilename));

                // Run the deployment tool.
                DeployerTool.Run();
            }
            catch (Exception e)
            {
                LogEvent(e.ToString());
            }

            // Pause for user interaction before closing.
            Console.Write("Press any key to exit.");
            Console.ReadKey(true);
        }
Пример #2
0
        static void Main(string[] args)
        {
            ALFADeployerTool DeployerTool = new ALFADeployerTool();

            try
            {
                // Delete the old deployment logs.
                if (File.Exists(Program.LogFilename))
                {
                    File.Delete(Program.LogFilename);
                }
                if (File.Exists(SevenzipExtractor.LogFilename))
                {
                    File.Delete(SevenzipExtractor.LogFilename);
                }
                if (File.Exists("DeploymentStager_Recompile.log"))
                {
                    File.Delete("DeploymentStager_Recompile.log");
                }


                // Make sure that we have the 7-zip extractor.
                if (!File.Exists(SevenZipFilename))
                {
                    throw new Exception(string.Format("{0} not found!", SevenZipFilename));
                }

                // Verify that we have the Advanced Script Compiler.
                if (!File.Exists(ScriptCompilerFilename))
                {
                    throw new Exception(string.Format("{0} not found!", ScriptCompilerFilename));
                }

                // Run the deployment tool.
                DeployerTool.Run();
            }
            catch (Exception e)
            {
                LogEvent(e.ToString());
            }

            // Pause for user interaction before closing.
            Console.Write("Press any key to exit.");
            Console.ReadKey(true);
        }
        public void Update(ALFADeployerTool deployer, string DownloadDirectory)
        {
            // Get the download location.
            string DownloadPath = DownloadDirectory + "\\" + name + ".lzma";

            // Get the file location.
            string FileDir = null;
            if (location == "InstallDir") FileDir = deployer.NWN2InstallPath;
            if (location == "NWNX4Dir") FileDir = deployer.NWNX4Path;
            string FilePath = FileDir + "\\" + name;

            Console.WriteLine("Updating '{0}' ...", name);

            // Does the file exist and is it valid?
            if (File.Exists(FilePath))
            {
                if (FileVerification.VerifyFile(FilePath, this))
                {
                    Console.WriteLine("File verified. Update not required.");
                    return;
                }
                else
                {
                    Console.WriteLine("File found, but failed verification. Updating.");
                    File.Delete(FilePath);
                }
            }

            // Does the download file exist and is valid?
            bool bDownloadRequired = true;
            if (File.Exists(DownloadPath))
            {
                if (FileVerification.VerifyFile(DownloadPath, this))
                {
                    Console.WriteLine("Download file found. Extracting.");
                    bDownloadRequired = false;
                }
                else
                {
                    File.Delete(DownloadPath);
                }
            }

            // Download file if necessary.
            if (bDownloadRequired)
            {
                WebClient downloader = new WebClient();
                bool bDownloaded = false;
                foreach (int server in servers)
                {
                    try
                    {
                        // Valid server?
                        if (!deployer.ServerList.Keys.Contains(server)) throw new Exception("Server not found.");

                        // Get local and remote destinations.
                        string url = deployer.ServerList[server] + name + ".lzma";

                        // Try to download.
                        float sizeInMB = (float)(downloadSize) / 1024 / 1024;
                        Console.WriteLine("Downloading update from server {1} ({2} MB)", name, server, sizeInMB);
                        downloader.DownloadFile(url, DownloadPath);

                        // Download. Verify file again.
                        if (!FileVerification.VerifyFile(DownloadPath, this))
                        {
                            // TODO: Log the details of the discrepency.
                            throw new Exception("Verification failed.");
                        }

                        bDownloaded = true;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("WARNING: Download failed for server index '{0}'. {1}", server, e.Message);
                        if (File.Exists(DownloadPath)) File.Delete(DownloadPath);
                    }

                    // Break if we downloaded it successfully.
                    if (bDownloaded) break;
                }

                if (!bDownloaded) throw new Exception(string.Format("Could not download file: {0}", name));
            }

            // Extract it.
            SevenzipExtractor extractor = new SevenzipExtractor(DownloadPath);
            int ExitCode = extractor.extract(FileDir);

            // Check exit codes.
            if (ExitCode == 1)
            {
                Console.WriteLine("WARNING: Non-fatal errors when extracting '{0}'", name);
            }
            else if (ExitCode == 2)
            {
                throw new Exception(string.Format("Fatal error when extracting '{0}'", name));
            }
            else if (ExitCode == 7)
            {
                throw new Exception(string.Format("Command line error."));
            }
            else if (ExitCode == 8)
            {
                throw new Exception(string.Format("Not enough memory when extracting '{0}'", name));
            }

            // Verify extracted file.
            if (!FileVerification.VerifyFile(FilePath, this))
            {
                throw new Exception("Could not verify extracted file. Contact the technical administrator.");
            }
        }
Пример #4
0
        public void Update(ALFADeployerTool deployer, string DownloadDirectory)
        {
            // Get the download location.
            string DownloadPath = DownloadDirectory + "\\" + name + ".lzma";

            // Get the file location.
            string FileDir = null;

            if (location == "InstallDir")
            {
                FileDir = deployer.NWN2InstallPath;
            }
            if (location == "NWNX4Dir")
            {
                FileDir = deployer.NWNX4Path;
            }
            string FilePath = FileDir + "\\" + name;

            Console.WriteLine("Updating '{0}' ...", name);

            // Does the file exist and is it valid?
            if (File.Exists(FilePath))
            {
                if (FileVerification.VerifyFile(FilePath, this))
                {
                    Console.WriteLine("File verified. Update not required.");
                    return;
                }
                else
                {
                    Console.WriteLine("File found, but failed verification. Updating.");
                    File.Delete(FilePath);
                }
            }

            // Does the download file exist and is valid?
            bool bDownloadRequired = true;

            if (File.Exists(DownloadPath))
            {
                if (FileVerification.VerifyFile(DownloadPath, this))
                {
                    Console.WriteLine("Download file found. Extracting.");
                    bDownloadRequired = false;
                }
                else
                {
                    File.Delete(DownloadPath);
                }
            }

            // Download file if necessary.
            if (bDownloadRequired)
            {
                WebClient downloader  = new WebClient();
                bool      bDownloaded = false;
                foreach (int server in servers)
                {
                    try
                    {
                        // Valid server?
                        if (!deployer.ServerList.Keys.Contains(server))
                        {
                            throw new Exception("Server not found.");
                        }

                        // Get local and remote destinations.
                        string url = deployer.ServerList[server] + name + ".lzma";

                        // Try to download.
                        float sizeInMB = (float)(downloadSize) / 1024 / 1024;
                        Console.WriteLine("Downloading update from server {1} ({2} MB)", name, server, sizeInMB);
                        downloader.DownloadFile(url, DownloadPath);

                        // Download. Verify file again.
                        if (!FileVerification.VerifyFile(DownloadPath, this))
                        {
                            // TODO: Log the details of the discrepency.
                            throw new Exception("Verification failed.");
                        }

                        bDownloaded = true;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("WARNING: Download failed for server index '{0}'. {1}", server, e.Message);
                        if (File.Exists(DownloadPath))
                        {
                            File.Delete(DownloadPath);
                        }
                    }

                    // Break if we downloaded it successfully.
                    if (bDownloaded)
                    {
                        break;
                    }
                }

                if (!bDownloaded)
                {
                    throw new Exception(string.Format("Could not download file: {0}", name));
                }
            }

            // Extract it.
            SevenzipExtractor extractor = new SevenzipExtractor(DownloadPath);
            int ExitCode = extractor.extract(FileDir);

            // Check exit codes.
            if (ExitCode == 1)
            {
                Console.WriteLine("WARNING: Non-fatal errors when extracting '{0}'", name);
            }
            else if (ExitCode == 2)
            {
                throw new Exception(string.Format("Fatal error when extracting '{0}'", name));
            }
            else if (ExitCode == 7)
            {
                throw new Exception(string.Format("Command line error."));
            }
            else if (ExitCode == 8)
            {
                throw new Exception(string.Format("Not enough memory when extracting '{0}'", name));
            }

            // Verify extracted file.
            if (!FileVerification.VerifyFile(FilePath, this))
            {
                throw new Exception("Could not verify extracted file. Contact the technical administrator.");
            }
        }