Ejemplo n.º 1
0
void ODBDirDlg::OnBnClickedOpenArchive()
{
   // TODO: Add your control notification handler code here
   CString fullPath,fileName;

   int sel = m_filesLB.GetCurSel();

   if (sel == LB_ERR)
   {
      return;
   }

   m_filesLB.GetText(sel,fileName);

   if (fileName.Left(1) == "[")
   {
      fileName.Remove('[');
      fileName.Remove(']');

      if (fileName.Left(1) == "-")
      {
         fileName.Remove('-');
      }
   }

   CFilePath archivePath(m_dir);
   archivePath.pushLeaf(fileName);
   archivePath.setDelimiterBackSlash();

   if ((archivePath.getExtension().CompareNoCase("gz" )  == 0) ||
       (archivePath.getExtension().CompareNoCase("tar")  == 0) ||
       (archivePath.getExtension().CompareNoCase("tgz")  == 0)    )
   {
      m_archiveFilePath = archivePath.getPath();
      m_archiveFileOpened = true;

      CResizingDialog::OnOK();
   }
}
Ejemplo n.º 2
0
void PackageManager::archivePath(const char * pFilePath)
{
#ifdef WIN32
	if (!pFilePath || pFilePath[0] == 0) {
		return;
	}

    WIN32_FIND_DATAA FindFileData;
    HANDLE hFind = INVALID_HANDLE_VALUE;
    char DirSpec[MAX_PATH + 1];// 指定路径
    DWORD dwError;

    strncpy (DirSpec, pFilePath, strlen(pFilePath) + 1);
	if (pFilePath[strlen(pFilePath) - 1] == '/') {
		strncat(DirSpec, "*", 2);
	} else {
		strncat(DirSpec, "/*", 3);
	}

    hFind = FindFirstFileA(DirSpec, &FindFileData);

    if (hFind == INVALID_HANDLE_VALUE) {
        printf ("Invalid file handle. Error is %u ", GetLastError());
        return ;
    }

    if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
		archiveFile(FindFileData.cFileName, pFilePath);
	} else if((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        && strcmp(FindFileData.cFileName, ".") != 0
        && strcmp(FindFileData.cFileName, "..") != 0
		&& strcmp(FindFileData.cFileName, ".svn") != 0) {   //找到目录
        char Dir[MAX_PATH + 1];
        strcpy(Dir, pFilePath);
		if (pFilePath[strlen(pFilePath) - 1] != '/') {
			 strncat(Dir, "/", 2);
		}

        strcat(Dir, FindFileData.cFileName);
        archivePath(Dir);
    }

    while (FindNextFileA(hFind, &FindFileData) != 0)
    {
        if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {   //找到文件
			archiveFile(FindFileData.cFileName, pFilePath);
        } else if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
            && strcmp(FindFileData.cFileName, ".") != 0
            && strcmp(FindFileData.cFileName, "..") != 0
			&& strcmp(FindFileData.cFileName, ".svn") != 0) { //找到目录
            char Dir[MAX_PATH + 1];
            strcpy(Dir, pFilePath);
			if (pFilePath[strlen(pFilePath) - 1] != '/') {
				 strncat(Dir, "/", 2);
			}
            strcat(Dir, FindFileData.cFileName);
            archivePath(Dir);
		}
    }

    dwError = GetLastError();
    FindClose(hFind);

    if (dwError != ERROR_NO_MORE_FILES) {
        printf ("FindNextFile error. Error is %u ", dwError);
        return;
    }
#endif
}
Ejemplo n.º 3
0
void PackageManager::createMpqPackage(const char* pathName, const char* pszMpqName)
{
#ifdef WIN32
	if (!pathName || pathName[0] == 0) {
		return;
	}

	PackageUtil::logMsg("createPackage begin");

	std::string realPath = PackageUtil::flattenPathName(pathName);
	s_rootDir = realPath;

	std::replace(s_rootDir.begin(), s_rootDir.end(), '\\', '/');
	std::transform(s_rootDir.begin(), s_rootDir.end(), s_rootDir.begin(), tolower);
	if (s_rootDir.back() != '/') {
		s_rootDir += '/';
	}

	std::string fileName;
	if (realPath.back() == '/') {
		int last = realPath.find_last_of('/', realPath.size() - 2);
		fileName = realPath.substr(last + 1, realPath.size() - last - 1 - 1);
	} else {
		int last = realPath.find_last_of('/');
		fileName = realPath.substr(last, realPath.size() - last);
	}

	std::string listFileName = WORK_PATH + fileName + ".txt";
	std::string mpqName = WORK_PATH;
	mpqName += fileName;
	mpqName += ".mpq";

	if (PackageUtil::fileExists(mpqName.c_str())) {
		remove(mpqName.c_str());
	}

#ifdef WIN32
	wchar_t szMpqName[256] = {0};
	MultiByteToWideChar (CP_ACP, 0, mpqName.c_str(), mpqName.size(), szMpqName, 255);

	if (!SFileCreateArchive(szMpqName, MPQ_CREATE_ARCHIVE_V4 | MPQ_CREATE_ATTRIBUTES, 4000, &s_currentMpqHandle)) {
		s_currentMpqHandle = NULL;
		return;
	}
#else
	if (!SFileCreateArchive(mpqName.c_str(), MPQ_CREATE_ARCHIVE_V4 | MPQ_CREATE_ATTRIBUTES, 4000, &s_currentMpqHandle)) {
		s_currentMpqHandle = NULL;
		return;
	}
#endif

	if (s_fpListFile) {
		fclose(s_fpListFile);
	}

	s_fpListFile = fopen(listFileName.c_str(), "w");
	archivePath(realPath.c_str());
	fclose(s_fpListFile);
	SFileCloseArchive(s_currentMpqHandle);

	PackageUtil::logMsg("createPackage over");

	// 测试文件是否正确
#ifdef WIN32
	if(SFileOpenArchive(szMpqName, 0, 0, &s_currentMpqHandle)) {
        SFileCloseArchive(s_currentMpqHandle);
		return;
	}
#else
	if(SFileOpenArchive(mpqName.c_str(), 0, 0, &s_currentMpqHandle)) {
		SFileCloseArchive(s_currentMpqHandle);
		return;
	}
#endif

	assert(false);
#endif
}