diff --git a/commandline.cpp b/commandline.cpp index ab747d6..0988cbf 100644 --- a/commandline.cpp +++ b/commandline.cpp @@ -20,6 +20,9 @@ #include "par2cmdline.h" #ifdef _MSC_VER +// quick fix for POSIX names +#define stricmp _stricmp + #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; diff --git a/diskfile.cpp b/diskfile.cpp index c3356fa..6e20300 100644 --- a/diskfile.cpp +++ b/diskfile.cpp @@ -20,6 +20,9 @@ #include "par2cmdline.h" #ifdef _MSC_VER +// quick fix for posix names +#define unlink _unlink + #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; @@ -345,6 +348,13 @@ list* DiskFile::FindFiles(string path, string wildcard) return matches; } +bool DiskFile::FileExists(string filename) +{ + struct stat st; + return ((0 == stat(filename.c_str(), &st)) && + (st.st_mode & S_IFREG) ); +} + u64 DiskFile::GetFileSize(string filename) { struct _stati64 st; @@ -707,6 +717,39 @@ list* DiskFile::FindFiles(string path, string wildcard) return matches; } + +bool DiskFile::FileExists(string filename) +{ + struct stat st; + return ((0 == stat(filename.c_str(), &st)) && + (st.st_mode & (S_IFREG|S_IFBLK)) ); +} + +u64 DiskFile::GetFileSize(string filename) +{ + struct stat st; + if (0 == stat(filename.c_str(), &st)) + { + if (st.st_mode & S_IFREG) + { + return st.st_size; + } + else if (st.st_mode & S_IFBLK) + { + FILE *fp; + u64 size = 0; + if ( NULL != (fp = fopen(filename.c_str(), "rb")) ) + { + ioctl(fileno(fp), BLKGETSIZE64, &size); + fclose(fp); + } + return size; + } + } + + return 0; +} + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// #endif @@ -814,38 +857,6 @@ void DiskFile::SplitFilename(string filename, string &path, string &name) } } -bool DiskFile::FileExists(string filename) -{ - struct stat st; - return ((0 == stat(filename.c_str(), &st)) && - (st.st_mode & (S_IFREG|S_IFBLK)) ); -} - -u64 DiskFile::GetFileSize(string filename) -{ - struct stat st; - if (0 == stat(filename.c_str(), &st)) - { - if (st.st_mode & S_IFREG) - { - return st.st_size; - } - else if (st.st_mode & S_IFBLK) - { - FILE *fp; - u64 size = 0; - if ( NULL != (fp = fopen(filename.c_str(), "rb")) ) - { - ioctl(fileno(fp), BLKGETSIZE64, &size); - fclose(fp); - } - return size; - } - } - - return 0; -} - // Take a filename from a PAR2 file and replace any characters diff --git a/par2cmdline.sln b/par2cmdline.sln index 070d62a..62aa980 100644 --- a/par2cmdline.sln +++ b/par2cmdline.sln @@ -1,21 +1,19 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "par2cmdline", "par2cmdline.vcproj", "{D0A94F83-495E-4FB2-AC33-9A3EC2CC263B}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "par2cmdline", "par2cmdline.vcxproj", "{D0A94F83-495E-4FB2-AC33-9A3EC2CC263B}" EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {D0A94F83-495E-4FB2-AC33-9A3EC2CC263B}.Debug.ActiveCfg = Debug|Win32 - {D0A94F83-495E-4FB2-AC33-9A3EC2CC263B}.Debug.Build.0 = Debug|Win32 - {D0A94F83-495E-4FB2-AC33-9A3EC2CC263B}.Release.ActiveCfg = Release|Win32 - {D0A94F83-495E-4FB2-AC33-9A3EC2CC263B}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D0A94F83-495E-4FB2-AC33-9A3EC2CC263B}.Debug|Win32.ActiveCfg = Debug|Win32 + {D0A94F83-495E-4FB2-AC33-9A3EC2CC263B}.Debug|Win32.Build.0 = Debug|Win32 + {D0A94F83-495E-4FB2-AC33-9A3EC2CC263B}.Release|Win32.ActiveCfg = Release|Win32 + {D0A94F83-495E-4FB2-AC33-9A3EC2CC263B}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal diff --git a/par2cmdline.vcxproj b/par2cmdline.vcxproj new file mode 100644 index 0000000..541b897 --- /dev/null +++ b/par2cmdline.vcxproj @@ -0,0 +1,189 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {D0A94F83-495E-4FB2-AC33-9A3EC2CC263B} + Win32Proj + + + + Application + MultiByte + + + Application + MultiByte + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.40219.1 + Debug\ + Debug\ + true + Release\ + Release\ + false + AllRules.ruleset + + + AllRules.ruleset + + + par2 + par2 + + + + Disabled + WIN32;_DEBUG;_CONSOLE;PACKAGE="par2cmdline";VERSION="0.4";%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebug + + + par2cmdline.h + Level3 + EditAndContinue + + + $(OutDir)par2.exe + true + $(OutDir)par2cmdline.pdb + Console + MachineX86 + + + + + MaxSpeed + AnySuitable + Speed + true + WIN32;NDEBUG;_CONSOLE;PACKAGE="par2cmdline";VERSION="0.4";%(PreprocessorDefinitions) + true + MultiThreaded + true + + + par2cmdline.h + Level3 + ProgramDatabase + + + $(OutDir)par2.exe + true + Console + true + true + MachineX86 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/par2creator.cpp b/par2creator.cpp index b746593..a09a870 100644 --- a/par2creator.cpp +++ b/par2creator.cpp @@ -19,8 +19,10 @@ #include "par2cmdline.h" #include +#ifndef WIN32 #include #include +#endif #ifdef _MSC_VER #ifdef _DEBUG @@ -76,6 +78,9 @@ Par2Creator::Par2Creator(void) // Some stuff for the multi-thread optimization pthread_mutex_init (&progressMutex, NULL); // Go and find number of CPU's in this machine +#ifdef WIN32 + numCPUs = pthread_num_processors_np(); +#else // !WIN32 #ifdef CTL_HW int lName [2] = { CTL_HW, HW_NCPU }; size_t lLen = sizeof (numCPUs); @@ -88,7 +93,8 @@ Par2Creator::Par2Creator(void) numCPUs = sysconf( _SC_NPROCESSORS_ONLN ); #else numCPUs = 1; -#endif +#endif // CTL_HW +#endif // !WIN32 } Par2Creator::~Par2Creator(void) diff --git a/par2repairer.cpp b/par2repairer.cpp index e6232d5..c35ff19 100755 --- a/par2repairer.cpp +++ b/par2repairer.cpp @@ -19,12 +19,18 @@ #include "par2cmdline.h" #include + +#ifndef WIN32 #include #include #include #include +#endif #ifdef _MSC_VER +// quick fix for posix names +#define stricmp _stricmp + #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; @@ -122,6 +128,9 @@ Par2Repairer::Par2Repairer(void) pthread_mutex_init (&progressMutex, NULL); pthread_mutex_init (&fileIteratorMutex, NULL); // Go and find out the number of CPU's +#ifdef WIN32 + numCPUs = pthread_num_processors_np(); +#else // !WIN32 #ifdef CTL_HW int lName [2] = { CTL_HW, HW_NCPU }; size_t lLen = sizeof (numCPUs); @@ -134,7 +143,8 @@ Par2Repairer::Par2Repairer(void) numCPUs = sysconf( _SC_NPROCESSORS_ONLN ); #else numCPUs = 1; -#endif +#endif // CTL_HW +#endif // !WIN32 } Par2Repairer::~Par2Repairer(void) @@ -171,9 +181,6 @@ Result Par2Repairer::Process(const CommandLine &commandline, bool dorepair) // What noiselevel are we using noiselevel = commandline.GetNoiseLevel(); - struct rlimit rlp; // Need this to allow for enough file handles - int lFileHandlesNeeded; - // Get filesnames from the command line string par2filename = commandline.GetParFilename(); const list &extrafiles = commandline.GetExtraFiles(); @@ -201,6 +208,10 @@ Result Par2Repairer::Process(const CommandLine &commandline, bool dorepair) if (!CheckPacketConsistency()) return eInsufficientCriticalData; +// looks like Windows either has no explicit file handle limit, or you shouldn't adjust it +#ifndef WIN32 + struct rlimit rlp; // Need this to allow for enough file handles + int lFileHandlesNeeded; // It appears that during repair the program opens all files simultaneously. // Suppose the maximum number of file handles is 256, this would mean you can have // about 250 files in a par set. This can be too small, so adjust if necessary. */ @@ -215,6 +226,7 @@ Result Par2Repairer::Process(const CommandLine &commandline, bool dorepair) return eLogicError; cout << "Increased file limit to " << lFileHandlesNeeded << endl; } +#endif // Use the information in the main packet to get the source files // into the correct order and determine their filenames diff --git a/verificationhashtable.h b/verificationhashtable.h index d239732..3b8b4d8 100644 --- a/verificationhashtable.h +++ b/verificationhashtable.h @@ -49,9 +49,30 @@ class VerificationHashEntry ~VerificationHashEntry(void) { + // problem: may cause stack overflow due to recursion. + // this happens if there are a lot of nodes with the same crc & hash + // possible solution: use a loop + + // I still don't like the idea of two recursions (left and right), + // AFAIK only one can be optimized by the compiler + + // delete all nodes with same crc and hash + VerificationHashEntry *nextSame = same; + while(0 != nextSame) + { + VerificationHashEntry *const currSame = nextSame; + nextSame = currSame->same; + + // prevent currSame from recursive delete + currSame->same = 0; + currSame->left = 0; + currSame->right = 0; + + delete currSame; + } + delete left; delete right; - delete same; } // Insert the current object is a child of the specified parent