public MYPHandler(string filename, del_FileTableEventHandler eventHandler_FileTable, del_FileEventHandler eventHandler_Extraction, HashDictionary hashDic) { // Try to set ramCounter to the performance counter but if it fails set it to null to default getUsedRAM() to 0 try { ramCounter = new PerformanceCounter("Process", "Private Bytes", Process.GetCurrentProcess().ProcessName); } catch { ramCounter = null; } this.hashDictionary = hashDic; if (eventHandler_Extraction != null) { this.event_Extraction += eventHandler_Extraction; } if (eventHandler_FileTable != null) { this.event_FileTable += eventHandler_FileTable; } this.currentMypFileName = filename.Substring(filename.LastIndexOf('\\') + 1, filename.Length - filename.LastIndexOf('\\') - 1); this.currentMypFileName = this.currentMypFileName.Split('.')[0]; this.fullMypFileName = filename; this.mypPath = filename.LastIndexOf('\\') < 0 ? "" : filename.Substring(0, filename.LastIndexOf('\\')); this.pattern = "*"; this.unCompressedSize = 0L; this.numberOfFileNamesFound = 0L; this.totalNumberOfFiles = 0L; this.numberOfFilesFound = 0L; this.error_FileEntryNumber = 0L; this.error_ExtractionNumber = 0L; this.archiveStream = new FileStream(filename, FileMode.Open, FileAccess.Read); this.archiveStream.Seek(12L, SeekOrigin.Begin); byte[] numArray = new byte[8]; this.archiveStream.Read(numArray, 0, numArray.Length); this.tableStart = (long)FileInArchiveDescriptor.convertLittleEndianBufferToInt(numArray, 0L); this.tableStart += (long)FileInArchiveDescriptor.convertLittleEndianBufferToInt(numArray, 4L) << 32; this.GetFileNumber(); this.oSearcher = new ManagementObjectSearcher(this.oMs, this.oQuery); this.oReturnCollection = this.oSearcher.Get(); foreach (ManagementBaseObject oReturn in this.oReturnCollection) { this.totalMemory += Convert.ToDouble(oReturn["Capacity"]); } if (this.totalMemory > this.programMemory) { return; } this.programMemory = this.totalMemory / 2.0; }
/// <summary> /// Creates a new myp worker /// </summary> /// <param name="filename">the name of the file to work with</param> /// <param name="event_FileTable">method to treat events return when reading the file table</param> /// <param name="event_Extraction">method to treat events return when extracting files</param> /// <param name="hasher">the dictionnary</param> public MYPHandler(string filename , del_FileTableEventHandler eventHandler_FileTable , del_FileEventHandler eventHandler_Extraction , HashDictionary hashDic) { this.hashDictionary = hashDic; if (eventHandler_Extraction != null) { this.event_Extraction += eventHandler_Extraction; } if (eventHandler_FileTable != null) { this.event_FileTable += eventHandler_FileTable; } //parse the filename to get the path this.currentMypFileName = filename.Substring(filename.LastIndexOf('\\') + 1, filename.Length - filename.LastIndexOf('\\') - 1); this.currentMypFileName = currentMypFileName.Split('.')[0]; this.fullMypFileName = filename; if (filename.LastIndexOf('\\') >= 0) { this.mypPath = filename.Substring(0, filename.LastIndexOf('\\')); } else { this.mypPath = ""; } //Initialize some data pattern = "*"; unCompressedSize = 0; numberOfFileNamesFound = 0; totalNumberOfFiles = 0; numberOfFilesFound = 0; error_FileEntryNumber = 0; error_ExtractionNumber = 0; //open the archive file archiveStream = new FileStream(filename, FileMode.Open, FileAccess.Read); //read the position of the starting file table archiveStream.Seek(0x0C, SeekOrigin.Begin); byte[] buffer = new byte[8]; archiveStream.Read(buffer, 0, buffer.Length); tableStart = FileInArchiveDescriptor.convertLittleEndianBufferToInt(buffer, 0); tableStart += ((long)FileInArchiveDescriptor.convertLittleEndianBufferToInt(buffer, 4)) << 32; GetFileNumber(); }
/// <summary> /// Creates a new myp worker /// </summary> /// <param name="filename">the name of the file to work with</param> /// <param name="event_FileTable">method to treat events return when reading the file table</param> /// <param name="event_Extraction">method to treat events return when extracting files</param> /// <param name="hasher">the dictionnary</param> public MYPHandler(string filename , del_FileTableEventHandler eventHandler_FileTable , del_FileEventHandler eventHandler_Extraction , HashDictionary hashDic) { this.hashDictionary = hashDic; if (eventHandler_Extraction != null) { this.event_Extraction += eventHandler_Extraction; } if (eventHandler_FileTable != null) { this.event_FileTable += eventHandler_FileTable; } //parse the filename to get the path this.currentMypFileName = filename.Substring(filename.LastIndexOf('\\') + 1, filename.Length - filename.LastIndexOf('\\') - 1); this.currentMypFileName = currentMypFileName.Split('.')[0]; this.fullMypFileName = filename; if (filename.LastIndexOf('\\') >= 0) { this.mypPath = filename.Substring(0, filename.LastIndexOf('\\')); } else { this.mypPath = ""; } //Initialize some data pattern = "*"; unCompressedSize = 0; numberOfFileNamesFound = 0; totalNumberOfFiles = 0; numberOfFilesFound = 0; error_FileEntryNumber = 0; error_ExtractionNumber = 0; //open the archive file archiveStream = new FileStream(filename, FileMode.Open, FileAccess.Read); //read the position of the starting file table archiveStream.Seek(0x0C, SeekOrigin.Begin); byte[] buffer = new byte[8]; archiveStream.Read(buffer, 0, buffer.Length); tableStart = FileInArchiveDescriptor.convertLittleEndianBufferToInt(buffer, 0); tableStart += ((long)FileInArchiveDescriptor.convertLittleEndianBufferToInt(buffer, 4)) << 32; GetFileNumber(); //get the total memory available #region System Memory Management oSearcher = new ManagementObjectSearcher(oMs, oQuery); oReturnCollection = oSearcher.Get(); foreach (ManagementObject oReturn in oReturnCollection) { totalMemory += Convert.ToDouble(oReturn["Capacity"]); } if (totalMemory <= programMemory) { programMemory = totalMemory / 2; //Security } #endregion }
long unCompressedSize = 0; //uncompressed size #endregion Fields #region Constructors /// <summary> /// Creates a new myp worker /// </summary> /// <param name="filename">the name of the file to work with</param> /// <param name="event_FileTable">method to treat events return when reading the file table</param> /// <param name="event_Extraction">method to treat events return when extracting files</param> /// <param name="hasher">the dictionnary</param> public MYPHandler(string filename , del_FileTableEventHandler eventHandler_FileTable , del_FileEventHandler eventHandler_Extraction , HashDictionary hashDic) { this.hashDictionary = hashDic; if (eventHandler_Extraction != null) this.event_Extraction += eventHandler_Extraction; if (eventHandler_FileTable != null) this.event_FileTable += eventHandler_FileTable; //parse the filename to get the path this.currentMypFileName = filename.Substring(filename.LastIndexOf('\\') + 1, filename.Length - filename.LastIndexOf('\\') - 1); this.currentMypFileName = currentMypFileName.Split('.')[0]; this.fullMypFileName = filename; if (filename.LastIndexOf('\\') >= 0) { this.mypPath = filename.Substring(0, filename.LastIndexOf('\\')); } else { this.mypPath = ""; } //Initialize some data pattern = "*"; unCompressedSize = 0; numberOfFileNamesFound = 0; totalNumberOfFiles = 0; numberOfFilesFound = 0; error_FileEntryNumber = 0; error_ExtractionNumber = 0; //open the archive file archiveStream = new FileStream(filename, FileMode.Open, FileAccess.Read); //read the position of the starting file table archiveStream.Seek(0x0C, SeekOrigin.Begin); byte[] buffer = new byte[8]; archiveStream.Read(buffer, 0, buffer.Length); tableStart = FileInArchiveDescriptor.convertLittleEndianBufferToInt(buffer, 0); tableStart += ((long)FileInArchiveDescriptor.convertLittleEndianBufferToInt(buffer, 4)) << 32; GetFileNumber(); //get the total memory available #region System Memory Management oSearcher = new ManagementObjectSearcher(oMs, oQuery); oReturnCollection = oSearcher.Get(); foreach (ManagementObject oReturn in oReturnCollection) { totalMemory += Convert.ToDouble(oReturn["Capacity"]); } if (totalMemory <= programMemory) { programMemory = totalMemory / 2; //Security } #endregion }