コード例 #1
0
        internal static void StartKernel()
        {
            FilesList.LoadSharedFiles();

            UDPListener.Start();
            Listener.Start();

            CLog.Log(Constants.Log.Notify, "INIT_KRN", Version);
            LastSearch = 1;

            if (Preferences.GetBool("IPFilterEnabled"))
            {
                IPFilter = new CIPFilter();
                IPFilter.LoadIPFilter(DllDirectory, "ipfilter.dat", 128);
            }
            else
            {
                IPFilter = null;
            }

            if (Preferences.GetBool("DownloadServerMet"))
            {
                httpDownload.DownloadFile(Preferences.GetString("ServerMetUri"), "", "server.met", false);
            }
            else
            {
                CKernel.ServersList.Load("", true);
            }

            //if threaded = true, it returns "", else can be used later to get
            //CLog.Log(Constants.Log.Info,httpDownload.getReadInfoFromXML("log"));
            //

            if (Preferences.GetBool("AutoReconnect"))
            {
                ServersList.ConnectToAnyServer();
            }
        }
コード例 #2
0
        /// <summary>
        /// Event handler for preferences class if any property was changed.
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">changed property arguments</param>
        internal void OnPropertyChanged(object sender, PropertyEventArgs e)
        {
            if (e.Key == "MaxDownloadRate")
            {
                float upRate   = Preferences.GetFloat("MaxUploadRate");
                float downRate = (float)e.NewValue;
                if (downRate < 1.0F)
                {
                    e.NewValue = 1.0F;
                }

                if ((upRate * 4.0F < downRate) && (upRate < 9))
                {
                    e.NewValue = upRate * 4.0F;
                }
                else
                {
                    // do nothing
                }
            }

            if (e.Key == "MaxUploadRate")
            {
                float upRate   = (float)e.NewValue;
                float downRate = Preferences.GetFloat("MaxDownloadRate");
                if (upRate < 1.0F)
                {
                    e.NewValue = 1.0F;
                }

                if ((upRate * 4.0F < downRate) && (upRate < 9))
                {
                    Preferences.SetProperty("MaxDownloadRate", upRate * 4.0F, false);
                }
                else
                {
                    // do nothing
                }
            }

            if (e.Key == "RemotePassword")
            {
                System.Security.Cryptography.MD5 crypto = System.Security.Cryptography.MD5.Create();
                byte [] c         = null;
                string  clearPass = (string)e.NewValue;
                c = new byte[clearPass.Length];
                for (int i = 0; i < clearPass.Length; i++)
                {
                    c[i] = System.Convert.ToByte(clearPass[i]);
                }
                byte[] res = crypto.ComputeHash(c);
                e.NewValue = CKernel.HashToString(res);
            }
            if (e.Key == "Language")
            {
                Globalization.Language = e.NewValue.ToString();
            }

            if (e.Key == "IPFilterEnabled")
            {
                bool enabled = (bool)e.NewValue;
                if (enabled)
                {
                    IPFilter = new CIPFilter();
                    IPFilter.LoadIPFilter(DllDirectory, "ipfilter.dat", 128);
                }
                else
                {
                    IPFilter = null;
                }
            }

            if (e.Key == "TCPPort")
            {
                m_PortChanged = true;
                if (e.NewValue != e.OldValue)
                {
                    CKernel.Listener.Stop();
                    CKernel.Listener = new CListener((ushort)e.NewValue);
                    CKernel.Listener.Start();
                    CKernel.ServersList.ConnectToAnyServer();                    //first call disconnects
                    CKernel.ServersList.ConnectToAnyServer();                    //secons call connects
                }
            }

            if (e.Key == "UDPPort")
            {
                if (e.NewValue != e.OldValue)
                {
                    CKernel.UDPListener.Close();
                    CKernel.UDPListener = new CUDPListener();
                    CKernel.UDPListener.Start();
                }
            }

            if (e.Key == "TempFolders")
            {
                ArrayList newFolders = new ArrayList((Array)e.NewValue);
                ArrayList oldFolders = new ArrayList((Array)e.OldValue);
                foreach (string oldfolder in (Array)e.OldValue)
                {
                    if (!newFolders.Contains(oldfolder))
                    {
                        //remove files from folder
                        CKernel.FilesList.RemoveIncompleteFolder(oldfolder);
                    }
                }
                foreach (string newfolder in (Array)e.NewValue)
                {
                    if (!oldFolders.Contains(newfolder))
                    {
                        //remove files from folderadd new temp folder
                        CKernel.FilesList.AddNewIncompleteFolder(newfolder);
                    }
                }
            }
            if (e.Key == "SharedFolders")
            {
                string sharedOld = "";
                string sharedNew = "";
                foreach (string oldfolder in (Array)e.OldValue)
                {
                    sharedOld += oldfolder;
                }
                foreach (string newfolder in (Array)e.NewValue)
                {
                    sharedNew += newfolder;
                }
                if (sharedOld != sharedNew)
                {
                    CKernel.FilesList.RefreshSharedList();
                }
            }
        }