String GetExeFilePath() { static String exepath; ONCELOCK { const char *exe = procexepath_(); if(*exe) exepath = exe; else { String x = Argv0__; if(IsFullPath(x) && FileExists(x)) exepath = x; else { exepath = GetHomeDirFile("upp"); Vector<String> p = Split(FromSystemCharset(Environment().Get("PATH")), ':'); if(x.Find('/') >= 0) p.Add(GetCurrentDirectory()); for(int i = 0; i < p.GetCount(); i++) { String ep = NormalizePath(AppendFileName(p[i], x)); if(FileExists(ep)) exepath = ep; } } } } return exepath; }
static bool sGetSymLinkPath0(const char *linkpath, String *path) { bool ret = false; HRESULT hres; IShellLink* psl; IPersistFile* ppf; CoInitialize(NULL); hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (PVOID *) &psl); if(SUCCEEDED(hres)) { hres = psl->QueryInterface(IID_IPersistFile, (PVOID *) &ppf); if(SUCCEEDED(hres)) { hres = ppf->Load(ToSystemCharsetW(linkpath), STGM_READ); if(SUCCEEDED(hres)) if(path) { char fileW[_MAX_PATH] = {0}; psl->GetPath(fileW, _MAX_PATH, NULL, 0); *path = FromSystemCharset(fileW); } else ret = true; ppf->Release(); } psl->Release(); } CoUninitialize(); return ret; }
String GetModuleFileName(HINSTANCE instance) { #ifdef PLATFORM_WINCE wchar h[_MAX_PATH]; GetModuleFileName(instance, h, _MAX_PATH); return FromSystemCharset(h); #else if(IsWinNT()) { wchar h[_MAX_PATH]; UnicodeWin32().GetModuleFileNameW(instance, h, _MAX_PATH); return FromSystemCharsetW(h); } else { char h[_MAX_PATH]; GetModuleFileName(instance, h, _MAX_PATH); return FromSystemCharset(h); } #endif }
String GetCurrentDirectory() { #if defined(PLATFORM_WIN32) if(IsWinNT()) { wchar h[MAX_PATH]; UnicodeWin32().GetCurrentDirectoryW(MAX_PATH, h); return FromSystemCharsetW(h); } else { char h[MAX_PATH]; ::GetCurrentDirectory(MAX_PATH, h); return FromSystemCharset(h); } #elif defined(PLATFORM_POSIX) char h[1024]; return getcwd(h, 1024) ? FromSystemCharset(h) : String(); #else #error GetCurrentDirectory not implemented for this platform, comment this line to get Null return Null; #endif//PLATFORM }
static int CALLBACK Win32_AddFace(const LOGFONT *logfont, const TEXTMETRIC *, dword type, LPARAM param) { #ifdef PLATFORM_WINCE const wchar *facename = (const wchar *)param; if(facename && _wcsicmp(logfont->lfFaceName, facename)) return 1; #else const char *facename = (const char *)param; if(facename && stricmp(logfont->lfFaceName, facename)) return 1; #endif if(logfont->lfFaceName[0] == '@') return 1; #ifdef PLATFORM_WINCE FontFaceInfo& f = sFontFace().GetAdd(WString(logfont->lfFaceName).ToString()); f.name = FromSystemCharset(logfont->lfFaceName); #else String name = FromSystemCharset(logfont->lfFaceName); if(FindIndex(Split("Courier New CE;Courier New CYR;Courier New Greek;" "Courier New TUR;Courier New Baltic;Arial CE;Arial CYR;" "Arial Greek;Arial TUR;Arial Baltic;Arial CE;Times New Roman CE;" "Times New Roman CYR;Times New Roman Greek;Times New Roman TUR;" "Times New Roman Baltic;Times New Roman CE", ';'), name) >= 0) return 1; int q = sList->Find(name); FaceInfo& f = q < 0 ? sList->Add(logfont->lfFaceName) : (*sList)[q]; f.name = FromSystemCharset(logfont->lfFaceName); #endif if(q < 0) f.info = Font::SCALEABLE; if((logfont->lfPitchAndFamily & 3) == FIXED_PITCH) f.info |= Font::FIXEDPITCH; if(!(type & TRUETYPE_FONTTYPE)) f.info &= ~Font::SCALEABLE; if(logfont->lfCharSet == SYMBOL_CHARSET || logfont->lfCharSet == OEM_CHARSET) f.info |= Font::SPECIAL; return facename ? 0 : 1; }
String GetTempPath() { if(IsWinNT()) { wchar h[MAX_PATH]; UnicodeWin32().GetTempPathW(MAX_PATH, h); return FromSystemCharsetW(h); } else { char h[MAX_PATH]; ::GetTempPath(MAX_PATH, h); return FromSystemCharset(h); } }
String GetLocaleInfoA(LCID lcid, LCTYPE lctype) { if(IsWinNT()) { wchar cbuf[1000]; UnicodeWin32().GetLocaleInfoW(lcid, lctype, cbuf, __countof(cbuf)); return FromSystemCharsetW(cbuf); } else { char cbuf[1000]; ::GetLocaleInfoA(lcid, lctype, cbuf, __countof(cbuf)); return FromSystemCharset(cbuf); } }
String GetWindowsDirectory() { if(IsWinNT()) { wchar temp[MAX_PATH]; *temp = 0; UnicodeWin32().GetWindowsDirectoryW(temp, sizeof(temp)); return FromSystemCharsetW(temp); } else { char temp[MAX_PATH]; *temp = 0; ::GetWindowsDirectory(temp, sizeof(temp)); return FromSystemCharset(temp); } }
Array<NetNode> NetNode::Enum0(HANDLE hEnum) { Array<NetNode> r; DWORD cEntries = (DWORD)-1, cbBuffer = 0x4000; Buffer<NETRESOURCE> lpnr(cbBuffer); while(::WNetEnumResource(hEnum, &cEntries, lpnr, &cbBuffer) == 0) { for(int i = 0; i < (int)cEntries; i++) { NETRESOURCE& sn = lpnr[i]; const char *s = sn.lpRemoteName; NetNode& nn = r.Add(); NETRESOURCE& n = nn.net; n = sn; nn.local = n.lpLocalName; nn.remote = n.lpRemoteName; nn.comment = n.lpComment; nn.provider = n.lpProvider; nn.SetPtrs(); if(s) { if(s[0] == '\\' && s[1] == '\\') nn.name = FromSystemCharset(DosInitCaps(GetFileName(s))); else nn.name = FromSystemCharset(s); } if(n.lpComment && *n.lpComment) if(nn.name.GetCount()) nn.name = String().Cat() << FromSystemCharset(n.lpComment) << " (" << nn.name << ")"; else nn.name = FromSystemCharset(n.lpComment); if(!(n.dwUsage & RESOURCEUSAGE_CONTAINER)) nn.path = FromSystemCharset(n.lpRemoteName); } } ::WNetCloseEnum(hEnum); return r; }
String GetFullPath(const char *file) { #ifdef PLATFORM_WIN32 if(IsWinNT()) { String ufn = FromUnixName(file); wchar h[MAX_PATH]; UnicodeWin32().GetFullPathNameW(ToSystemCharsetW(ufn), MAX_PATH, h, 0); return FromSystemCharsetW(h); } else { String ufn = FromUnixName(file); char h[MAX_PATH]; GetFullPathName(ToSystemCharset(ufn), MAX_PATH, h, 0); return FromSystemCharset(h); } #else return NormalizePath(file); #endif }
bool FindFile::Next() { file = false; if(!dir) return false; statis = false; for(;;) { struct dirent *e = readdir(dir); if(!e) { name.Clear(); file = false; Close(); return false; } name = FromSystemCharset(e->d_name); if(PatternMatch(pattern, name)) { file = true; return true; } } }
Vector<WString> SplitCmdLine__(const char *cmd) { Vector<WString> out; while(*cmd) if((byte)*cmd <= ' ') cmd++; else if(*cmd == '\"') { WString quoted; while(*++cmd && (*cmd != '\"' || *++cmd == '\"')) quoted.Cat(FromSystemCharset(String(cmd, 1)).ToWString()); out.Add(quoted); } else { const char *begin = cmd; while((byte)*cmd > ' ') cmd++; out.Add(String(begin, cmd).ToWString()); } return out; }
String GetSystemDirectory() { char temp[MAX_PATH]; *temp = 0; ::GetSystemDirectory(temp, sizeof(temp)); return FromSystemCharset(temp); }
String GetTempPath() { return FromSystemCharset(P_tmpdir); }
Array<FileSystemInfo::FileInfo> FileSystemInfo::Find(String mask, int max_count, bool unmounted) const { Array<FileInfo> fi; if(IsNull(mask)) { // root #ifdef PLATFORM_WINCE FileInfo& f = fi.Add(); f.filename = "\\"; f.root_style = ROOT_FIXED; #elif defined(PLATFORM_WIN32) char drive[4] = "?:\\"; for(int c = 'A'; c <= 'Z'; c++) { *drive = c; int n = GetDriveType(drive); if(n == DRIVE_NO_ROOT_DIR) continue; FileInfo& f = fi.Add(); f.filename = drive; char name[256], system[256]; DWORD d; if(c != 'A' && c != 'B' && n != DRIVE_REMOTE && n != DRIVE_UNKNOWN) { bool b = GetVolumeInformation(drive, name, 256, &d, &d, &d, system, 256); if(b) { if(*name) f.root_desc << " " << FromSystemCharset(name); } else if(n == DRIVE_REMOVABLE || n == DRIVE_CDROM) { if(unmounted) { f.root_desc = t_("Empty drive"); } else { fi.Drop(); continue; } } } switch(n) { default: case DRIVE_UNKNOWN: f.root_style = ROOT_UNKNOWN; break; case DRIVE_NO_ROOT_DIR: f.root_style = ROOT_NO_ROOT_DIR; break; case DRIVE_REMOVABLE: f.root_style = ROOT_REMOVABLE; break; case DRIVE_FIXED: f.root_style = ROOT_FIXED; break; case DRIVE_REMOTE: f.root_style = ROOT_REMOTE; break; case DRIVE_CDROM: f.root_style = ROOT_CDROM; break; case DRIVE_RAMDISK: f.root_style = ROOT_RAMDISK; break; } } #elif defined(PLATFORM_POSIX) FileInfo& f = fi.Add(); f.filename = "/"; f.root_style = ROOT_FIXED; #endif } else { FindFile ff; if(ff.Search(mask)) do { FileInfo& f = fi.Add(); f.filename = ff.GetName(); #ifndef PLATFORM_POSIX f.is_archive = ff.IsArchive(); f.is_compressed = ff.IsCompressed(); f.is_hidden = ff.IsHidden(); f.is_system = ff.IsSystem(); f.is_temporary = ff.IsTemporary(); #endif f.is_read_only = ff.IsReadOnly(); f.length = ff.GetLength(); #ifdef PLATFORM_POSIX f.creation_time = ff.GetLastChangeTime(); f.unix_mode = ff.GetMode(); #endif f.last_access_time = ff.GetLastAccessTime(); f.last_write_time = ff.GetLastWriteTime(); #ifdef PLATFORM_WIN32 f.creation_time = ff.GetCreationTime(); f.unix_mode = 0; #endif f.read_only = ff.IsReadOnly(); f.is_directory = ff.IsDirectory(); f.is_folder = ff.IsFolder(); f.is_file = ff.IsFile(); #ifdef PLATFORM_POSIX f.is_symlink = ff.IsSymLink(); #endif } while(ff.Next() && fi.GetCount() < max_count); } return fi; }
String GetLocaleInfoA(LCID lcid, LCTYPE lctype) { wchar cbuf[1000]; ::GetLocaleInfoW(lcid, lctype, cbuf, __countof(cbuf)); return FromSystemCharset(cbuf); }
String FindFile::GetName() const { return w ? FromSystemCharsetW(w->cFileName) : FromSystemCharset(a->cFileName); }
String GetEnv(const char *id) { return FromSystemCharset(getenv(id)); }