Beispiel #1
0
        public CKernel()
        {
#if VERBOSE
            LogClient = new CLogClient();
#endif
            m_PortChanged = false;
            m_Version     = (Protocol.eAnt_VERSION_MAJOR).ToString() + "." + Protocol.eAnt_VERSION.ToString("00");

            Preferences = new Config(DllDirectory, "config.xml", "0.02", "AntKernel");

            Preferences.PropertyChanged  += new Config.PropertyEventHandler(OnPropertyChanged);
            Preferences.PropertyDefaults += new Config.PropertyDefaultHandler(OnGetDefaultProperty);
            Preferences.PropertyLoaded   += new Config.PropertyLoadedHandler(OnPropertyLoaded);
            Preferences.LoadProperties();

            Globalization = new Classes.Globalization(LangDirectory, "kernel_", "xml", Preferences.GetString("Language"));



            SourcesOld      = new CSourcesOld();
            Listener        = new CListener();
            ConnectionsList = new CConnectionsList();
            ServersList     = new CServersList();

            FilesList               = new CFilesList();
            ClientsList             = new CClientsList();
            InterfaceGateway[0]     = new CInterfaceGateway();
            InterfaceGateway[0].apw = true;
            //InterfaceGateway[0].CheckPw(Preferences.GetString("RemotePassword"));
            //FilesList.LoadSharedFiles(); // > StartKernel()
            FriendsList = new CFriendsList();

            GlobalStatistics = new CStatistics();
            if (Preferences.GetBool("RemoteControlEnabled"))
            {
                Sremoto = new CRemoting();
            }
            Searchs     = new SortedList();
            Queue       = new CQueue();
            UDPListener = new CUDPListener();           // UDPListener.Start(); > StartKernel()

            CategoriesList = new CCategoriesList();

            httpDownload             = new ChttpDownload();
            httpDownload.Downloaded += new DownloadedEventHandler(OnFileDownloaded);
        }
Beispiel #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();
                }
            }
        }