Exemplo n.º 1
0
 private void ReadCreditStruct29a(SafeBufferedFile file, CreditStruct newcstruct)
 {
     file.Read(newcstruct.abyKey);
     newcstruct.nUploadedLo   = file.ReadUInt32(); // uploaded TO him
     newcstruct.nDownloadedLo = file.ReadUInt32(); // downloaded from him
     newcstruct.nLastSeen     = file.ReadUInt32();
     newcstruct.nUploadedHi   = file.ReadUInt32(); // upload high 32
     newcstruct.nDownloadedHi = file.ReadUInt32(); // download high 32
     newcstruct.nReserved3    = file.ReadUInt16();
 }
Exemplo n.º 2
0
 private void ReadCreditStruct(SafeBufferedFile file, CreditStruct newcstruct)
 {
     ReadCreditStruct29a(file, newcstruct);
     newcstruct.nKeySize = file.ReadUInt8();
     file.Read(newcstruct.abySecureIdent, 0, (int)CreditStruct.MAXPUBKEYSIZE);
 }
Exemplo n.º 3
0
        protected void LoadList()
        {
            string strFileName =
                System.IO.Path.Combine(MuleApplication.Instance.Preference.GetMuleDirectory(Mule.Preference.DefaultDirectoryEnum.EMULE_CONFIGDIR),
                                       CLIENTS_MET_FILENAME);

            if (!System.IO.File.Exists(strFileName))
            {
                return;
            }

            SafeBufferedFile file = null;

            try
            {
                file =
                    MpdObjectManager.CreateSafeBufferedFile(strFileName,
                                                            System.IO.FileMode.Open,
                                                            System.IO.FileAccess.Read,
                                                            System.IO.FileShare.None);

                byte version = file.ReadUInt8();

                if (version != (byte)VersionsEnum.CREDITFILE_VERSION &&
                    version != (byte)VersionsEnum.CREDITFILE_VERSION_29)
                {
                    file.Close();
                    return;
                }

                // everything is ok, lets see if the backup exist...
                string strBakFileName =
                    System.IO.Path.Combine(MuleApplication.Instance.Preference.GetMuleDirectory(Mule.Preference.DefaultDirectoryEnum.EMULE_CONFIGDIR),
                                           string.Format("{0}{1}", CLIENTS_MET_FILENAME, ".bak"));

                uint dwBakFileSize = 0;
                bool bCreateBackup = true;

                if (System.IO.File.Exists(strBakFileName))
                {
                    FileInfo fInfo = new FileInfo(strBakFileName);

                    dwBakFileSize = (uint)fInfo.Length;
                    if (dwBakFileSize > (uint)file.Length)
                    {
                        // the size of the backup was larger then the org. file, something is wrong here, don't overwrite old backup..
                        bCreateBackup = false;
                    }
                }
                //else: the backup doesn't exist, create it

                if (bCreateBackup)
                {
                    file.Close(); // close the file before copying

                    System.IO.File.Copy(strFileName, strBakFileName, true);

                    file = MpdObjectManager.CreateSafeBufferedFile(strFileName,
                                                                   System.IO.FileMode.Open,
                                                                   System.IO.FileAccess.Read,
                                                                   System.IO.FileShare.None);

                    file.Seek(1, SeekOrigin.Begin); //set filepointer behind file version byte
                }

                uint count = file.ReadUInt32();

                uint dwExpired = MpdUtilities.Time() - 12960000; // today - 150 day
                uint cDeleted  = 0;
                for (uint i = 0; i < count; i++)
                {
                    CreditStruct newcstruct = new CreditStruct();
                    if (version == (byte)VersionsEnum.CREDITFILE_VERSION_29)
                    {
                        ReadCreditStruct29a(file, newcstruct);
                    }
                    else
                    {
                        ReadCreditStruct(file, newcstruct);
                    }

                    if (newcstruct.nLastSeen < dwExpired)
                    {
                        cDeleted++;
                        continue;
                    }

                    ClientCredits newcredits =
                        MuleApplication.Instance.CoreObjectManager.CreateClientCredits(newcstruct);
                    clients_[new MapCKey(newcredits.Key)] = newcredits;
                }
                file.Close();
            }
            catch (Exception error)
            {
                MpdUtilities.DebugLogError(error);
                file.Close();
            }
        }