Example #1
0
    public override int GetHashCode()
    {
        int hashcode = 157;

        unchecked {
            if (__isset.endpoint)
            {
                hashcode = (hashcode * 397) + Endpoint.GetHashCode();
            }
            if (__isset.endpointSsl)
            {
                hashcode = (hashcode * 397) + EndpointSsl.GetHashCode();
            }
            if (__isset.updateUrl)
            {
                hashcode = (hashcode * 397) + UpdateUrl.GetHashCode();
            }
            if (__isset.c2dmAccount)
            {
                hashcode = (hashcode * 397) + C2dmAccount.GetHashCode();
            }
            if (__isset.nniServer)
            {
                hashcode = (hashcode * 397) + NniServer.GetHashCode();
            }
        }
        return(hashcode);
    }
Example #2
0
    public override string ToString()
    {
        var  sb      = new StringBuilder("SystemConfiguration(");
        bool __first = true;

        if (Endpoint != null && __isset.endpoint)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Endpoint: ");
            Endpoint.ToString(sb);
        }
        if (EndpointSsl != null && __isset.endpointSsl)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("EndpointSsl: ");
            EndpointSsl.ToString(sb);
        }
        if (UpdateUrl != null && __isset.updateUrl)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("UpdateUrl: ");
            UpdateUrl.ToString(sb);
        }
        if (C2dmAccount != null && __isset.c2dmAccount)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("C2dmAccount: ");
            C2dmAccount.ToString(sb);
        }
        if (NniServer != null && __isset.nniServer)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("NniServer: ");
            NniServer.ToString(sb);
        }
        sb.Append(")");
        return(sb.ToString());
    }
Example #3
0
            public void ReadXml(XmlReader reader)
            {
                bool in_urls = false;

                reader.MoveToNextAttribute();
                if (reader.Name == "status")
                {
                    status = reader.Value;
                }
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (!in_urls)
                        {
                            if (reader.Name == "urls")
                            {
                                urls    = new List <UpdateUrl>();
                                in_urls = true;
                            }
                            else if (reader.Name == "manifest")
                            {
                                manifest = new UpdateManifest();
                                XmlReader s = reader.ReadSubtree();
                                s.Read();
                                manifest.ReadXml(s);
                                s.Close();
                            }
                        }
                        else if (reader.Name == "url")
                        {
                            UpdateUrl uu = new UpdateUrl();
                            XmlReader s  = reader.ReadSubtree();
                            s.Read();
                            uu.ReadXml(s);
                            s.Close();
                            urls.Add(uu);
                        }
                    }
                    else if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        if (reader.Name == "urls")
                        {
                            in_urls = false;
                        }
                    }
                }
            }
Example #4
0
        public DialogResult CheckUpdate <T>(Form parentForm, out Dictionary <string, string> configurations) where T : Form, IUpdateForm, new()
        {
            ClearOldFile(Environment.CurrentDirectory);
            bool   result = false;
            string tempUpdateConfigFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".json");

            Common.WriteLog_Information("配置文件临时路径:{0}", tempUpdateConfigFile);
            try
            {
                string url = string.Empty;
                if (!UpdateUrl.EndsWith("/"))
                {
                    url = UpdateUrl + "/";
                }
                url += updateConfig;

                if (download.HttpDownload(url, tempUpdateConfigFile))
                {
                    UpdateInfo = Json.JsonDeserialize <UpdateInfo>(File.ReadAllText(tempUpdateConfigFile));
                    File.Delete(tempUpdateConfigFile);
                    if (UpdateInfo == null)
                    {
                        throw Common.Exception <Exception>("更新配置文件反序列失败!" + Environment.NewLine + "错误代码:0x0d3");
                    }
                    foreach (UpdateFileInfo updateFileInfo in UpdateInfo.FileInfos)
                    {
                        if (Common.CheckFileIsUpdate(updateFileInfo))
                        {
                            result = true;
                            break;
                        }
                    }
                }

                configurations = null;
                if (result)
                {
                    configurations = UpdateInfo.Configurations;
                    using (IUpdateForm updateForm = new T())
                    {
                        Common.WriteLog_Information("实例化更新窗体,窗体类型:{0}", typeof(T).AssemblyQualifiedName);

                        updateForm.FormClosing  += (s, e) => { e.Cancel = beginUpdate; };
                        updateForm.Shown        += (s, e) => { OnUpdateProgressing(new UpdateArgs(UpdateState.Find, null, NeedUpdateFile.Length, -1)); };
                        updateForm.OnErrorUpdate = new Action(delegate
                        {
                            beginUpdate = false;
                            Common.WriteLog_Warning("更新发生错误");
                            updateForm.DialogResult = DialogResult.Abort;
                        });

                        updateForm.OnFinishUpdate = new Action(delegate
                        {
                            beginUpdate = false;
                            Common.WriteLog_Information("更新完成");
                            updateForm.DialogResult = DialogResult.OK;
                        });

                        updateForm.OnCancelUpdate = new Action(delegate
                        {
                            beginUpdate = false;
                            OnUpdateProgressing(new UpdateArgs(UpdateState.Cancel, null, NeedUpdateFile.Length, -1));
                            updateForm.DialogResult = DialogResult.Cancel;
                        });

                        updateForm.OnRollbackUpdate = OnRollbackUpdate;

                        updateForm.OnBeginUpdate = OnBeginUpdate;

                        updateForm.UpdateInfo = _UpdateInfo;

                        updateForm.VersionHistory = VersionHistory;

                        updateForm.NeedUpdateFile = NeedUpdateFile;

                        updateForm.BackupFile = new Func <Dictionary <string, string> >(delegate
                        {
                            return(BackupFile);
                        });

                        UpdateProgressingCallBack = updateForm.UpdateProgressingCallBack;



                        DialogResult dialogResult = (DialogResult)parentForm.Invoke(new Func <IWin32Window, DialogResult>(delegate { return(updateForm.ShowDialog(parentForm)); }), parentForm);
                        if (dialogResult == DialogResult.Abort)
                        {
                            Common.WriteLog_Error(Exception);
                            throw Exception;
                        }
                        return(dialogResult);
                    }
                }
                return(DialogResult.Cancel);
            }
            catch (Exception ex)
            {
                throw Common.Exception <Exception>(ex.Message + Environment.NewLine + "错误代码:0x0f03");
            }
        }
Example #5
0
        static void Main(string[] args)
        {
#if !_CONSOLE
            foreach (string arg in args)
            {
                if (arg == "--setautorun")
                {
                    if (!Controller.AutoStartup.Switch())
                    {
                        Environment.ExitCode = 1;
                    }
                    return;
                }
            }
            using (Mutex mutex = new Mutex(false, "Global\\ShadowsocksR_" + Application.StartupPath.GetHashCode()))
            {
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                Application.EnableVisualStyles();
                Application.ApplicationExit += Application_ApplicationExit;
                SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
                Application.SetCompatibleTextRenderingDefault(false);

                if (!mutex.WaitOne(0, false))
                {
                    MessageBox.Show(I18N.GetString("Find Shadowsocks icon in your notify tray.") + "\n" +
                        I18N.GetString("If you want to start multiple Shadowsocks, make a copy in another directory."),
                        I18N.GetString("ShadowsocksR is already running."));
                    return;
                }
#endif
                Directory.SetCurrentDirectory(Application.StartupPath);
                //#if !DEBUG
                Logging.OpenLogFile();
                //#endif
#if !_CONSOLE
                int try_times = 0;
                while (Configuration.Load() == null)
                {
                    if (try_times >= 5)
                        return;
                    using (InputPassword dlg = new InputPassword())
                    {
                        if (dlg.ShowDialog() == DialogResult.OK)
                            Configuration.SetPassword(dlg.password);
                        else
                            return;
                    }
                    try_times += 1;
                }
                
#endif
                _controller = new ShadowsocksController();
                HostMap.Instance().LoadHostFile();

                UpdateUrl.Instance().Load();
#if !_CONSOLE
                _viewController = new MenuViewController(_controller);
#endif

                _controller.Start();

#if !_CONSOLE
                //Util.Utils.ReleaseMemory();

                Application.Run();
            }
#else
            Console.ReadLine();
            _controller.Stop();
#endif
        }