//--------------------------------------------------------------------------- size_t MediaInfo_Internal::Open(const String &File_Name_) { //Test existence of the file File_Name=File_Name_; if (!File::Exists(File_Name)) return 0; //Get the Extension Ztring Extension=FileName::Extension_Get(File_Name); Extension.MakeLowerCase(); //Search the theorical format from extension InfoMap &FormatList=MediaInfoLib::Config.Format_Get(); InfoMap::iterator Format=FormatList.begin(); while (Format!=FormatList.end()) { const Ztring &Extensions=FormatList.Get(Format->first, InfoFormat_Extensions); if (Extensions.find(Extension)!=Error) { if(Extension.size()==Extensions.size()) break; //Only one extenion in the list if(Extensions.find(Extension+_T(" "))!=Error || Extensions.find(_T(" ")+Extension)!=Error) break; } Format++; } if (Format!=FormatList.end()) { const Ztring &Parser=Format->second(InfoFormat_Parser); SelectFromExtension(Parser); } CriticalSectionLocker CSL(CS); //Test the theorical format if (Format_Test()>0) return 1; //Extension is not the good one, parse with all formats /* delete Info; Info=new File__MultipleParsing; if (Format_Test()>0) return 1; delete Info; Info=new File_Unknown; if (Format_Test()>0) return 1; return 0; */ InternalMethod=1; size_t ToReturn=ListFormats(); Format_Test_FillBuffer_Close(); return ToReturn; }
//--------------------------------------------------------------------------- size_t MediaInfo_Internal::Open (const int8u* Begin_, size_t Begin_Size_, const int8u*, size_t, int64u FileSize_) { CriticalSectionLocker CSL(CS); Buffer_Size_Max=Begin_Size_; delete[] Buffer; Buffer=new int8u[Buffer_Size_Max]; std::memcpy(Buffer, Begin_, Begin_Size_); Buffer_Size=Begin_Size_; File_Name.clear(); File_Size=FileSize_; InternalMethod=1; size_t ToReturn=ListFormats(); Buffer_Clear(); return ToReturn; }
int main(int argc, char* argv[]) { int result = 0; const char* pszSourceFilename = NULL; const char* pszDestFilename = NULL; bool bMultiFileMode = false; bool bPauseAtEnd = false; bool bPauseOnError = false; bool bRunTest = false; bool bClothingOptionSet = false; bool bCharacterOptionSet = false; if (argc == 1) { Usage(); result = -1; goto Finish; } int iArg; for (iArg = 1; iArg < argc; ++iArg) { if ('-' == argv[iArg][0] || '/' == argv[iArg][0]) { switch (argv[iArg][1]) { case '?': Usage(); result = 0; goto Finish; break; case 'a': case 'A': { int threshold = atoi(&argv[iArg][2]); if (threshold < 0 || threshold > 255) { printf("ERROR: Alpha threshold must be between 0 and 255.\n"); result = -1; goto Finish; } MemImage::s_byAlphaThreshold = threshold; break; } case 'c': case 'C': MemImage::s_bCreateMipTestImage = true; break; case 'e': case 'E': bPauseOnError = true; break; case 'f': case 'F': { const char* arg = &argv[iArg][2]; g_targetFormatID = FORMAT_UNSPECIFIED; g_targetFormatID = GetFormatFromString(arg); if (FORMAT_UNSPECIFIED == g_targetFormatID) { ListFormats(); result = -1; goto Finish; } break; } /* case 'g': case 'G': MemImage::s_fGammaFactor = (float) atof(&argv[iArg][2]); if (MemImage::s_fGammaFactor < 0.0f || MemImage::s_fGammaFactor > 1.0f) { printf("ERROR: Gamma factor must between 0.0 and 1.0.\n"); result = -1; goto Finish; } break; */ case 'h': case 'H': bCharacterOptionSet = true; MemImage::s_ruleTable[PNGTYPE_PALETTIZED_ALPHAMASK] = BLPTYPE_PAL_ALPHA0; MemImage::s_ruleTable[PNGTYPE_RGB] = BLPTYPE_PAL_ALPHA0; MemImage::s_ruleTable[PNGTYPE_RGBA] = BLPTYPE_PAL_ALPHA0; break; case 'i': case 'I': printf("File Info Mode.\n"); g_bInfoMode = true; MemImage::s_bVerbose = true; bMultiFileMode = true; break; case 'l': case 'L': ListFormats(); goto Finish; break; case 'm': case 'M': bMultiFileMode = true; break; case 'n': case 'N': MemImage::s_bNoMips = true; break; case 'p': case 'P': bPauseAtEnd = true; break; case 'r': case 'R': bClothingOptionSet = true; MemImage::s_ruleTable[PNGTYPE_RGB] = BLPTYPE_PAL_ALPHA0; MemImage::s_ruleTable[PNGTYPE_RGBA] = BLPTYPE_PAL_ALPHA8; MemImage::s_ruleTable[BLPTYPE_PAL_ALPHA0] = PNGTYPE_RGB; MemImage::s_ruleTable[BLPTYPE_PAL_ALPHA1] = PNGTYPE_RGBA; MemImage::s_ruleTable[BLPTYPE_PAL_ALPHA4] = PNGTYPE_RGBA; MemImage::s_ruleTable[BLPTYPE_PAL_ALPHA8] = PNGTYPE_RGBA; break; case 't': case 'T': bRunTest = true; break; case 'u': case 'U': { char arg[128]; ::strncpy(arg, &argv[iArg][2], 127); char* pszGT = ::strchr(arg, '='); if (NULL == pszGT) { LOG("ERROR: No \"=\" character found in /U option.\n"); result = -1; goto Finish; } pszGT[0] = 0; char* arg2 = &pszGT[1]; FORMATID srcID = GetFormatFromString(arg); FORMATID destID = GetFormatFromString(arg2); if (FORMAT_UNSPECIFIED == srcID || FORMAT_UNSPECIFIED == destID) { ListFormats(); result = -1; goto Finish; } MemImage::s_ruleTable[srcID] = destID; break; } case 'v': case 'V': MemImage::s_bVerbose = true; break; default: printf("ERROR; %c is not a valid option.\n", argv[iArg][1]); result = -1; goto Finish; } } else { break; } } if (bRunTest) { if (!RunTest()) result = -1; goto Finish; } if (bClothingOptionSet && bCharacterOptionSet) { printf("ERROR: -r and -h are exclusive.\n"); result = -1; goto Finish; } if (iArg == argc) { printf("ERROR: Filename argument missing.\n"); result = -1; goto Finish; } else if (bMultiFileMode) { do { #ifndef LINUX char filepath[BLPCONV_MAX_PATH] = ""; ::strcpy(filepath, argv[iArg]); char* slash = ::strrchr(filepath, '\\'); if (NULL == slash) slash = ::strrchr(filepath, '/'); if (NULL != slash) slash[1] = 0; else filepath[0] = 0; //LOG("File to search for = %s.\n", argv[iArg]); WIN32_FIND_DATA aFindData; HANDLE hFindFile = ::FindFirstFile(argv[iArg], &aFindData); if (INVALID_HANDLE_VALUE == hFindFile) { printf("ERROR: Couldn't find file '%s'.\n", argv[iArg]); result = -1; break; } do { char foundFile[BLPCONV_MAX_PATH]; ::sprintf(foundFile, "%s%s", filepath, aFindData.cFileName); //LOG("FindFirstFile found %s\n", foundFile); result = ProcessFile(foundFile, NULL); if (result != 0) break; } while (FindNextFile(hFindFile, &aFindData)); FindClose(hFindFile); #else DIR *dp; struct dirent *de; dp = opendir( dirname( argv[iArg] )); if( dp == NULL ) { printf("ERROR: Couldn't find file '%s' (%d).\n", argv[iArg], errno); result = -1; } else { while ( (de = readdir(dp)) != NULL ) { if( fnmatch( basename(argv[iArg]), de->d_name, FNM_PATHNAME ) == 0 ) { result = ProcessFile(de->d_name, NULL); if( result != 0 ) { break; } } } closedir(dp); } #endif ++iArg; } while ((result == 0) && (iArg < argc)); } else { pszSourceFilename = argv[iArg++]; if (!bMultiFileMode && iArg < argc) { pszDestFilename = argv[iArg]; } result = ProcessFile(pszSourceFilename, pszDestFilename); } Finish: if (bPauseAtEnd || (bPauseOnError && result != 0)) { printf("Press any key to continue...\n"); #ifndef LINUX _getch(); #else getchar(); #endif } return result; }