Exemplo n.º 1
0
        private void verifyAndResetThreads(int threads)
        {
            for (int i = 0; i < MAX_UNPACK_THREADS; i++)
            {
                if (unpackThreads[i] == null)
                {
                    if (i <= threads)
                    {
                        unpackThreads[i] = new UnpackThreadInfo();
                    }
                    else
                    {
                        continue;
                    }
                }

                unpackThreads[i].options            = default(BigFileUnpackOptions);
                unpackThreads[i].bigFile            = null;
                unpackThreads[i].fileMapping        = null;
                unpackThreads[i].startIndex         = 0;
                unpackThreads[i].count              = 0;
                unpackThreads[i].threadID           = i;
                unpackThreads[i].progress           = 0;
                unpackThreads[i].OnWorkDoneCallback = internal_OnThreadFinished;
            }
        }
Exemplo n.º 2
0
 private void internal_OnThreadFinished(UnpackThreadInfo info)
 {
     if (!IsUnpacking)
     {
         log.Info("All unpacking threads finished their work!");
         log.Info(" > Time taken: ");
         log.Info(formatted_diag_msg);
         for (int i = 0; i < MAX_UNPACK_THREADS; i++)
         {
             if (unpackThreads[i] != null)
             {
                 string str = string.Format("  {0,6}        {1,4}s  {2,6}   {3,6}", i, unpackThreads[i].stopwatch.ElapsedMilliseconds / 1000, unpackThreads[i].startIndex, unpackThreads[i].count);
                 log.Info(str);
             }
         }
     }
 }
Exemplo n.º 3
0
        private void internal_UnpackFiles(object state)
        {
            UnpackThreadInfo info = state as UnpackThreadInfo;

            info.isUnpacking = true;
            info.stopwatch.Reset();
            info.stopwatch.Start();

            //int segmentDataOffset = info.bigFile.FileUtil.CalculateDataOffset(ref info.bigFile.SegmentHeader, ref info.bigFile.FileHeader);
            //byte[] buffer = info.buffers[4];
            BigFileFile[] files = new BigFileFile[info.count];
            Array.Copy(info.bigFile.FileMap.FilesList, info.startIndex, files, 0, info.count);

            IEnumerator <int[]> headers = info.bigFile.FileReader.ReadAllHeaders(files, info.buffers, info.options.Flags).GetEnumerator();
            IEnumerator <int>   data    = info.bigFile.FileReader.ReadAllData(files, info.buffers, info.options.Flags).GetEnumerator();

            for (int i = 0; i < files.Length; i++)
            {
                info.progress = i;

                headers.MoveNext();
                data.MoveNext();

                log.Info("Unpacking file {0}", files[i].Name);

                //********************************************//
                //DON'T FORGET THE ******* UNPACK SUBDIRECTORY//
                //********************************************//
                string dataFileName = info.options.Directory.FullName + "\\"
                                      + BigFileConst.UNPACK_DIR + "\\"
                                      + info.fileMapping[files[i].FileInfo.Key].FileName;

                string headerFileName = dataFileName + BigFileConst.UNPACKED_HEADER_FILE_EXTENSION;

                using (FileStream dataFS = File.Create(dataFileName))
                    using (FileStream headerFS = File.Create(headerFileName))
                    {
                        int   size   = data.Current;
                        int[] header = headers.Current;
                        if (size != -1)
                        {
                            int headerCount = header.Length;
                            dataFS.Write(info.buffers[size], 0, size);

                            headerFS.Write(headerCount.ToByteArray(info.buffers[4]), 0, 4);
                            for (int j = 0; j < headerCount; j++)
                            {
                                headerFS.Write(header[j].ToByteArray(info.buffers[4]), 0, 4);
                                if (header[j] == 0)
                                {
                                    log.Error("WTF");
                                }
                            }
                        }
                        else
                        {
                            log.Error("Can't unpack file {0} because size is -1", files[i].Name);
                        }
                    }
            }

            //int index = -1;
            //foreach (int size in info.bigFile.FileReader.ReadAllRaw(files, info.buffers, info.options.Flags))
            //{
            //    index++;

            //    info.progress = index;

            //    log.Info("Unpacking file {0}", files[index].Name);

            //    //********************************************//
            //    //DON'T FORGET THE ******* UNPACK SUBDIRECTORY//
            //    //********************************************//
            //    string dataFileName = info.options.Directory.FullName + "\\"
            //                        + BigFileConst.UNPACK_DIR + "\\"
            //                        + info.fileMapping[files[index].FileInfo.Key].FileName;

            //    string headerFileName = dataFileName + BigFileConst.UNPACKED_HEADER_FILE_EXTENSION;

            //    IEnumerable<int> p = info.bigFile.FileReader.ReadAllData(files, info.buffers, info.options.Flags);

            //    using (FileStream dataFS = File.Create(dataFileName))
            //    using (FileStream headerFS = File.Create(headerFileName))
            //    {
            //        if (size != -1)
            //        {
            //            int headerCount = BitConverter.ToInt32(info.buffers[size], 0);
            //            int dataOffset = headerCount * 4 + 4;

            //            if (dataOffset > size)
            //            {
            //                log.Error("Hmmm... something's wrong here");
            //                headerFS.Write(info.buffers[size], 0, size);
            //            }
            //            else
            //            {
            //                dataFS.Write(info.buffers[size], dataOffset, size - dataOffset);
            //                headerFS.Write(info.buffers[size], 0, dataOffset);
            //            }
            //        }
            //        else
            //        {
            //            log.Error("Can't unpack file {0} because size is -1", files[index].Name);
            //        }
            //    }
            //}

            log.Info("Unpack thread (ID:" + info.threadID + ") finished work!");
            info.isUnpacking = false;
            info.stopwatch.Stop();

            info.OnWorkDoneCallback.Invoke(info);
        }