예제 #1
0
        void SplitFile()
        {
            long LeafsInPart = LeafCount / ThreadCount;

            // check if file is bigger then 1 MB or don't use threads
            if (FilePtr.Length > 1024 * 1024)
            {
                for (int i = 0; i < ThreadCount; i++)
                {
                    FileParts[i] = new FileBlock(LeafsInPart * LeafSize * i,
                                                 LeafsInPart * LeafSize * (i + 1));
                }
            }

            FileParts[ThreadCount - 1].End = FilePtr.Length;
        }
예제 #2
0
        void StartThreads()
        {
            for (int i = 0; i < ThreadCount; i++)
            {
                ThreadsList[i]              = new Thread(new ThreadStart(ProcessLeafs));
                ThreadsList[i].Priority     = threadPriority;
                ThreadsList[i].IsBackground = true;
                ThreadsList[i].Name         = i.ToString();
#if !COMPACT_FRAMEWORK
                ThreadsList[i].Start();
#else
                ThreadsList[i].Start(true);
#endif
            }

            bool ThreadsAreWorking = false;

            do
            {
                // FLOW84 : START
                //Thread.Sleep(1000);
                Thread.Sleep(100);
                // FLOW84 : END
                ThreadsAreWorking = false;

                for (int i = 0; i < ThreadCount; i++)
#if !COMPACT_FRAMEWORK
                { if (ThreadsList[i].IsAlive)
#else
                { if (ThreadsList[i].IsAlive())
#endif
                  { ThreadsAreWorking = true; } }
            } while (ThreadsAreWorking);
        }

        void StopThreads()
        {
            for (int i = 0; i < ThreadCount; i++)
#if !COMPACT_FRAMEWORK
            { if (ThreadsList[i] != null && ThreadsList[i].IsAlive)
#else
                if (ThreadsList[i] != null && ThreadsList[i].IsAlive())
#endif
              { ThreadsList[i].Abort(); } }
        }

        void ProcessLeafs()
        {
            try
            {
                FileStream ThreadFilePtr   = new FileStream(Filename, FileMode.Open, FileAccess.Read);
                FileBlock  ThreadFileBlock = FileParts[System.Convert.ToInt16(Thread.CurrentThread.Name)];
                Tiger      TG = new Tiger();
                byte[]     DataBlock;
                byte[]     Data = new byte[LeafSize + 1];
                long       LeafIndex;
                int        BlockLeafs;
                int        i;

                ThreadFilePtr.Position = ThreadFileBlock.Start;

                while (ThreadFilePtr.Position < ThreadFileBlock.End)
                {
                    LeafIndex = (long)ThreadFilePtr.Position / 1024;

                    if (ThreadFileBlock.End - ThreadFilePtr.Position < DataBlockSize)
                    {
                        DataBlock = new byte[ThreadFileBlock.End - ThreadFilePtr.Position];
                    }
                    else
                    {
                        DataBlock = new byte[DataBlockSize];
                    }

                    ThreadFilePtr.Read(DataBlock, 0, DataBlock.Length); //read block

                    BlockLeafs = DataBlock.Length / 1024;

                    for (i = 0; i < BlockLeafs; i++)
                    {
                        Buffer.BlockCopy(DataBlock, i * LeafSize, Data, 1, LeafSize);

                        TG.Initialize();
                        TTH[0][LeafIndex++] = TG.ComputeHash(Data);
                    }

                    if (i * LeafSize < DataBlock.Length)
                    {
                        Data    = new byte[DataBlock.Length - BlockLeafs * LeafSize + 1];
                        Data[0] = LeafHash;

                        Buffer.BlockCopy(DataBlock, BlockLeafs * LeafSize, Data, 1, (Data.Length - 1));

                        TG.Initialize();
                        TTH[0][LeafIndex++] = TG.ComputeHash(Data);

                        Data    = new byte[LeafSize + 1];
                        Data[0] = LeafHash;
                    }
                }

                DataBlock = null;
                Data      = null;
            }
            catch (ThreadAbortException) { }
            finally
            {
                // We remove the object to indicate that we are finished
#if COMPACT_FRAMEWORK
                Thread.CurrentThread.GetData();
#endif
            }
        }

        void CompressTree()
        {
            int InternalLeafCount;
            int Level = 0, i, LeafIndex;

            while (Level + 1 < LevelCount)
            {
                LeafIndex         = 0;
                InternalLeafCount = (LeafCount / 2) + (LeafCount % 2);
                TTH[Level + 1]    = new byte[InternalLeafCount][];

                for (i = 1; i < LeafCount; i += 2)
                    ProcessInternalLeaf(Level + 1, LeafIndex++, TTH[Level][i - 1], TTH[Level][i]); }

                if (LeafIndex < InternalLeafCount)
                {
                    TTH[Level + 1][LeafIndex] = TTH[Level][LeafCount - 1];
                }

                Level++;
                LeafCount = InternalLeafCount;
            }
        }
예제 #3
0
        void SplitFile()
        {
            long LeafsInPart = LeafCount / ThreadCount;

            // check if file is bigger then 1 MB or don't use threads
            if (FilePtr.Length > 1024 * 1024)
                for (int i = 0; i < ThreadCount; i++)
                    FileParts[i] = new FileBlock(LeafsInPart * LeafSize * i,
                                                 LeafsInPart * LeafSize * (i + 1));

            FileParts[ThreadCount - 1].End = FilePtr.Length;
        }