Example #1
0
void ArcAPI::load() {
  load_libs(add_trailing_slash(Far::get_plugin_module_path()) + L"*.dll");
  find_sfx_modules(add_trailing_slash(Far::get_plugin_module_path()) + L"*.sfx");
  if (arc_libs.empty() || sfx_modules.empty()) {
    wstring _7zip_path;
    Key _7zip_key;
    _7zip_key.open_nt(HKEY_CURRENT_USER, L"Software\\7-Zip", KEY_QUERY_VALUE, false) && _7zip_key.query_str_nt(_7zip_path, L"Path");
    if (_7zip_path.empty())
      _7zip_key.open_nt(HKEY_LOCAL_MACHINE, L"Software\\7-Zip", KEY_QUERY_VALUE, false) && _7zip_key.query_str_nt(_7zip_path, L"Path");
    if (!_7zip_path.empty()) {
      if (arc_libs.empty())
        load_libs(add_trailing_slash(_7zip_path) + L"7z.dll");
      if (sfx_modules.empty())
        find_sfx_modules(add_trailing_slash(_7zip_path) + L"*.sfx");
    }
  }
  if (arc_libs.empty()) {
    wstring _7z_dll_path;
    IGNORE_ERRORS(_7z_dll_path = search_path(L"7z.dll"));
    if (!_7z_dll_path.empty())
      load_libs(_7z_dll_path);
  }
  for (unsigned i = 0; i < arc_libs.size(); i++) {
    const ArcLib& arc_lib = arc_libs[i];

    UInt32 num_formats;
    if (arc_lib.GetNumberOfFormats) {
      if (arc_lib.GetNumberOfFormats(&num_formats) != S_OK)
        num_formats = 0;
    }
    else
      num_formats = 1;

    for (UInt32 idx = 0; idx < num_formats; idx++) {
      ArcFormat arc_format;
      arc_format.lib_index = i;
      ArcType type;
      if (arc_lib.get_bytes_prop(idx, NArchive::kClassID, type) != S_OK) continue;
      arc_lib.get_string_prop(idx, NArchive::kName, arc_format.name);
      if (arc_lib.get_bool_prop(idx, NArchive::kUpdate, arc_format.updatable) != S_OK)
        arc_format.updatable = false;
      arc_lib.get_bytes_prop(idx, NArchive::kStartSignature, arc_format.start_signature);
      arc_lib.get_string_prop(idx, NArchive::kExtension, arc_format.extension_list);
      ArcFormats::const_iterator existing_format = arc_formats.find(type);
      if (existing_format == arc_formats.end() || arc_libs[existing_format->second.lib_index].version < arc_lib.version)
        arc_formats[type] = arc_format;
    }
  }
  // unload unused libraries
  set<unsigned> used_libs;
  for_each(arc_formats.begin(), arc_formats.end(), [&] (const pair<ArcType, ArcFormat>& arc_format) {
    used_libs.insert(arc_format.second.lib_index);
  });
  for (unsigned i = 0; i < arc_libs.size(); i++) {
    if (used_libs.count(i) == 0) {
      FreeLibrary(arc_libs[i].h_module);
      arc_libs[i].h_module = nullptr;
    }
  }
}
Example #2
0
void FilePanel::scan_dir( const std::string& root_path, const std::string& rel_path, std::list<PanelItemData>& pid_list, FileListProgress& progress ) {
	std::string path = add_trailing_slash( root_path ) + rel_path;
	bool more = true;
	WIN32_FIND_DATAW find_data;
	HANDLE h_find = FindFirstFileW( long_path( add_trailing_slash( path ) + L"*" ).data( ), &find_data );
	try {
		if ( h_find == INVALID_HANDLE_VALUE ) {
			// special case: symlink that denies access to directory, try real path
			if ( GetLastError( ) == ERROR_ACCESS_DENIED ) {
				DWORD attr = GetFileAttributesW( long_path( path ).data( ) );
				CHECK_SYS( attr != INVALID_FILE_ATTRIBUTES );
				if ( attr & FILE_ATTRIBUTE_REPARSE_POINT ) {
					h_find = FindFirstFileW( long_path( add_trailing_slash( get_real_path( path ) ) + L"*" ).data( ), &find_data );
					}
				else CHECK_SYS( false );
				}
			}
		if ( h_find == INVALID_HANDLE_VALUE ) {
			CHECK_SYS( GetLastError( ) == ERROR_NO_MORE_FILES );
			more = false;
			}
		}
	catch ( ... ) {
		if ( flat_mode ) {
			more = false;
			}
		else throw;
		}
	ALLOC_RSRC( ; );
Example #3
0
CL_String CL_PathHelp::get_fullname(
	const CL_String &fullpath,
	const CL_String &filename,
	const CL_String &extension,
	PathType path_type)
{
	if (!extension.empty() && extension[0] == '.')
		return add_trailing_slash(fullpath, path_type) + filename + extension;
	else if (!extension.empty())
		return add_trailing_slash(fullpath, path_type) + filename + "." + extension;
	else
		return add_trailing_slash(fullpath, path_type) + filename;
}
Example #4
0
wstring Archive::get_temp_file_name() const {
  GUID guid;
  CHECK_COM(CoCreateGuid(&guid));
  wchar_t guid_str[50];
  CHECK(StringFromGUID2(guid, guid_str, ARRAYSIZE(guid_str)));
  return add_trailing_slash(arc_dir()) + guid_str + L".tmp";
}
Example #5
0
int combine(const char* lowerdir, const char* upperdir,const char* combineddir, bool is_verbose, FILE* script_stream) {
	char dummy_0[PATH_MAX];
	char dummy_1[PATH_MAX];
	struct extra_path extra = { (char*) combineddir, strlen(combineddir) };
	command(script_stream, "cp -rf $ %", strcat(add_trailing_slash(dummy_0,lowerdir),"*"),add_trailing_slash(dummy_1,combineddir));
	return traverse(lowerdir, upperdir, is_verbose, script_stream, combine_d, NULL, combine_f, NULL, combine_whiteout,(void *)&extra);
}
Example #6
0
CL_String CL_PathHelp::get_fullname(
	const CL_String &fullpath,
	const CL_String &filename,
	PathType path_type)
{
	return add_trailing_slash(fullpath, path_type) + filename;
}
Example #7
0
void package_processing()
{
    std::vector<PackageCompiler*> packageCompilers;
    if(g_config->m_packageName.length() > 0)
    {
        PackageCompiler* compiler = new PackageCompiler;
        compiler->m_input = ROOT_DATA_PATH + g_config->m_packageName;
        compiler->m_output = ROOT_DATA_PATH + g_config->m_packageName + ".package";
        add_trailing_slash(compiler->m_input);
        LOGI("package compile %s -> %s", compiler->m_input.c_str(), compiler->m_output.c_str());
        packageCompilers.push_back(compiler);
    }
    else
    {
        StringArray folders;
        scan_dir(folders, ROOT_DATA_PATH, "*", SCAN_DIRS, false);
        for(size_t i=0; i<folders.size(); ++i)
        {
            std::string folder = remove_top_folder(folders[i]);
            PackageCompiler* compiler = new PackageCompiler;
            compiler->m_input = ROOT_DATA_PATH + folder;
            compiler->m_output = ROOT_DATA_PATH + folder + ".package";
            add_trailing_slash(compiler->m_input);
            LOGI("package compile %s -> %s", compiler->m_input.c_str(), compiler->m_output.c_str());
            packageCompilers.push_back(compiler);
        }
    }
    for(size_t i=0; i<packageCompilers.size(); ++i)
    {
        packageCompilers[i]->preProcess();
    }
    for(size_t i=0; i<packageCompilers.size(); ++i)
    {
        packageCompilers[i]->go();
    }
    for(size_t i=0; i<packageCompilers.size(); ++i)
    {
        packageCompilers[i]->postProcess();
    }
    for(size_t i=0; i<packageCompilers.size(); ++i)
    {
        delete packageCompilers[i];
    }
    packageCompilers.clear();
}
Example #8
0
// determine full file paths for FILE_NAME attributes
void FileInfo::find_full_paths() {
  unsigned fn_idx = 0;
  for (unsigned attr_idx = 0; attr_idx < attr_list.size(); attr_idx++) {
    if (attr_list[attr_idx].type != AT_FILE_NAME) continue;
    if (file_name_list[fn_idx].name == L".") {
      attr_list.item(attr_idx).name = add_trailing_slash(volume->name);
    }
    else {
      UnicodeString full_path = file_name_list[fn_idx].name;
      u64 parent_dir_ref = file_name_list[fn_idx].parent_directory;
      while (true) {
        FileInfo file_info;
        file_info.volume = volume;
        file_info.process_file(parent_dir_ref);
        unsigned posix_name_idx = -1;
        unsigned win32_name_idx = -1;
        for (unsigned i = 0; i < file_info.file_name_list.size(); i++) {
          const FileNameAttr& attr = file_info.file_name_list[i];
          if (attr.file_name_type == FILE_NAME_POSIX) {
            posix_name_idx = i;
          }
          else if ((attr.file_name_type == FILE_NAME_WIN32) || (attr.file_name_type == FILE_NAME_WIN32_AND_DOS)) {
            win32_name_idx = i;
          }
        }
        unsigned name_idx;
        if (posix_name_idx != -1) name_idx = posix_name_idx;
        else if (win32_name_idx != -1) name_idx = win32_name_idx;
        else CHECK_FMT(false);
        const FileNameAttr& attr = file_info.file_name_list[name_idx];
        CHECK_FMT((attr.file_attributes & FILE_ATTR_I30_INDEX_PRESENT) == FILE_ATTR_I30_INDEX_PRESENT);
        if (attr.name == L".") { // root directory
          full_path.insert(0, add_trailing_slash(volume->name));
          attr_list.item(attr_idx).name = full_path;
          break;
        }
        else {
          full_path.insert(0, add_trailing_slash(attr.name));
          parent_dir_ref = attr.parent_directory;
        }
      }
    }
    fn_idx++;
  }
}
Example #9
0
bool get_volume_guid_path( const wstring& volume_mount_point, wstring& volume_guid_path ) {
	unsigned buf_size = MAX_PATH;
	unique_ptr<wchar_t[ ]> buffer( new wchar_t[ buf_size ] );
	if ( !::GetVolumeNameForVolumeMountPointW( add_trailing_slash( volume_mount_point ).c_str( ), buffer.get( ), buf_size ) ) {
		return false;
		}
	volume_guid_path.assign( buffer.get( ) );
	return true;
	}
Example #10
0
list<wstring> get_include_file_list(const wstring& file_path, const list<wstring>& include_dirs) {
  list<wstring> file_list;
  wstring text = load_file(file_path);
  wstring inc_file;
  size_t pos = 0;
  while (true) {
    if (is_include_directive(text, pos, inc_file)) {
      fix_slashes(inc_file);
      wstring inc_path = add_trailing_slash(extract_file_path(file_path)) + inc_file;
      bool found = file_exists(inc_path);
      for (list<wstring>::const_iterator inc_dir = include_dirs.begin(); !found && inc_dir != include_dirs.end(); inc_dir++) {
        inc_path = add_trailing_slash(*inc_dir) + inc_file;
        found = file_exists(inc_path);
      }
      if (found) file_list.push_back(inc_path);
    }
    pos = text.find(L'\n', pos);
    if (pos == wstring::npos) break;
    else pos++;
  }
  return file_list;
}
Example #11
0
list<wstring> get_volume_mount_points( const wstring& volume_guid_path ) {
	unsigned buf_size = MAX_PATH;
	unique_ptr<wchar_t[ ]> buffer( new wchar_t[ buf_size ] );
	DWORD len;
	BOOL res = GetVolumePathNamesForVolumeNameW( add_trailing_slash( volume_guid_path ).c_str( ), buffer.get( ), buf_size, &len );
	if ( !res ) {
		if ( GetLastError( ) == ERROR_MORE_DATA ) {
			buf_size = len;
			buffer.reset( new wchar_t[ buf_size ] );
			res = GetVolumePathNamesForVolumeNameW( add_trailing_slash( volume_guid_path ).c_str( ), buffer.get( ), buf_size, &len );
			}
		CHECK_SYS( res );
		}
	list<wstring> result;
	const wchar_t* path = buffer.get( );
	while ( *path ) {
		unsigned len = wcslen( path );
		result.push_back( wstring( path, len ) );
		path += len + 1;
		}
	return result;
	}
Example #12
0
int
parse_dnsa_config_file(dnsa_config_s *dc, char *config)
{
	int retval = 0;
	FILE *cnf;
#ifdef HAVE_WORDEXP_H
	char **uconf;
	wordexp_t p;
#endif /* HAVE_WORDEXP_H */

	dc->port = 3306;
	dc->cliflag = 0;

	if (!(cnf = fopen(config, "r"))) {
		fprintf(stderr, "Cannot open config file %s\n", config);
		retval = CONF_ERR;
	} else {
		read_dnsa_config_values(dc, cnf);
		fclose(cnf);
	}
#ifdef HAVE_WORDEXP
	if ((retval = wordexp("~/.dnsa.conf", &p, 0)) == 0) {
		uconf = p.we_wordv;
		if ((cnf = fopen(*uconf, "r"))) {
			read_dnsa_config_values(dc, cnf);
			fclose(cnf);
		}
		wordfree(&p);
	}
#endif /* HAVE_WORDEXP */
	if ((retval = add_trailing_slash(dc->dir)) != 0)
		return DIR_ERR;
	if ((retval = add_trailing_slash(dc->bind)) != 0)
		return BIND_ERR;
	if ((retval = add_trailing_dot(dc->hostmaster)) != 0)
		return HOSTM_ERR;
	return retval;
}
Example #13
0
void gendep(const deque<wstring>& params) {
  list<wstring> source_dirs, include_dirs;
  parse_cmd_line(params, source_dirs, include_dirs);
  wstring output;
  set<wstring> file_set;
  for (list<wstring>::const_iterator src_dir = source_dirs.begin(); src_dir != source_dirs.end(); src_dir++) {
    DirList dir_list(get_full_path_name(src_dir->empty() ? L"." : *src_dir));
    while (dir_list.next()) {
      if (!dir_list.data().is_dir() && is_valid_ext(dir_list.data().cFileName)) {
        process_file(output, file_set, add_trailing_slash(*src_dir) + dir_list.data().cFileName, include_dirs);
      }
    }
  }
  cout << unicode_to_ansi(output, CP_ACP);
}
Example #14
0
CL_String CL_PathHelp::get_fullname(
	const CL_String &location,
	const CL_String &basepath,
	const CL_String &filename,
	const CL_String &extension,
	PathType path_type)
{
	CL_String fullname = location;
	fullname += add_trailing_slash(basepath, path_type);
	fullname += filename;
	if (!extension.empty() && extension[0] == '.')
		fullname += extension;
	else if (!extension.empty())
		fullname += "." + extension;
	return fullname;
}
Example #15
0
/**
  * This method is to post-process options once we know all of them
  */
void unionfs_post_opts(void) {
	// chdir to the given chroot, we
	if (uopt.chroot) {
		int res = chdir(uopt.chroot);
		if (res) {
			fprintf(stderr, "Chdir to %s failed: %s ! Aborting!\n",
				  uopt.chroot, strerror(errno));
			exit(1);
		}
	}

	// Make the pathes absolute and add trailing slashes
	int i;
	for (i = 0; i<uopt.nbranches; i++) {
		// if -ochroot= is specified, the path has to be given absolute
		// or relative to the chroot, so no need to make it absolute
		// also won't work, since we are not yet in the chroot here
		if (!uopt.chroot) {
			uopt.branches[i].path = make_absolute(uopt.branches[i].path);
		}
		uopt.branches[i].path = add_trailing_slash(uopt.branches[i].path);

		// Prevent accidental umounts. Especially system shutdown scripts tend
		// to umount everything they can. If we don't have an open file descriptor,
		// this might cause unexpected behaviour.
		char path[PATHLEN_MAX];

		if (!uopt.chroot) {
			BUILD_PATH(path, uopt.branches[i].path);
		} else {
			BUILD_PATH(path, uopt.chroot, uopt.branches[i].path);
		}

		int fd = open(path, O_RDONLY);
		if (fd == -1) {
			fprintf(stderr, "\nFailed to open %s: %s. Aborting!\n\n",
				path, strerror(errno));
			exit(1);
		}
		uopt.branches[i].fd = fd;
		uopt.branches[i].path_len = strlen(path);
	}
}
Example #16
0
void ArcAPI::find_sfx_modules(const wstring& path) {
  FileEnum file_enum(path);
  wstring dir = extract_file_path(path);
  bool more;
  while (file_enum.next_nt(more) && more) {
    SfxModule sfx_module;
    sfx_module.path = add_trailing_slash(dir) + file_enum.data().cFileName;
    File file;
    if (!file.open_nt(sfx_module.path, FILE_READ_DATA, FILE_SHARE_READ, OPEN_EXISTING, 0))
      continue;
    Buffer<char> buffer(2);
    unsigned sz;
    if (!file.read_nt(buffer.data(), static_cast<unsigned>(buffer.size()), sz))
      continue;
    string sig(buffer.data(), sz);
    if (sig != "MZ")
      continue;
    sfx_modules.push_back(sfx_module);
  }
}
Example #17
0
bool FileEnum::next_nt(bool& more) {
  while (true) {
    if (h_find == INVALID_HANDLE_VALUE) {
      h_find = FindFirstFileW(long_path(add_trailing_slash(dir_path) + L'*').c_str(), &find_data);
      if (h_find == INVALID_HANDLE_VALUE)
        return false;
    }
    else {
      if (!FindNextFileW(h_find, &find_data)) {
        if (GetLastError() == ERROR_NO_MORE_FILES) {
          more = false;
          return true;
        }
        return false;
      }
    }
    if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
      if ((find_data.cFileName[0] == L'.') && ((find_data.cFileName[1] == 0) || ((find_data.cFileName[1] == L'.') && (find_data.cFileName[2] == 0))))
        continue;
    }
    more = true;
    return true;
  }
}
Example #18
0
void ArcAPI::load_libs(const wstring& path) {
  FileEnum file_enum(path);
  wstring dir = extract_file_path(path);
  bool more;
  while (file_enum.next_nt(more) && more) {
    ArcLib arc_lib;
    arc_lib.module_path = add_trailing_slash(dir) + file_enum.data().cFileName;
    arc_lib.h_module = LoadLibraryW(arc_lib.module_path.c_str());
    if (arc_lib.h_module == nullptr)
      continue;
    arc_lib.CreateObject = reinterpret_cast<ArcLib::FCreateObject>(GetProcAddress(arc_lib.h_module, "CreateObject"));
    arc_lib.GetNumberOfMethods = reinterpret_cast<ArcLib::FGetNumberOfMethods>(GetProcAddress(arc_lib.h_module, "GetNumberOfMethods"));
    arc_lib.GetMethodProperty = reinterpret_cast<ArcLib::FGetMethodProperty>(GetProcAddress(arc_lib.h_module, "GetMethodProperty"));
    arc_lib.GetNumberOfFormats = reinterpret_cast<ArcLib::FGetNumberOfFormats>(GetProcAddress(arc_lib.h_module, "GetNumberOfFormats"));
    arc_lib.GetHandlerProperty = reinterpret_cast<ArcLib::FGetHandlerProperty>(GetProcAddress(arc_lib.h_module, "GetHandlerProperty"));
    arc_lib.GetHandlerProperty2 = reinterpret_cast<ArcLib::FGetHandlerProperty2>(GetProcAddress(arc_lib.h_module, "GetHandlerProperty2"));
    if (arc_lib.CreateObject && ((arc_lib.GetNumberOfFormats && arc_lib.GetHandlerProperty2) || arc_lib.GetHandlerProperty)) {
      arc_lib.version = get_module_version(arc_lib.module_path);
      arc_libs.push_back(arc_lib);
    }
    else
      FreeLibrary(arc_lib.h_module);
  }
}
Example #19
0
int data_compiler_main(bx::CommandLine* cmdline)
{
    delete_file(DC_RESULT);

    int err = kErrorSuccess;
    uint32_t timeMS = ::GetTickCount();

    LOG_INIT("DataCompilerLog.html", "Data Compiler");
    MemoryConfig cfg;
    memset(&cfg, 0, sizeof cfg);
    cfg.m_debugMemSize = SIZE_MB(2);
    g_memoryMgr.init(cfg);

#ifdef DC_DUMP_PROFILE
    g_profiler.init(TOTAL_BLOCK_NUM);
#endif

    register_engine_factories();

    g_config = new DC_Config;
    const char* inputChar = cmdline->findOption('i');
    if(!inputChar) inputChar = "intermediate";
    const char* outputFolderChar = cmdline->findOption('o');
    if(!outputFolderChar) outputFolderChar = "data";
    const char* threadChar = cmdline->findOption('t');
    if(threadChar) g_config->m_numThreads = atoi(threadChar);
    g_config->m_ignoreTextures = cmdline->hasArg("ignore_texture");
    g_config->m_slient = cmdline->hasArg("slient");
    g_config->m_bundled = cmdline->hasArg("bundle");
    g_config->m_forceRecompile = cmdline->hasArg('b');

    create_folder("data");
    g_config->m_database.load(DC_DATABASE);

    g_config->m_inputDir = inputChar;
    string_replace(g_config->m_inputDir, "\\", "/");
    add_trailing_slash(g_config->m_inputDir);
    g_config->m_topFolder = get_top_folder(g_config->m_inputDir);
    g_config->m_outputDir = input_to_output(g_config->m_inputDir);

    ENGINE_ASSERT(g_config->m_topFolder.length(), "top folder error.");
    string_replace(g_config->m_outputDir, "\\", "/");
    add_trailing_slash(g_config->m_outputDir);
    std::string secondFolder = remove_top_folder(g_config->m_outputDir);
    if(secondFolder.length()) g_config->m_packageName = get_top_folder(secondFolder);
    LOGI("input = %s, output = %s, top-folder = %s, package-name=%s",
        g_config->m_inputDir.c_str(),
        g_config->m_outputDir.c_str(),
        g_config->m_topFolder.c_str(),
        g_config->m_packageName.c_str());

    level_processing();
    resources_process();
    if(g_config->m_compilers.size() < 10) g_config->m_numThreads = 0;
    if(g_config->m_numThreads < 2)
    {
        for(size_t i=0; i<g_config->m_compilers.size(); ++i)
        {
            g_config->m_compilers[i]->go();
        }
    }
    else
    {
        const int maxThreads = 8;
        if(g_config->m_numThreads > maxThreads) g_config->m_numThreads = maxThreads;
        uint32_t totalNum = g_config->m_compilers.size();
        uint32_t numPerThread = totalNum / g_config->m_numThreads + 1;
        bx::Thread* threads[maxThreads];
        std::vector<BaseCompiler*> compilers[maxThreads];
        uint32_t currIndex = 0;

        for (int i=0; i<g_config->m_numThreads; ++i)
        {
            uint32_t elementNum = numPerThread;
            uint32_t numLeft = totalNum - currIndex;
            if(numLeft < elementNum) elementNum = numLeft;
            if(elementNum == 0) continue;
            std::vector<BaseCompiler*>& comArray = compilers[i];
            comArray.resize(elementNum);
            memcpy(&comArray[0], &g_config->m_compilers[currIndex], elementNum*sizeof(void*));
            currIndex += elementNum;
            if(i == 0) continue;
            threads[i] = new bx::Thread();
            threads[i]->init(thread_compile, &comArray);
        }
        //main thread with other threads.
        thread_compile(&compilers[0]);
        for (int i=1; i<g_config->m_numThreads; ++i)
        {
            delete threads[i];
        }
    }
    g_config->post_process();
    package_processing();

    timeMS = ::GetTickCount() - timeMS;
    if(!g_config->m_slient) g_config->m_error.show_error();
    g_config->m_database.save(DC_DATABASE);
    g_config->m_database.m_files.clear();
    SAFE_DELETE(g_config);

#ifdef DC_DUMP_PROFILE
    g_profiler.dump_to_file("data_compiler_profile.txt", true, true);
    g_profiler.shutdown();
#endif

    g_memoryMgr.shutdown();

    LOGD("******************************************************");
    LOGD("******************************************************");
    LOGD("* TOTAL TIME COST = %d[MS] *", timeMS);
    LOGD("******************************************************");
    LOGD("******************************************************");
    LOG_TERM();

	return err;
}
Example #20
0
DirList::DirList(const wstring& dir_path): FileEnum(add_trailing_slash(dir_path) + L'*') {
}
Example #21
0
int havok_convert_main(bx::CommandLine* cmdline)
{
#ifdef HAVOK_COMPILE
    uint32_t timeMS = GetTickCount();

    int err = kErrorSuccess;
    LOG_INIT("HavokConverterLog.html", "Havok Converter");
    MemoryConfig cfg;
    memset(&cfg, 0, sizeof(cfg));
    cfg.m_debugMemSize = SIZE_MB(2);
    cfg.m_initHavok = true;
    cfg.m_havokFrameMemSize = 0;
    cfg.m_havokMonitorMemSize = 0;
    g_memoryMgr.init(cfg);

#ifdef HC_DUMP_PROFILE
    g_profiler.init(64);
#endif

    register_engine_factories();

    g_hc_config = new HC_Config;
    g_hc_config->m_packNormal = cmdline->hasArg("packnormal");
    g_hc_config->m_packUV = cmdline->hasArg("packuv");
    g_hc_config->m_slient = cmdline->hasArg("slient");
    g_hc_config->m_verbose = cmdline->hasArg("verbose");
    g_hc_config->m_merge = !cmdline->hasArg('b');

    Actor_Config config;
    ActorConverter* converter = 0;
    const char* mode = cmdline->findOption('m');
    if(!mode)
        mode = "model";

    const char* class_name = cmdline->findOption('c');
    if(!class_name)
        class_name = "level_geometry";

    const char* input = cmdline->findOption('f');
    const char* output = cmdline->findOption('o');
    if(!input)
    {
        g_hc_config->m_error.add_error("havok convert must specific f args!");
        err = kErrorArg;
        goto error_exit;
    }

    config.m_exportMode = mode;
    config.m_input = input;
    config.m_exportName = getFileName(input);
    config.m_exportFolder = "";
    config.m_rootPath = "";
    config.m_exportClass = class_name;

    if(output)
    {
        std::string output_path = output;
        string_replace(output_path, "\\", "/");
        if (str_begin_with(output_path, "./"))
        {
            output_path = output_path.substr(2, output_path.length() - 2);
        }
        if(!str_begin_with(output_path, INTERMEDIATE_PATH))
            config.m_exportFolder = std::string(INTERMEDIATE_PATH) + output_path;
        else
            config.m_exportFolder = output_path;
        add_trailing_slash(config.m_exportFolder);
        std::string path = config.m_exportFolder;
        string_replace(path, INTERMEDIATE_PATH, "");
        config.m_rootPath = path;
        LOGD("export-folder=%s *********** root-folder=%s", config.m_exportFolder.c_str(), config.m_rootPath.c_str());
    }
    else
    {
        config.m_exportFolder = TEMP_PATH;
    }
    config.m_output = config.m_exportFolder + config.m_exportName + "." + std::string(EngineNames::ACTOR);

    config.m_loader = new hkLoader;
    hkRootLevelContainer* rlc = config.m_loader->load(config.m_input.c_str());
    if (!rlc)
    {
        g_hc_config->m_error.add_error("can not load input havok file %s", config.m_input.c_str());
        err = kErrorLoadHavok;
        goto error_exit;
    }

    config.m_rlc = rlc;
    create_folder(config.m_exportFolder);
    hkxEnvironment* env = LOAD_OBJECT(rlc, hkxEnvironment);
    if(env)
    {
        hkStringBuf env_str;
        env->convertToString(env_str);
        LOGI(env_str.cString());
        config.m_assetFolder = env->getVariableValue("assetFolder");
        config.m_assetPath = env->getVariableValue("assetPath");
    }

    hkaAnimationContainer* ac = LOAD_OBJECT(rlc, hkaAnimationContainer);
    hkxScene* scene = LOAD_OBJECT(rlc,hkxScene);
    hkpPhysicsData* data = LOAD_OBJECT(rlc, hkpPhysicsData);

    config.m_scene = scene;
    config.m_animation = ac;
    config.m_physics = data;

    if(config.m_exportMode == "model")
    {
        if(!scene || !scene->m_rootNode)
        {
            g_hc_config->m_error.add_error("hkx file do not has root scene node.");
            goto error_exit;
        }
        converter = new StaticModelConverter;
        converter->setClass(config.m_exportClass);
    }
    else if(config.m_exportMode == "skin")
    {
        converter = new CharacterConverter;
        converter->setClass("character");
    }
    else if(config.m_exportMode == "level")
    {
        converter = new LevelConverter;
        config.m_output = config.m_exportFolder + config.m_exportName + "." + std::string(EngineNames::LEVEL);
    }
    else if(config.m_exportMode == "animation")
    {
        converter = new AnimationConverter;
        config.m_output = config.m_exportFolder + config.m_exportName + "." + std::string(EngineNames::ANIMATION);
    }
    if(!converter)
    {
        g_hc_config->m_error.add_error("havok converter export mode error.");
        err = kErrorArg;
        goto error_exit;
    }

    converter->m_config = &config;
    converter->setName(config.m_exportName);
    if(config.m_exportMode == "skin")
    {
        converter->process(ac);
    }
    else if(config.m_exportMode == "animation")
    {
        converter->process(ac);
    }
    else
    {
        converter->process(scene);
    }
    converter->postProcess();
    converter->serializeToFile(config.m_output.c_str());

error_exit:
    SAFE_REMOVEREF(converter);
    SAFE_REMOVEREF(config.m_loader);
    if(!g_hc_config->m_slient)
        g_hc_config->m_error.show_error();
    SAFE_DELETE(g_hc_config);

#ifdef HC_DUMP_PROFILE
    g_profiler.dump_to_file("havokconverter_profile.txt", true, true);
    g_profiler.shutdown();
#endif

    g_memoryMgr.shutdown();

    timeMS = GetTickCount() - timeMS;
    LOGD("******************************************************");
    LOGD("******************************************************");
    LOGD("* TOTAL TIME COST = %d[MS]", timeMS);
    LOGD("******************************************************");
    LOGD("******************************************************");

    LOG_TERM();
#endif
	return kErrorSuccess;
}
Example #22
0
CL_String CL_PathHelp::make_absolute(
	const CL_String &base_path,
	const CL_String &relative_path,
	PathType path_type)
{
	CL_String base = normalize(base_path, path_type);
	CL_String relative = normalize(relative_path, path_type);
	if (path_type == path_type_file)
	{
		if (!is_absolute(base, path_type_file))
		{
			// make base_path absolute using current drive and directory
#ifdef WIN32
			TCHAR absolute_base[MAX_PATH];
			memset(absolute_base, 0, sizeof(TCHAR) * MAX_PATH);
			if (_tfullpath(absolute_base, CL_StringHelp::utf8_to_ucs2(base).c_str(), MAX_PATH) == 0)
				throw CL_Exception(cl_format("Unable to make base path absolute: %1", base_path));
			base = absolute_base;
#else
			char working_dir[1024];
			memset(working_dir, 0, 1024);
			if (getcwd(working_dir, 1024) == 0)
				throw CL_Exception("Unable to get current working directory!");
			base = add_trailing_slash(working_dir, path_type) + base;
#endif
		}

		CL_String base_location = get_location(base_path, path_type_file);
		CL_String relative_location = get_location(relative_path, path_type_file);
		if (relative_location.empty() || CL_StringHelp::compare(relative_location, base_location, true) == 0)
		{
			if (is_absolute(relative, path_type))
			{
				if (relative_location.empty())
					return base_location + relative;
				else
					return relative;
			}
			CL_String absolute = add_trailing_slash(base, path_type) + relative.substr(relative_location.length());
			return normalize(absolute, path_type);
		}
		else
		{
#ifdef WIN32
			if (is_absolute(relative, path_type))
				return relative;

			if (relative_location.length() == 2 && relative_location[1] == ':')
			{
				int drive = 0;
				if (relative_location[0] >= 'A' && relative_location[0] <= 'Z')
					drive = relative_location[0] - 'A' + 1;
				else if (relative_location[0] >= 'a' && relative_location[0] <= 'z')
					drive = relative_location[0] - 'a' + 1;
				else
					throw CL_Exception(cl_format("Invalid drive: %1", relative_location));
				TCHAR working_dir[MAX_PATH];
				memset(working_dir, 0, sizeof(TCHAR)*MAX_PATH);
				if (_tgetdcwd(drive, working_dir, MAX_PATH) == 0)
					throw CL_Exception(cl_format("Unable to get current working directory for %1!", relative_location));

				return add_trailing_slash(working_dir, path_type) + relative.substr(relative_location.length());
			}
			else
			{
				return relative; // UNC path
			}
#else
			throw CL_Exception("Error in CL_PathHelp::make_absolute");
#endif
		}
	}
	else
	{
		if (is_absolute(relative, path_type))
			return relative;
		CL_String absolute = add_trailing_slash(base, path_type) + relative;
		return normalize(absolute, path_type);
	}
}
Example #23
0
CL_String CL_PathHelp::make_relative(
	const CL_String &base_path,
	const CL_String &absolute_path,
	PathType path_type)
{
	CL_String base = add_trailing_slash(normalize(base_path, path_type), path_type);
	CL_String absolute = normalize(absolute_path, path_type);

	if (path_type == path_type_file)
	{
		CL_String base_location = get_location(base, path_type_file);
		CL_String absolute_location = get_location(absolute, path_type_file);

		if (is_relative(base, path_type))
		{
#ifdef WIN32
			if (base_location.length() == 2 && base_location[1] == ':')
			{
				int drive = 0;
				if (base_location[0] >= 'A' && base_location[0] <= 'Z')
					drive = base_location[0] - 'A' + 1;
				else if (base_location[0] >= 'a' && base_location[0] <= 'z')
					drive = base_location[0] - 'a' + 1;
				else
					throw CL_Exception(cl_format("Invalid drive: %1", base_location));
				TCHAR working_dir[MAX_PATH];
				memset(working_dir, 0, sizeof(TCHAR)*MAX_PATH);
				if (_tgetdcwd(drive, working_dir, MAX_PATH) == 0)
					throw CL_Exception(cl_format("Unable to get current working directory for %1!", base_location));

				base = add_trailing_slash(working_dir, path_type) + base;
			}
			else if (base_location.empty())
			{
				TCHAR working_dir[MAX_PATH];
				memset(working_dir, 0, sizeof(TCHAR)*MAX_PATH);
				if (GetCurrentDirectory(MAX_PATH, working_dir) == FALSE)
					throw CL_Exception(cl_format("Unable to get current working directory for %1!", base_location));

				base = add_trailing_slash(working_dir, path_type) + base;
			}
			else
			{
				throw CL_Exception(cl_format("Error in make_relative with base path: %1", base_path));
			}
#else
			char working_dir[1024];
			memset(working_dir, 0, 1024);
			if (getcwd(working_dir, 1024) == 0)
				throw CL_Exception("Unable to get current working directory!");
			base = add_trailing_slash(working_dir, path_type) + base;
#endif
		}
		if (is_relative(absolute, path_type))
		{
#ifdef WIN32
			if (absolute_location.length() == 2 && absolute_location[1] == ':')
			{
				int drive = 0;
				if (absolute_location[0] >= 'A' && absolute_location[0] <= 'Z')
					drive = absolute_location[0] - 'A' + 1;
				else if (absolute_location[0] >= 'a' && absolute_location[0] <= 'z')
					drive = absolute_location[0] - 'a' + 1;
				else
					throw CL_Exception(cl_format("Invalid drive: %1", absolute_location));
				TCHAR working_dir[MAX_PATH];
				memset(working_dir, 0, sizeof(TCHAR)*MAX_PATH);
				if (_tgetdcwd(drive, working_dir, MAX_PATH) == 0)
					throw CL_Exception(cl_format("Unable to get current working directory for %1!", absolute_location));

				absolute = add_trailing_slash(working_dir, path_type) + absolute;
			}
			else if (absolute_location.empty())
			{
				TCHAR working_dir[MAX_PATH];
				memset(working_dir, 0, sizeof(TCHAR)*MAX_PATH);
				if (GetCurrentDirectory(MAX_PATH, working_dir) == FALSE)
					throw CL_Exception(cl_format("Unable to get current working directory for %1!", absolute_location));

				absolute = add_trailing_slash(working_dir, path_type) + absolute;
			}
			else
			{
				throw CL_Exception(cl_format("Error in make_relative with absolute path: %1", absolute_path));
			}
#else
			char working_dir[1024];
			memset(working_dir, 0, 1024);
			if (getcwd(working_dir, 1024) == 0)
				throw CL_Exception("Unable to get current working directory!");
			absolute = add_trailing_slash(working_dir, path_type) + absolute;
#endif
		}

		base_location = get_location(base, path_type_file);
		absolute_location = get_location(absolute, path_type_file);
		if (CL_StringHelp::compare(absolute_location, base_location, true) != 0)
			return absolute_path;
	}

	if (is_relative(base, path_type))
		throw CL_Exception(cl_format("Relative path %1 used as base path for make_relative", base_path));
	if (is_relative(absolute, path_type))
		throw CL_Exception(cl_format("Relative path %1 used as absolute path for make_relative", absolute_path));

	CL_String relative;
	CL_String relative_end;

	bool differs = false;
	CL_String::size_type start_pos = 0, end_pos = 0;
	while (true)
	{
		if (path_type == path_type_file)
		{
			end_pos = base.find_first_of("\\/", start_pos);
		}
		else
		{
			end_pos = base.find('/', start_pos);
		}
		if (end_pos == CL_String::npos)
			break;

		if (!differs)
		{
			CL_String base_element = base.substr(start_pos, end_pos - start_pos + 1);
			CL_String absolute_element = absolute.substr(start_pos, end_pos - start_pos + 1);

			bool same_element = false;
			if (path_type == path_type_file)
			{
#ifdef WIN32
				same_element = (CL_StringHelp::compare(base_element, absolute_element, true) == 0);
#else
				same_element = (base_element == absolute_element);
#endif
			}
			else
			{
				same_element = (base_element == absolute_element);
			}

			if (!same_element)
			{
				relative_end = absolute.substr(start_pos);
				differs = true;
			}
			else
			{
				relative_end = absolute.substr(end_pos+1);
			}
		}

		if (differs)
		{
			if (path_type_file)
			{
#ifdef WIN32
				relative += "..\\";
#else
				relative += "../";
#endif
			}
			else
			{
				relative += "../";
			}
		}

		start_pos = end_pos + 1;
	}

	return relative + relative_end;
}