示例#1
0
文件: Statics.cs 项目: weinre/ezAria2
        static Stc()
        {
            ConfigController Start = new ConfigController();

            //判断几个关键的文件和路径是否存在
            if (!File.Exists(Start.Configs.Save_session))
            {
                File.Create(Start.Configs.Save_session).Close();
            }
            if (!File.Exists(Start.Configs.Input_file))
            {
                File.Create(Start.Configs.Input_file).Close();
            }
            if (!Directory.Exists(Start.Configs.Dir))
            {
                Directory.CreateDirectory(Start.Configs.Dir);
            }
            //if (!File.Exists(@"HistoryList.log"))
            //{
            //    File.Create(@"HistoryList.log").Close();
            //}
            Start.Make();
            Aria2Process = new Process();
            Aria2Process.StartInfo.FileName       = Config.Aria2cPath;
            Aria2Process.StartInfo.CreateNoWindow = true;
            Aria2Process.StartInfo.Arguments      = @"--conf-path=" + Config.Aria2cConfigPath;
            Aria2Process.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
            Aria2Process.Start();
            GloConf = Start.Configs;//给全局配置变量赋值,同时初始化所有其他全局变量
            Config.WebSocketPath = string.Format("ws://127.0.0.1:{0}/jsonrpc", GloConf.Rpc_listen_port);
            Config.Rpc_secret    = GloConf.Rpc_secret;
            Line   = new JRCtler(Config.WebSocketPath);//这里的逻辑重新梳理后,可以允许ezAria2作为客户端,控制其他主机的下载服务
            ProCtl = new ProgressController();
            Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
            Application.Current.Exit        += new ExitEventHandler(Quit);
            Application.Current.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(Crash);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
            dispatcherTimer.Start();
        }
示例#2
0
 /// <summary>
 /// 序列化配置文件为ConfigInformation对象
 /// </summary>
 /// <param name="Json_config">Json形式的Config配置文件</param>
 private void LoadConfigFile(string Json_config)
 {
     Configs = JsonConvert.DeserializeObject <ConfigInformation>(Json_config);
     if (Configs.Rpc_secret.Length != 16)
     {
         Random creator    = new Random();
         string charsToUse = "AzByCxDwEvFuGtHsIrJqKpLoMnNmOlPkQjRiShTgUfVeWdXcYbZa1234567890";
         int    i          = 1;
         Configs.Rpc_secret = "";
         while (i <= 16)
         {
             int    a = creator.Next(0, 61);
             string b = charsToUse.Substring(a, 1);
             Configs.Rpc_secret = Configs.Rpc_secret + b;
             i = i + 1;
         }
     }
     if (Configs.Dir == "")
     {
         KnownFolder DownloadFolder = new KnownFolder(KnownFolderType.Downloads);
         Configs.Dir = DownloadFolder.Path;
     }
 }
示例#3
0
 /// <summary>
 /// 接收一个ConfigInformation对象,并对其操作
 /// </summary>
 /// <param name="e">使用时应加入Out前缀</param>
 public ConfigController(ConfigInformation e)
 {
     Configs = e;
 }
示例#4
0
 public Settings()
 {
     Conf = Stc.GloConf.Copy();
     InitializeComponent();
     DataContext = Conf;
 }