Exemplo n.º 1
0
static WRes MyCreateDir(const UInt16 *name)
{
  #ifdef USE_WINDOWS_FILE
  
  return CreateDirectoryW(name, NULL) ? 0 : GetLastError();
  
  #else

  CBuf buf;
  WRes res;
  Buf_Init(&buf);
  RINOK(Utf16_To_Char(&buf, name MY_FILE_CODE_PAGE_PARAM));

  res =
  #ifdef _WIN32
  _mkdir((const char *)buf.data)
  #else
  mkdir((const char *)buf.data, 0777)
  #endif
  == 0 ? 0 : errno;
  Buf_Free(&buf, &g_Alloc);
  return res;
  
  #endif
}
Exemplo n.º 2
0
static WRes OutFile_OpenUtf16(CSzFile *p, const UInt16 *name, char **subdir, Bool *do_save)
{
  #ifdef USE_WINDOWS_FILE
  return OutFile_OpenW(p, name);
  #else
  CBuf buf;
  WRes res;
  char *work_name;
  
  Buf_Init(&buf);
  RINOK(Utf16_To_Char(&buf, name MY_FILE_CODE_PAGE_PARAM));
  work_name = (char *)buf.data;

  int is_normal = (*do_save && (*subdir == NULL || strncmp(work_name, *subdir, strlen(*subdir)) == 0));
  if (is_normal || FileIsSQL(work_name)) {
    if (is_normal) {
      if (*subdir) work_name = &work_name[strlen(*subdir) + 1];
    } else {
      work_name = basename(work_name);
    }
  }
  // @TODO: test this!
  if (skip_this_file(work_name)) {
    Buf_Free(&buf, &g_Alloc);
    return -1;
  }

  res = OutFile_Open(p, (const char *)work_name);
  Buf_Free(&buf, &g_Alloc);
  return res;
  #endif
}
Exemplo n.º 3
0
static WRes OutFile_OpenUtf16(CSzFile *p, const UInt16 *name)
{
  #ifdef USE_WINDOWS_FILE
  return OutFile_OpenW(p, name);
  #else
  CBuf buf;
  WRes res;
  Buf_Init(&buf);
  RINOK(Utf16_To_Char(&buf, name MY_FILE_CODE_PAGE_PARAM));
  res = OutFile_Open(p, (const char *)buf.data);
  Buf_Free(&buf, &g_Alloc);
  return res;
  #endif
}
Exemplo n.º 4
0
static SRes PrintString(const UInt16 *s)
{
  CBuf buf;
  SRes res;
  Buf_Init(&buf);
  res = Utf16_To_Char(&buf, s
      #ifndef _USE_UTF8
      , CP_OEMCP
      #endif
      );
  if (res == SZ_OK)
    fputs((const char *)buf.data, stdout);
  Buf_Free(&buf, &g_Alloc);
  return res;
}
Exemplo n.º 5
0
static WRes MyCreateDir(const UInt16 *name, char **subdir, Bool *do_save)
{
  #ifdef USE_WINDOWS_FILE
  
  return CreateDirectoryW(name, NULL) ? 0 : GetLastError();
  
  #else

  CBuf buf;
  WRes res;
  char *work_name =NULL;
  Buf_Init(&buf);
  RINOK(Utf16_To_Char(&buf, name MY_FILE_CODE_PAGE_PARAM));
  work_name = (char *)buf.data;

  if (*do_save) {
    if (*subdir && strstr(work_name, *subdir) == work_name)
      work_name = &work_name[strlen(*subdir) + 1];
  } else {
    if (strcmp(basename(work_name), globaldata.gd_inidata->archive_dir) == 0) {
      *subdir = strdup(work_name);
      *do_save = True;
    }
    Buf_Free(&buf, &g_Alloc);
    return 0;
  }
  
  res =
  #ifdef _WIN32
  _mkdir((const char *)work_name)
  #else
  mkdir((const char *)work_name, 0755) // orig 0777
  #endif
  == 0 ? 0 : errno;
  Buf_Free(&buf, &g_Alloc);
  return res;
  
  #endif
}
Exemplo n.º 6
0
bool SZFilePack::open(const char* packFileName)
{
	close();

	UInt32 i;
	SRes res;
	UInt16 *temp = NULL;
	size_t tempSize = 0;
	CBuf buf;
	buf.data = new byte[MAX_PATH];
	buf.size = MAX_PATH;
	mPackFileName = packFileName;
	if ( InFile_Open(&mArchiveStream.file, packFileName) ) {
		PrintError("can not open input file");
		return false;
	}

	FileInStream_CreateVTable(&mArchiveStream);
	LookToRead_CreateVTable(&mLookStream, False);

	mLookStream.realStream = &mArchiveStream.s;
	LookToRead_Init(&mLookStream);

	CrcGenerateTable();

	SzArEx_Init(&mDb);
	res = SzArEx_Open(&mDb, &mLookStream.s, &mAllocImp, &mAllocTempImp);
	if (res == SZ_OK) {
		for (i = 0; i < mDb.db.NumFiles; i++) {
			size_t len;
			const CSzFileItem *f = mDb.db.Files + i;

			if (f->IsDir)
				continue;

			len = SzArEx_GetFileNameUtf16(&mDb, i, NULL);
			if (len > tempSize) {
				SzFree(NULL, temp);
				tempSize = len;
				temp = (UInt16 *)SzAlloc(NULL, tempSize * sizeof(temp[0]));
				if (temp == 0) {
					res = SZ_ERROR_MEM;
					break;
				}
			}
			SzArEx_GetFileNameUtf16(&mDb, i, temp);
			if (res != SZ_OK)
				break;

			// 保存所有文件的索引号到hash表中
			res = Utf16_To_Char(&buf, temp, 0);
			if (res != SZ_OK)
				break;

			//名字转成小写
			_strlwr((char*)buf.data);
			string key = (const char*)buf.data;
			mIndexMap[key] = i;
		}
	}

	SzFree(NULL, temp);
	delete[] buf.data;
	mIsPackOpened = true;

	return true;
}