//-----------------------------------------------------------------// utils::strings get_sub_directory(const std::string& root, bool full) { utils::strings list; auto fpath = create_full_path(root); if(fpath.empty()) { return list; } if(fpath.back() != '/') fpath += '/'; unit_map_it it = unit_map_.find(fpath); if(it != unit_map_.end()) { const typename unit_t::childs& chs = it->second.get_childs(); list.resize(chs.size()); list.clear(); for(const auto& s : chs) { if(full) { list.push_back(fpath + strip_last_of_delimita_path(s)); } else { list.push_back(s); } } } return list; }
bool install_(const std::string& key, const T& value) { std::string fpath; if(!create_full_path(key, fpath)) { return false; } bool f = false; utils::strings ss = split_text(fpath, "/"); std::string p; for(uint32_t i = 0; i < ss.size(); ++i) { p += '/'; p += ss[i]; unit_t u; u.value = value; u.set_id(serial_id_); std::pair<unit_map_it, bool> ret = unit_map_.insert(unit_pair(p, u)); if(ret.second) { ++serial_id_; auto prev = utils::get_file_path(p); if(p != prev) { unit_map_it it = unit_map_.find(prev); if(it != unit_map_.end()) { unit_t& t = it->second; t.install_child(utils::get_file_name(p)); } } f = true; } else { f = false; } } return f; }
//-----------------------------------------------------------------// unit_map_its create_list(const std::string& root) { unit_map_its list; if(unit_map_.empty()) { list.clear(); return list; } if(root.empty()) { list.resize(unit_map_.size()); list.clear(); for(unit_map_it it = unit_map_.begin(); it != unit_map_.end(); ++it) { list.push_back(it); } } else { auto fpath = create_full_path(root); if(fpath.empty()) { list.clear(); return list; } unit_map_it it = unit_map_.find(fpath); if(it != unit_map_.end()) { const typename unit_t::childs& ch = it->second.get_childs(); list.resize(ch.size()); list.clear(); for(const auto& s : ch) { auto path = create_full_path(s); if(!path.empty()) { it = unit_map_.find(path); if(it != unit_map_.end()) { list.push_back(it); } } } } else { list.clear(); } } std::sort(list.begin(), list.end(), [] (unit_map_it l, unit_map_it r) { return l->first < r->first; } ); return list; }
//-----------------------------------------------------------------// uint32_t install(const std::string& path) { auto fpath = create_full_path(path); if(fpath.empty()) { return false; } return install_(strip_last_of_delimita_path(fpath)); }
//-----------------------------------------------------------------// bool is_directory(const std::string& path) const { auto fpath = create_full_path(path); if(fpath.empty()) { return false; } if(fpath.back() != '/') fpath += '/'; return is_directory(unit_map_.find(fpath)); }
//-----------------------------------------------------------------// uint32_t make_directory(const std::string& path) { auto fpath = create_full_path(path); if(fpath.empty()) { return 0; } if(fpath.back() != '/') fpath += '/'; return install_(fpath); }
//-----------------------------------------------------------------// uint32_t find(const std::string& path) const { auto fpath = create_full_path(path); if(fpath.empty()) { return 0; } unit_map_cit cit = unit_map_.find(fpath); if(cit != unit_map_.end()) { return cit->second.get_id(); } else { return 0; } }
//-----------------------------------------------------------------// handles remove_directory(const std::string& path) { handles hnds; auto fpath = create_full_path(path); if(fpath.empty()) { return hnds; } if(fpath.back() != '/') fpath += '/'; // std::cout << "Remove dir: " << fpath << std::endl; auto hnd = erase_(fpath, hnds); if(hnd) hnds.push_back(hnd); return hnds; }
static BOOL create_full_path(LPCWSTR path) { LPWSTR new_path; BOOL ret = TRUE; int len; new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) * sizeof(WCHAR)); if (!new_path) return FALSE; strcpyW(new_path, path); while ((len = strlenW(new_path)) && new_path[len - 1] == '\\') new_path[len - 1] = 0; while (!CreateDirectoryW(new_path, NULL)) { LPWSTR slash; DWORD last_error = GetLastError(); if(last_error == ERROR_ALREADY_EXISTS) break; if(last_error != ERROR_PATH_NOT_FOUND) { ret = FALSE; break; } if(!(slash = strrchrW(new_path, '\\'))) { ret = FALSE; break; } len = slash - new_path; new_path[len] = 0; if(!create_full_path(new_path)) { ret = FALSE; break; } new_path[len] = '\\'; } HeapFree(GetProcessHeap(), 0, new_path); return ret; }
//-----------------------------------------------------------------// handles erase(const std::string& path) { handles hnds; auto fpath = create_full_path(path); if(fpath.empty()) { return hnds; } if(fpath.back() == '/') return hnds; auto hnd = erase_(fpath, hnds); if(hnd) hnds.push_back(hnd); return hnds; }
static gint parse_commandline(int argc, char **argv , gboolean *root_override , GList **load_filenames , GList **load_projects , gboolean *open_in_new_win , gint *linenumber ) { int c; gchar *tmpname; opterr = 0; DEBUG_MSG("parse_commandline, started\n"); while ((c = getopt(argc, argv, "hsvn:l:p:?")) != -1) { switch (c) { case 's': *root_override = 1; break; case 'v': g_print(CURRENT_VERSION_NAME); g_print("\n"); exit(1); break; case 'p': tmpname = create_full_path(optarg, NULL); *load_projects = g_list_append(*load_projects, tmpname); break; case 'l': *linenumber = strtoul(optarg, NULL,10); break; case 'h': case '?': g_print(CURRENT_VERSION_NAME); g_print(_("\nUsage: %s [options] [filenames ...]\n"), argv[0]); g_print(_("\nCurrently accepted options are:\n")); g_print(_("-s skip root check\n")); g_print(_("-v current version\n")); g_print(_("-n 0|1 open new window (1) or not (0)\n")); g_print(_("-p filename open project\n")); g_print(_("-l number set line<number>. Negative value takes no effect.\n")); g_print(_("-h this help screen\n")); exit(1); break; case 'n': if (strncmp(optarg,"0",1)==0) { *open_in_new_win = 0; }else{ *open_in_new_win = 1; } break; default: DEBUG_MSG("parse_commandline, abort ?!?\n"); abort(); } } DEBUG_MSG("parse_commandline, optind=%d, argc=%d\n", optind, argc); while (optind < argc) { /* related to BUG#93 */ /*if (file_exists_and_readable(argv[optind])){*/ tmpname = create_full_path(argv[optind], NULL); DEBUG_MSG("parse_commandline, argv[%d]=%s, tmpname=%s\n", optind, argv[optind], tmpname); *load_filenames = g_list_append(*load_filenames, tmpname); /*}else{ g_print("winefish: file '%s' is unreadable\n", argv[optind]); }*/ optind++; } DEBUG_MSG("parse_commandline, finished, num files=%d, num projects=%d\n" , g_list_length(*load_filenames), g_list_length(*load_projects)); return 0; }
static HRESULT WINAPI IAssemblyCacheImpl_InstallAssembly(IAssemblyCache *iface, DWORD dwFlags, LPCWSTR pszManifestFilePath, LPCFUSION_INSTALL_REFERENCE pRefData) { static const WCHAR format[] = {'%','s','\\','%','s','\\','%','s','_','_','%','s','\\',0}; ASSEMBLY *assembly; LPWSTR filename; LPWSTR name = NULL; LPWSTR token = NULL; LPWSTR version = NULL; LPWSTR asmpath = NULL; WCHAR path[MAX_PATH]; WCHAR asmdir[MAX_PATH]; LPWSTR ext; HRESULT hr; static const WCHAR ext_exe[] = {'.','e','x','e',0}; static const WCHAR ext_dll[] = {'.','d','l','l',0}; TRACE("(%p, %d, %s, %p)\n", iface, dwFlags, debugstr_w(pszManifestFilePath), pRefData); if (!pszManifestFilePath || !*pszManifestFilePath) return E_INVALIDARG; if (!(ext = strrchrW(pszManifestFilePath, '.'))) return HRESULT_FROM_WIN32(ERROR_INVALID_NAME); if (lstrcmpiW(ext, ext_exe) && lstrcmpiW(ext, ext_dll)) return HRESULT_FROM_WIN32(ERROR_INVALID_NAME); if (GetFileAttributesW(pszManifestFilePath) == INVALID_FILE_ATTRIBUTES) return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); hr = assembly_create(&assembly, pszManifestFilePath); if (FAILED(hr)) { hr = COR_E_ASSEMBLYEXPECTED; goto done; } hr = assembly_get_name(assembly, &name); if (FAILED(hr)) goto done; hr = assembly_get_pubkey_token(assembly, &token); if (FAILED(hr)) goto done; hr = assembly_get_version(assembly, &version); if (FAILED(hr)) goto done; get_assembly_directory(asmdir, MAX_PATH, assembly_get_architecture(assembly)); sprintfW(path, format, asmdir, name, version, token); create_full_path(path); hr = assembly_get_path(assembly, &asmpath); if (FAILED(hr)) goto done; filename = PathFindFileNameW(asmpath); strcatW(path, filename); if (!CopyFileW(asmpath, path, FALSE)) hr = HRESULT_FROM_WIN32(GetLastError()); done: HeapFree(GetProcessHeap(), 0, name); HeapFree(GetProcessHeap(), 0, token); HeapFree(GetProcessHeap(), 0, version); HeapFree(GetProcessHeap(), 0, asmpath); assembly_release(assembly); return hr; }
static HRESULT WINAPI IAssemblyCacheImpl_InstallAssembly(IAssemblyCache *iface, DWORD dwFlags, LPCWSTR pszManifestFilePath, LPCFUSION_INSTALL_REFERENCE pRefData) { static const WCHAR format[] = {'%','s','\\','%','s','\\','%','s','_','_','%','s','\\',0}; static const WCHAR format_v40[] = {'%','s','\\','%','s','\\','v','4','.','0','_','%','s','_','_','%','s','\\',0}; static const WCHAR ext_exe[] = {'.','e','x','e',0}; static const WCHAR ext_dll[] = {'.','d','l','l',0}; IAssemblyCacheImpl *cache = impl_from_IAssemblyCache(iface); ASSEMBLY *assembly; const WCHAR *extension, *filename, *src_dir; WCHAR *name = NULL, *token = NULL, *version = NULL, *asmpath = NULL; WCHAR asmdir[MAX_PATH], *p, **external_files = NULL, *dst_dir = NULL; PEKIND architecture; char *clr_version; DWORD i, count = 0, src_len, dst_len = sizeof(format_v40)/sizeof(format_v40[0]); HRESULT hr; TRACE("(%p, %d, %s, %p)\n", iface, dwFlags, debugstr_w(pszManifestFilePath), pRefData); if (!pszManifestFilePath || !*pszManifestFilePath) return E_INVALIDARG; if (!(extension = strrchrW(pszManifestFilePath, '.'))) return HRESULT_FROM_WIN32(ERROR_INVALID_NAME); if (lstrcmpiW(extension, ext_exe) && lstrcmpiW(extension, ext_dll)) return HRESULT_FROM_WIN32(ERROR_INVALID_NAME); if (GetFileAttributesW(pszManifestFilePath) == INVALID_FILE_ATTRIBUTES) return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); hr = assembly_create(&assembly, pszManifestFilePath); if (FAILED(hr)) { hr = COR_E_ASSEMBLYEXPECTED; goto done; } hr = assembly_get_name(assembly, &name); if (FAILED(hr)) goto done; hr = assembly_get_pubkey_token(assembly, &token); if (FAILED(hr)) goto done; hr = assembly_get_version(assembly, &version); if (FAILED(hr)) goto done; hr = assembly_get_runtime_version(assembly, &clr_version); if (FAILED(hr)) goto done; hr = assembly_get_external_files(assembly, &external_files, &count); if (FAILED(hr)) goto done; cache_lock( cache ); architecture = assembly_get_architecture(assembly); get_assembly_directory(asmdir, MAX_PATH, clr_version, architecture); dst_len += strlenW(asmdir) + strlenW(name) + strlenW(version) + strlenW(token); if (!(dst_dir = HeapAlloc(GetProcessHeap(), 0, dst_len * sizeof(WCHAR)))) { hr = E_OUTOFMEMORY; goto done; } if (!strcmp(clr_version, "v4.0.30319")) dst_len = sprintfW(dst_dir, format_v40, asmdir, name, version, token); else dst_len = sprintfW(dst_dir, format, asmdir, name, version, token); create_full_path(dst_dir); hr = assembly_get_path(assembly, &asmpath); if (FAILED(hr)) goto done; if ((p = strrchrW(asmpath, '\\'))) { filename = p + 1; src_dir = asmpath; src_len = filename - asmpath; } else { filename = asmpath; src_dir = NULL; src_len = 0; } hr = copy_file(src_dir, src_len, dst_dir, dst_len, filename); if (FAILED(hr)) goto done; for (i = 0; i < count; i++) { hr = copy_file(src_dir, src_len, dst_dir, dst_len, external_files[i]); if (FAILED(hr)) break; } done: HeapFree(GetProcessHeap(), 0, name); HeapFree(GetProcessHeap(), 0, token); HeapFree(GetProcessHeap(), 0, version); HeapFree(GetProcessHeap(), 0, asmpath); HeapFree(GetProcessHeap(), 0, dst_dir); for (i = 0; i < count; i++) HeapFree(GetProcessHeap(), 0, external_files[i]); HeapFree(GetProcessHeap(), 0, external_files); assembly_release(assembly); cache_unlock( cache ); return hr; }