Example #1
0
 public AudioNormalizerService(
     ISettingsManager settingsManager,
     IProcessWrapper processWrapper,
     IStorageWrapper storageWrapper)
 {
     _userSettings   = settingsManager.LoadSettings();
     _processWrapper = processWrapper;
     _storageWrapper = storageWrapper;
 }
Example #2
0
        public StorageController(ILogger <StorageController> logger, IStorageWrapper storage)
        {
            _logger  = logger;
            _storage = storage;
            var exists = _storage.BucketExists(BucketName);

            if (!exists)
            {
                _storage.CreateBucket(ProjectId, BucketName);
            }
        }
Example #3
0
 protected NormalDownloader(IStorageWrapper storageWrapper, int pieceNumber, List <SingleDownload> downloads)
 {
     this.storageWrapper  = storageWrapper;
     this.backLog         = 5;
     this.maxRatePeriod   = 50;
     this.piecesNumber    = pieceNumber;
     this.downloadMeasure = new Measure(15);
     this.measureFunction = null;
     this.downloads       = downloads;
     this.snubTime        = 60;
 }
Example #4
0
 public NormalDownloader(IStorageWrapper storageWrapper, IPiecePicker piecePicker, int backLog, double maxRatePeriod,
                         int piecesNumber, Measure downloadMeasure, double snubTime, DataDelegate measureFunction)
 {
     this.storageWrapper  = storageWrapper;
     this.piecePicker     = piecePicker;
     this.backLog         = backLog;
     this.maxRatePeriod   = maxRatePeriod;
     this.downloadMeasure = downloadMeasure;
     this.piecesNumber    = piecesNumber;
     this.snubTime        = snubTime;
     this.measureFunction = measureFunction;
     this.downloads       = new List <SingleDownload>();
 }
Example #5
0
        private static IList <byte[]> DecryptMsg(IStorageWrapper iw, string path, byte[] pass)
        {
            List <byte[]> msgList = new List <byte[]>();

            int num = 0;

            int[] pos = null;
            int[] len = null;
            using (IBaseStorageWrapper.FileObjects.FileObject fileObject = GetStorageFileObject(iw, path, "Index.msj"))
            {
                if (fileObject == null)
                {
                    return(msgList);
                }
                int fileLen = (int)fileObject.Length;
                num = fileLen / 4;
                pos = new int[num + 1];
                using (BinaryReader br = new BinaryReader(fileObject))
                {
                    for (int i = 0; i < num; ++i)
                    {
                        pos[i] = br.ReadInt32();
                    }
                }
            }
            using (IBaseStorageWrapper.FileObjects.FileObject fileObject = GetStorageFileObject(iw, path, "Data.msj"))
            {
                if (fileObject != null)
                {
                    int fileLen = (int)fileObject.Length;
                    len      = new int[num];
                    pos[num] = fileLen;
                    for (int i = 0; i < num; ++i)
                    {
                        len[i] = pos[i + 1] - pos[i];
                    }
                    using (BinaryReader br = new BinaryReader(fileObject))
                    {
                        for (int i = 0; i < num; ++i)
                        {
                            fileObject.Seek(pos[i], SeekOrigin.Begin);
                            byte[] data = br.ReadBytes(len[i]);
                            byte[] msg  = Decrypt(data, pass, 0);
                            msgList.Add(msg);
                        }
                    }
                }
            }
            return(msgList);
        }
Example #6
0
        public MainWindow(
            ISettingsManager settingsManager,
            IUnityContainer unityContainer,
            MainViewModel mainViewModel,
            IClipboardWrapper clipboardWrapper,
            IStorageWrapper storageWrapper)
        {
            InitializeComponent();

            _userSettings     = settingsManager.LoadSettings();
            _unityContainer   = unityContainer;
            _viewModel        = mainViewModel;
            _clipboardWrapper = clipboardWrapper;
            _storageWrapper   = storageWrapper;
            DataContext       = mainViewModel;
        }
Example #7
0
        public SettingsViewModel(
            ISettingsManager settingsManager,
            IDialogCoordinator dialogCoordinator,
            IProcessWrapper processWrapper,
            IThemeManagerWrapper themeManagerWrapper,
            IStorageWrapper storageWrapper)
        {
            _settingsManager     = settingsManager;
            _userSettings        = settingsManager.LoadSettings();
            _dialogCoordinator   = dialogCoordinator;
            _processWrapper      = processWrapper;
            _themeManagerWrapper = themeManagerWrapper;
            _storageWrapper      = storageWrapper;

            PropertyChanged += SettingsViewModel_PropertyChanged;
        }
Example #8
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="connection">连接类</param>
        /// <param name="choker">阻塞类</param>
        /// <param name="storageWrapper">磁盘封装类</param>
        /// <param name="maxSliceLength">最大子片断长度</param>
        /// <param name="maxRatePeriod">最大速率更新时间</param>
        /// <param name="fudge"></param>
        public Upload(IConnection connection, IChoker choker, IStorageWrapper storageWrapper, int maxSliceLength,
                      double maxRatePeriod, double fudge)
        {
            this.connection     = connection;
            this.choker         = choker;
            this.storageWrapper = storageWrapper;
            this.maxSliceLength = maxSliceLength;
            this.maxRatePeriod  = maxRatePeriod;
            this.choked         = true;
            this.interested     = false;
            this.buffer         = new LinkedList <ActiveRequest>();
            this.measure        = new Measure(maxRatePeriod, fudge);

            //如果已经获取的某些片断,则向所有节点发送BitField信息
            if (storageWrapper.DoIHaveAnything())
            {
                connection.SendBitfield(storageWrapper.GetHaveList());
            }
        }
Example #9
0
        public void Open(string QQID, string QQPath)
        {
            if (QQPath == null)
            {
                using (Microsoft.Win32.RegistryKey reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Tencent\QQ"))
                {
                    QQPath = reg.GetValue("Install") as string;
                }
                if (QQPath == null)
                {
                    return;
                }
            }

            for (int i = 0; i < m_MsgList.Length; ++i)
            {
                m_MsgList[i] = new List <string>();
            }
            m_Storage  = null;
            m_Password = null;

            m_Storage  = new IStorageWrapper(QQPath + QQID + @"\MsgEx.db");
            m_Password = QQMsgMgr.GetGlobalPass(m_Storage, QQID);

            if (m_Password == null)
            {
                m_Storage = null;
            }

            foreach (IBaseStorageWrapper.FileObjects.FileObject fileObject in m_Storage.foCollection)
            {
                if (fileObject.FileType == 1)
                {
                    for (int i = 0; i < m_MsgList.Length; ++i)
                    {
                        if (fileObject.FilePath == s_MsgName[i])
                        {
                            m_MsgList[i].Add(fileObject.FileName);
                        }
                    }
                }
            }
        }
Example #10
0
        public Repository()
        {
            SmtpWrapper = new DefaultSmtpWrapper();
            EmailWrapper = new DefaultEmailWrapper();
            InvoiceWrapper = new DefaultInvoiceWrapper();
            ClientsWrapper = new DefaultClientsWrappers();
            CompanyInformationWrapper = new DefaultCompanyInformationWrapper();
            TermsWrapper = new DefaultTermsWrapper();
            StorageWrapper = new DefaultStorageWrapper();

            EnsureConfigsExist();

            SmtpWrapper.Load();
            EmailWrapper.Load();
            InvoiceWrapper.Load();
            ClientsWrapper.Load();
            CompanyInformationWrapper.Load();
            TermsWrapper.Load();
            StorageWrapper.Load();
        }
Example #11
0
        public void Open(string QQID, string QQPath)
        {
            if (QQPath == null)
            {
                using (Microsoft.Win32.RegistryKey reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Tencent\QQ"))
                {
                    QQPath = reg.GetValue("Install") as string;
                }
                if (QQPath == null) return;
            }

            for (int i = 0; i < m_MsgList.Length; ++i)
            {
                m_MsgList[i] = new List<string>();
            }
            m_Storage = null;
            m_Password = null;

            m_Storage = new IStorageWrapper(QQPath + QQID + @"\MsgEx.db");
            m_Password = QQMsgMgr.GetGlobalPass(m_Storage, QQID);

            if (m_Password == null) m_Storage = null;

            foreach (IBaseStorageWrapper.FileObjects.FileObject fileObject in m_Storage.foCollection)
            {
                if (fileObject.FileType == 1)
                {
                    for (int i = 0; i < m_MsgList.Length; ++i)
                    {
                        if (fileObject.FilePath == s_MsgName[i])
                        {
                            m_MsgList[i].Add(fileObject.FileName);
                        }
                    }
                }
            }
        }
Example #12
0
 private static IBaseStorageWrapper.FileObjects.FileObject GetStorageFileObject(IStorageWrapper iw, string path, string fileName)
 {
     foreach (IBaseStorageWrapper.FileObjects.FileObject fileObject in iw.foCollection)
     {
         if (fileObject.CanRead)
         {
             if (fileObject.FilePath == path && fileObject.FileName == fileName)
             {
                 return(fileObject);
             }
         }
     }
     return(null);
 }
 public DummyNormalDownloader(IStorageWrapper storageWrapper, int pieceNumber, List <SingleDownload> downloads)
     : base(storageWrapper, pieceNumber, downloads)
 {
 }
Example #14
0
        private static byte[] GetGlobalPass(IStorageWrapper iw, string QQID)
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] dataID = new byte[QQID.Length];
            for (int i = 0; i < QQID.Length; ++i) dataID[i] = (byte)(QQID[i]);
            byte[] hashID = md5.ComputeHash(dataID);
            IBaseStorageWrapper.FileObjects.FileObject fileObject = GetStorageFileObject(iw, "Matrix", "Matrix.db");
            if (fileObject != null)
            {
                using (BinaryReader br = new BinaryReader(fileObject))
                {
                    byte[] data = br.ReadBytes((int)fileObject.Length);
                    long len = data.Length;
                    if (len < 6 || data[0] != 0x51 || data[1] != 0x44) return null;
                    if (len >= 32768) return null;

                    bool bl = false;
                    int i = 6;
                    while (i < len)
                    {
                        bl = false;
                        byte type = data[i++];
                        if (i + 2 > len) break;
                        int len1 = data[i] + data[i + 1] * 256;
                        byte xor1 = (byte)(data[i] ^ data[i + 1]);
                        i += 2;
                        if (i + len1 > len) break;
                        for (int j = 0; j < len1; ++j) data[i + j] = (byte)(~(data[i + j] ^ xor1));
                        if (len1 == 3 && data[i] == 0x43 && data[i + 1] == 0x52 && data[i + 2] == 0x4B)
                        {
                            bl = true;
                        }
                        i += len1;

                        if (type > 7) break;
                        if (i + 4 > len) break;
                        int len2 = data[i] + data[i + 1] * 256 + data[i + 2] * 256 * 256 + data[i + 3] * 256 * 256 * 256;
                        byte xor2 = (byte)(data[i] ^ data[i + 1]);
                        i += 4;
                        if (i + len2 > len) break;
                        if (type == 6 || type == 7)
                        {
                            for (int j = 0; j < len2; ++j) data[i + j] = (byte)(~(data[i + j] ^ xor2));
                        }
                        if (bl && len2 == 0x20)
                        {
                            byte[] dataT = new byte[len2];
                            for (int j = 0; j < len2; ++j) dataT[j] = data[i + j];
                            return Decrypt(dataT, hashID, 0);
                        }
                        i += len2;
                    }
                    if (i != len) return null;
                }
            }
            return null;
        }
Example #15
0
        private static IList<byte[]> DecryptMsg(IStorageWrapper iw, string path, byte[] pass)
        {
            List<byte[]> msgList = new List<byte[]>();

            int num = 0;
            int[] pos = null;
            int[] len = null;
            using (IBaseStorageWrapper.FileObjects.FileObject fileObject = GetStorageFileObject(iw, path, "Index.msj"))
            {
                if (fileObject == null) return msgList;
                int fileLen = (int)fileObject.Length;
                num = fileLen / 4;
                pos = new int[num + 1];
                using (BinaryReader br = new BinaryReader(fileObject))
                {
                    for (int i = 0; i < num; ++i)
                    {
                        pos[i] = br.ReadInt32();
                    }
                }
            }
            using (IBaseStorageWrapper.FileObjects.FileObject fileObject = GetStorageFileObject(iw, path, "Data.msj"))
            {
                if (fileObject != null)
                {
                    int fileLen = (int)fileObject.Length;
                    len = new int[num];
                    pos[num] = fileLen;
                    for (int i = 0; i < num; ++i)
                    {
                        len[i] = pos[i + 1] - pos[i];
                    }
                    using (BinaryReader br = new BinaryReader(fileObject))
                    {
                        for (int i = 0; i < num; ++i)
                        {
                            fileObject.Seek(pos[i], SeekOrigin.Begin);
                            byte[] data = br.ReadBytes(len[i]);
                            byte[] msg = Decrypt(data, pass, 0);
                            msgList.Add(msg);
                        }
                    }
                }
            }
            return msgList;
        }
Example #16
0
 private static IBaseStorageWrapper.FileObjects.FileObject GetStorageFileObject(IStorageWrapper iw, string path, string fileName)
 {
     foreach (IBaseStorageWrapper.FileObjects.FileObject fileObject in iw.foCollection)
     {
         if (fileObject.CanRead)
         {
             if (fileObject.FilePath == path && fileObject.FileName == fileName) return fileObject;
         }
     }
     return null;
 }
Example #17
0
        private static byte[] GetGlobalPass(IStorageWrapper iw, string QQID)
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] dataID = new byte[QQID.Length];
            for (int i = 0; i < QQID.Length; ++i)
            {
                dataID[i] = (byte)(QQID[i]);
            }
            byte[] hashID = md5.ComputeHash(dataID);
            IBaseStorageWrapper.FileObjects.FileObject fileObject = GetStorageFileObject(iw, "Matrix", "Matrix.db");
            if (fileObject != null)
            {
                using (BinaryReader br = new BinaryReader(fileObject))
                {
                    byte[] data = br.ReadBytes((int)fileObject.Length);
                    long   len  = data.Length;
                    if (len < 6 || data[0] != 0x51 || data[1] != 0x44)
                    {
                        return(null);
                    }
                    if (len >= 32768)
                    {
                        return(null);
                    }

                    bool bl = false;
                    int  i  = 6;
                    while (i < len)
                    {
                        bl = false;
                        byte type = data[i++];
                        if (i + 2 > len)
                        {
                            break;
                        }
                        int  len1 = data[i] + data[i + 1] * 256;
                        byte xor1 = (byte)(data[i] ^ data[i + 1]);
                        i += 2;
                        if (i + len1 > len)
                        {
                            break;
                        }
                        for (int j = 0; j < len1; ++j)
                        {
                            data[i + j] = (byte)(~(data[i + j] ^ xor1));
                        }
                        if (len1 == 3 && data[i] == 0x43 && data[i + 1] == 0x52 && data[i + 2] == 0x4B)
                        {
                            bl = true;
                        }
                        i += len1;

                        if (type > 7)
                        {
                            break;
                        }
                        if (i + 4 > len)
                        {
                            break;
                        }
                        int  len2 = data[i] + data[i + 1] * 256 + data[i + 2] * 256 * 256 + data[i + 3] * 256 * 256 * 256;
                        byte xor2 = (byte)(data[i] ^ data[i + 1]);
                        i += 4;
                        if (i + len2 > len)
                        {
                            break;
                        }
                        if (type == 6 || type == 7)
                        {
                            for (int j = 0; j < len2; ++j)
                            {
                                data[i + j] = (byte)(~(data[i + j] ^ xor2));
                            }
                        }
                        if (bl && len2 == 0x20)
                        {
                            byte[] dataT = new byte[len2];
                            for (int j = 0; j < len2; ++j)
                            {
                                dataT[j] = data[i + j];
                            }
                            return(Decrypt(dataT, hashID, 0));
                        }
                        i += len2;
                    }
                    if (i != len)
                    {
                        return(null);
                    }
                }
            }
            return(null);
        }
Example #18
0
        public override bool GetPiece(int index, int begin, byte[] piece)
        {
            ActiveRequest comeInRequest = new ActiveRequest(index, begin, piece.Length);

            if (downloader.Requests.Contains(comeInRequest))
            {
                downloader.Requests.Remove(comeInRequest);
            }

            else
            {
                return(false);
            }

            last = DateTime.Now;
            measure.UpdateRate(piece.Length);
            downloader.DownloadMeasure.UpdateRate(piece.Length);
            if (downloader.MeasureFunction != null)
            {
                downloader.MeasureFunction(piece.Length);
            }
            IStorageWrapper storageWrapper = downloader.StorageWrapper;

            storageWrapper.PieceCameIn(index, begin, piece);
            if (storageWrapper.DoIHaveRequests(index))
            {
                List <InactiveRequest> inactiveRequests = new List <InactiveRequest>();
                InactiveRequest        newRequest;
                while (storageWrapper.DoIHaveRequests(index))
                {
                    newRequest = storageWrapper.NewRequest(index);
                    inactiveRequests.Add(newRequest);
                    downloader.Requests.Add(new ActiveRequest(index, newRequest.Begin, newRequest.Length));
                }

                foreach (EndGameSingleDownload download in downloader.Downloads)
                {
                    if (!download.choked && download.have[index])
                    {
                        List <InactiveRequest> requests = new List <InactiveRequest>();

                        while (inactiveRequests.Count > 0)
                        {
                            int k = ran.Next(inactiveRequests.Count);
                            requests.Add(inactiveRequests[k]);
                            inactiveRequests.RemoveAt(k);
                        }

                        inactiveRequests = requests;

                        foreach (InactiveRequest request in inactiveRequests)
                        {
                            if (request.Begin != begin || download == this)
                            {
                                download.SendRequest(index, request.Begin, request.Length);
                            }
                        }
                    }
                }
                return(false);
            }

            foreach (EndGameSingleDownload download in downloader.Downloads)
            {
                if (download.have[index] && download != this && !download.choked)
                {
                    download.connection.SendCancel(index, begin, piece.Length);
                }
            }

            foreach (ActiveRequest activeRequest in downloader.Requests)
            {
                if (activeRequest.Index == index)
                {
                    return(true);
                }
            }

            foreach (EndGameSingleDownload download in downloader.Downloads)
            {
                if (download.have[index])
                {
                    bool bFound = false;
                    foreach (ActiveRequest activeRequest in downloader.Requests)
                    {
                        if (download.have[activeRequest.Index])
                        {
                            bFound = true;
                            break;
                        }
                    }
                    if (!bFound)
                    {
                        download.interested = false;
                        download.connection.SendNotInterested();
                    }
                }
            }

            if (downloader.Requests.Count == 0)
            {
                SingleDownload[] activeDownloads = downloader.Downloads.ToArray();
                foreach (EndGameSingleDownload download in activeDownloads)
                {
                    if (download.unhave == 0)
                    {
                        download.connection.Close();
                    }
                }
            }
            return(true);
        }