Esempio n. 1
0
        private static bool Initialize(string[] args)
        {
            Console.Title = "压缩包密码测试工具";
            List <string> StartupParameters = args.ToList();

            if (StartupParameters.Contains("-Debug"))
            {
                while (true)
                {
                    Console.Write("注意。程序处于Debug状态,将会在控制台输出大量信息,是否继续?(按Y继续/按N退出Debug模式): ");
                    switch (Console.ReadKey().Key)
                    {
                    case ConsoleKey.Y:
                        ProgramParameter.DebugMode = true;
                        Debugger.Launch();
                        break;

                    case ConsoleKey.N:
                        break;

                    case ConsoleKey.F:
                        ProgramParameter.DebugMode     = true;
                        ProgramParameter.FastDebugMode = true;
                        Debugger.Launch();
                        break;

                    default:
                        Console.WriteLine();
                        Console.WriteLine("输入错误!");
                        continue;
                    }
                    Console.Clear();
                    break;
                }
            }

            if (Debugger.IsAttached)
            {
                Console.Title += " - DEBUG ";
                if (ProgramParameter.FastDebugMode)
                {
                    Console.Title += "[Fast]";
                }
            }

            using (FileStream configFile = new FileStream(ProgramParameter.AppPath + "config.json", FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                JObject config = new JObject();
                if (configFile.Length == 0)
                {
                    config.Add("CheckUpgrade", DateTime.MinValue);
                    configFile.Write(Encoding.UTF8.GetBytes(config.ToString()), 0, Encoding.UTF8.GetBytes(config.ToString()).Length);
                    configFile.Flush();
                    configFile.Position = 0;
                }
                using (StreamReader configString = new StreamReader(configFile))
                {
                    config = (JObject)JsonConvert.DeserializeObject(configString.ReadToEnd());
                    Console.WriteLine("上次检查更新: " + config["CheckUpgrade"].ToObject <DateTime>().ToLocalTime().ToString());
                    if (config["CheckUpgrade"].ToObject <DateTime>() < (DateTime.Now - new TimeSpan(1, 0, 0)))
                    {
                        Console.WriteLine("正在从github.com获取最新版本信息...");
                        if (Upgrade.CheckUpgrade(new Uri("https://api.github.com/repos/" + ProgramParameter.Developer + "/" + ProgramParameter.AppName + "/releases/latest"), Http.Method.GET, new Dictionary <string, string>()
                        {
                            ["user-agent"] = ProgramParameter.AppName + " " + string.Join(".", ProgramParameter.Version) + ";"
                        }))
                        {
                            Console.WriteLine("当前本地程序已是最新版本。");
                            config["CheckUpgrade"] = DateTime.Now;
                        }
                        else
                        {
                            Console.ReadLine();
                            return(false);
                        }
                    }
                    configFile.Seek(0, SeekOrigin.Begin);
                    configFile.SetLength(0);
                    configFile.Write(Encoding.UTF8.GetBytes(config.ToString()), 0, Encoding.UTF8.GetBytes(config.ToString()).Length);
                    configFile.Flush();
                }
            }


            if (StartupParametersCheck(StartupParameters, "-F"))
            {
                try
                {
                    ProgramParameter.ArchiveFile = new FileInfo(Path.GetFullPath(StartupParameters[StartupParameters.IndexOf("-F") + 1]));
                    while (!ProgramParameter.ArchiveFile.Exists)
                    {
                        Console.WriteLine("没有找到您的压缩包[" + ProgramParameter.ArchiveFile.FullName + "]!");
                        Console.WriteLine("请将压缩包拖放到本窗口,或手动输入文件地址。(操作完成后, 按回车键继续)");
                        ProgramParameter.ArchiveFile = new FileInfo(Path.GetFullPath(Console.ReadLine()));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("尝试读取压缩包信息时出现错误!");
                    throw ex;
                }
            }
            else
            {
                do
                {
                    Console.WriteLine("您似乎没有提供需要进行测试的压缩包地址!");
                    Console.WriteLine("请将压缩包拖放到本窗口,或手动输入文件地址。(操作完成后, 按回车键继续)");
                    ProgramParameter.ArchiveFile = new FileInfo(Path.GetFullPath(Console.ReadLine()));
                } while (!ProgramParameter.ArchiveFile.Exists);
            }


            if (StartupParametersCheck(StartupParameters, "-D"))
            {
                try
                {
                    ProgramParameter.Dictionary = new FileInfo(Path.GetFullPath(StartupParameters[StartupParameters.IndexOf("-D") + 1]));
                    while (!ProgramParameter.Dictionary.Exists)
                    {
                        Console.WriteLine("没有找到您的密码字典[" + ProgramParameter.Dictionary.FullName + "]!");
                        Console.WriteLine("请将密码字典拖放到本窗口,或手动输入文件地址。(操作完成后, 按回车键继续)");
                        ProgramParameter.Dictionary = new FileInfo(Path.GetFullPath(Console.ReadLine()));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("尝试读取密码字典时出现错误!");
                    throw ex;
                }
            }
            else
            {
                do
                {
                    Console.WriteLine("您似乎没有提供您的密码字典地址!");
                    Console.WriteLine("请将密码字典拖放到本窗口,或手动输入文件地址。(操作完成后, 按回车键继续)");
                    ProgramParameter.Dictionary = new FileInfo(Path.GetFullPath(Console.ReadLine()));
                } while (!ProgramParameter.Dictionary.Exists);
            }


            if (StartupParametersCheck(StartupParameters, "-T"))
            {
                try
                {
                    ProgramParameter.DecryptArchiveThreadCount = Convert.ToInt32(StartupParameters[StartupParameters.IndexOf("-T") + 1]);
                }
                catch (Exception ex)
                {
                    Console.Write("启动参数存在错误!请检查参数:[-T]");
                    if (ProgramParameter.DebugMode)
                    {
                        Console.Write(ex.ToString());
                    }
                    throw ex;
                }
                if (ProgramParameter.DecryptArchiveThreadCount > (Environment.ProcessorCount - 1))
                {
                    Console.WriteLine("测试密码线程数过高! (已调整为最大线程[" + (Environment.ProcessorCount - 1).ToString() + "])");
                    ProgramParameter.DecryptArchiveThreadCount = Environment.ProcessorCount - 1;
                }
            }
            else
            {
                Console.WriteLine("您似乎没有提供进行测试的线程数!");
                do
                {
                    string DecryptArchiveThreadCountTemp;
                    do
                    {
                        Console.Write("请输入测试密码使用的线程数(操作完成后, 按回车键继续):");
                        DecryptArchiveThreadCountTemp = Console.ReadLine();
                    } while (string.IsNullOrEmpty(DecryptArchiveThreadCountTemp));
                    try
                    {
                        ProgramParameter.DecryptArchiveThreadCount = Convert.ToInt32(DecryptArchiveThreadCountTemp);
                        break;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("线程数存在错误,请检查输入的参数!");
                        continue;
                    }
                } while (true);
                if (ProgramParameter.DecryptArchiveThreadCount > (Environment.ProcessorCount - 1))
                {
                    Console.WriteLine("进行测试线程数过高! 已调整为最大线程(" + (Environment.ProcessorCount - 1).ToString() + ")");
                    ProgramParameter.DecryptArchiveThreadCount = Environment.ProcessorCount - 1;
                }
            }
            return(true);
        }
Esempio n. 2
0
        private void UpgradeApplication()
        {
            //Start Timer
            Upgrade.StartTimer();

            //Write out Header
            HtmlUtils.WriteHeader(Response, "upgrade");

            Response.Write("<h2>Current Assembly Version: " + Globals.glbAppVersion + "</h2>");
            Response.Flush();

            // get path to script files
            string providerPath = PortalSettings.GetProviderPath();

            if (!providerPath.StartsWith("ERROR:"))
            {
                // get current database version
                IDataReader dr = PortalSettings.GetDatabaseVersion();
                if (dr.Read())
                {
                    //Call Upgrade with the current DB Version to upgrade an
                    //existing DNN installation
                    int    majVersion         = Convert.ToInt32(dr["Major"]);
                    int    minVersion         = Convert.ToInt32(dr["Minor"]);
                    int    buildVersion       = Convert.ToInt32(dr["Build"]);
                    string strDatabaseVersion = String.Format(majVersion.ToString(), "00") + "." + String.Format(minVersion.ToString(), "00") + "." + String.Format(buildVersion.ToString(), "00");

                    Response.Write("<h2>Current Database Version: " + strDatabaseVersion + "</h2>");
                    Response.Flush();

                    string ignoreWarning = Null.NullString;
                    string strWarning    = Null.NullString;
                    if ((majVersion == 3 && minVersion < 3) || (majVersion == 4 && minVersion < 3))
                    {
                        //Users and profile have not been transferred

                        // Get the name of the data provider
                        ProviderConfiguration providerConfiguration = ProviderConfiguration.GetProviderConfiguration("data");

                        //Execute Special Script
                        Upgrade.ExecuteScript(providerPath + "Upgrade." + providerConfiguration.DefaultProvider);

                        if ((Request.QueryString["ignoreWarning"] != null))
                        {
                            ignoreWarning = Request.QueryString["ignoreWarning"].ToLower();
                        }

                        strWarning = Upgrade.CheckUpgrade();
                    }
                    else
                    {
                        ignoreWarning = "true";
                    }

                    //Check whether Upgrade is ok
                    if (strWarning == Null.NullString || ignoreWarning == "true")
                    {
                        Response.Write("<br><br>");
                        Response.Write("<h2>Upgrade Status Report</h2>");
                        Response.Flush();
                        Upgrade.UpgradeDNN(providerPath, strDatabaseVersion.Replace(".", ""));

                        //Install Resources
                        ResourceInstaller objResourceInstaller = new ResourceInstaller();
                        objResourceInstaller.Install(true, 0);

                        Response.Write("<h2>Upgrade Complete</h2>");
                        Response.Write("<br><br><h2><a href='../Default.aspx'>Click Here To Access Your Portal</a></h2><br><br>");
                    }
                    else
                    {
                        Response.Write("<h2>Warning:</h2>" + strWarning.Replace("\r\n", "<br />"));

                        Response.Write("<br><br><a href='Install.aspx?mode=Install&ignoreWarning=true'>Click Here To Proceed With The Upgrade.</a>");
                    }
                    Response.Flush();
                }
                dr.Close();
            }
            else
            {
                Response.Write("<h2>Upgrade Error: " + providerPath + "</h2>");
                Response.Flush();
            }

            //Write out Footer
            HtmlUtils.WriteFooter(Response);
        }