String GetExecutableDirFromSystem() { char Results[FILENAME_MAX]; #ifdef MEZZ_LINUX MaxInt Length = ::readlink("/proc/self/exe", Results, sizeof(Results)-1); if( Length != -1 ) { Results[Length] = '\0'; return DirName(String(Results)); }else{ return ""; } #endif #ifdef MEZZ_WINDOWS GetModuleFileName( NULL, Results, FILENAME_MAX ); return DirName(String(Results)); #endif #ifdef MEZZ_MACOSX uint32_t size = sizeof(Results); if( _NSGetExecutablePath(Results, &size) == 0 ) { return DirName(String(Results)); }else{ return ""; } #endif }
inline bool FindModule(std::string baseName, std::string *fileName, Module *hint) { // Try first in the current directory. if(ExistsFile(baseName)) { *fileName = baseName; return true; } // Now, use the hint. if(hint) { // Check in the same directory as the module. std::string modDir = DirName(hint->GetName().filename); *fileName = JoinPath(modDir, baseName); if(ExistsFile(*fileName)) return true; // Check in the library search path. for(size_t i = 0; i < hint->GetLibraryPathCount(); ++i) { *fileName = JoinPath(hint->GetLibraryPath(i), baseName); if(ExistsFile(*fileName)) return true; } } return false; }
static void _read_watin(void) { /*======================================================*/ /* get the name of the soilwat output definition file. */ /* assume that there is no path prepended to the file * specification in the SOILWAT input files. It might be * nice to allow relative paths, but there's really no need * for it as far as the STEPWAT program is concerned because * all the SOILWAT input files should be in one directory * and that is defined in sxw.in. Thus, we'll treat the * outsetup.in filename as though it has no dirname and * append it to the soilwat input dirname. */ FILE *f; int lineno = 0; Bool found = FALSE; MyFileName = SXW.f_watin; f = OpenFile(MyFileName, "r"); while( GetALine(f, inbuf) ) { if (++lineno == (eOutput + 2)) { strcpy(_swOutDefName, DirName(SXW.f_watin)); strcat(_swOutDefName, inbuf); found = TRUE; break; } } CloseFile(&f); if (!found) { LogError(logfp, LOGFATAL, "%s: Too few files (%d)", MyFileName, lineno); } }
String GetExecutableDirFromArg(int ArgCount, char** ArgVars) { if(ArgCount>0) { if(String("") == BaseName(ArgVars[0])) { // No command is clearly bogus, must bail return ""; } String Results(DirName(ArgVars[0])); // strip ./ ../ .\ ..\ and //String::iterator From=Results.begin(); //for(String::iterator Iter=Results.begin(); Iter!=Results.end();) //{} if( String("") == Results || String("./") == Results || String(".\\") == Results) {// common cases of exe existing but dir is empty return "."; } if(String("")!=Results) { // and exe is empty. return Results; } return String(""); }else{ return String(""); } }
bool TPath::HasAccess(const TCred &cred, enum Access mask) const { struct stat st; int mode; if (!cred.Uid && !access(c_str(), mask & TPath::RWX)) return true; if (stat(c_str(), &st)) { if (!(mask & TPath::P) || errno != ENOENT) return false; TPath dir = DirName(); while (stat(dir.c_str(), &st)) { if (errno != ENOENT) return false; if (dir.Path.size() <= 1) return false; dir = dir.DirName(); } } if ((mask & TPath::U) && cred.Uid == st.st_uid) return true; if (cred.Uid == st.st_uid) mode = st.st_mode >> 6; else if (cred.IsMemberOf(st.st_gid))
gcc_pure static inline bool GetRegularFileInfo(const TCHAR *path, FileInfo &info) { TCHAR buffer[MAX_PATH]; if (!File::Exists(path)) // XXX hack: get parent file's info, just in case this is a // virtual file inside a ZIP archive path = DirName(path, buffer); #ifdef HAVE_POSIX struct stat st; if (stat(path, &st) << 0 || !S_ISREG(st.st_mode)) return false; info.mtime = st.st_mtime; info.size = st.st_size; return true; #else WIN32_FILE_ATTRIBUTE_DATA data; if (!GetFileAttributesEx(path, GetFileExInfoStandard, &data) || (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) return false; info.mtime = FileTimeToInteger(data.ftLastWriteTime); info.size = data.nFileSizeLow | ((uint64_t)data.nFileSizeHigh << 32); return true; #endif }
bool CreateDirRecursive(LPCTSTR path) { bool ret = IsDir(path) || CreateDirectory(path, nullptr); if (!ret) { ret = CreateDirRecursive(DirName(path)) && CreateDirectory(path, nullptr); } return ret; }
CString GetAfxModulePath(bool bWithModuleName/* = false*/) { CString ret = GetModulePath(AfxGetInstanceHandle()); if (!bWithModuleName) { ret = DirName(ret); } return ret; }
CString GetProgramPath(bool bWithExeName/* = false*/) { CString ret = GetModulePath(nullptr); if (!bWithExeName) { ret = DirName(ret); } return ret; }
static void CopyConfigFile(const std::string& installDir, const std::string& sourceConfigPath, size_t skelPrefixLength) { std::string relativeConfigPath = sourceConfigPath.substr(skelPrefixLength); std::string targetConfigPath = installDir + relativeConfigPath; if (!PathExists(targetConfigPath)) { MkDirP(DirName(targetConfigPath)); CopyFile(sourceConfigPath, targetConfigPath); } }
inline void PlaneListWidget::EditClicked() { assert(GetList().GetCursorIndex() < list.size()); const unsigned index = GetList().GetCursorIndex(); const TCHAR *old_path = list[index].path; const TCHAR *old_filename = list[index].name; Plane plane; PlaneGlue::ReadFile(plane, old_path); while (dlgPlaneDetailsShowModal(plane)) { if (plane.registration.empty()) { ShowMessageBox(_("Please enter the registration of the plane!"), _("Error"), MB_OK); continue; } StaticString<42> filename(plane.registration); filename += _T(".xcp"); if (filename != old_filename) { StaticString<MAX_PATH> path; DirName(old_path, path.buffer()); path += _T(DIR_SEPARATOR_S); path += filename; if (File::Exists(path)) { StaticString<256> tmp; tmp.Format(_("Plane \"%s\" already exists. " "Overwrite it?"), plane.registration.c_str()); if (ShowMessageBox(tmp, _("Overwrite"), MB_YESNO) != IDYES) continue; } File::Delete(old_path); PlaneGlue::WriteFile(plane, path); if (Profile::GetPathIsEqual("PlanePath", old_path)) { list[index].path = path; list[index].name = filename; Load(index); } } else { PlaneGlue::WriteFile(plane, old_path); if (Profile::GetPathIsEqual("PlanePath", old_path)) Load(index); } UpdateList(); break; } }
static void EditClicked(gcc_unused WndButton &button) { assert(plane_list->GetCursorIndex() < list.size()); const unsigned index = plane_list->GetCursorIndex(); const TCHAR *old_path = list[index].path; const TCHAR *old_filename = list[index].name; Plane plane; PlaneGlue::ReadFile(plane, old_path); while (dlgPlaneDetailsShowModal(*(SingleWindow*)dialog->get_root_owner(), plane)) { if (plane.registration.empty()) { MessageBoxX(_("Please enter the registration of the plane!"), _("Error"), MB_OK); continue; } StaticString<42> filename(plane.registration); filename += _T(".xcp"); if (filename != old_filename) { StaticString<MAX_PATH> path; DirName(old_path, path.buffer()); path += _T(DIR_SEPARATOR_S); path += filename; if (File::Exists(path)) { StaticString<256> tmp; tmp.Format(_("A plane profile \"%s\" already exists. " "Do you want to overwrite it?"), filename.c_str()); if (MessageBoxX(tmp, _("Overwrite"), MB_YESNO) != IDYES) continue; } File::Delete(old_path); PlaneGlue::WriteFile(plane, path); if (Profile::GetPathIsEqual(_T("PlanePath"), old_path)) { list[index].path = path; list[index].name = filename; Load(index); } } else { PlaneGlue::WriteFile(plane, old_path); if (Profile::GetPathIsEqual(_T("PlanePath"), old_path)) Load(index); } UpdateList(); break; } }
bool dlgStartupShowModal() { LogStartUp(_T("Startup dialog")); logo = new LogoView(); wf = LoadDialog(CallBackTable, XCSoarInterface::main_window, Layout::landscape ? _T("IDR_XML_STARTUP_L") : _T("IDR_XML_STARTUP")); assert(wf != NULL); WndProperty* wp = ((WndProperty *)wf->FindByName(_T("prpProfile"))); assert(wp != NULL); DataFieldFileReader* dfe = (DataFieldFileReader*)wp->GetDataField(); assert(dfe != NULL); ((WndButton *)wf->FindByName(_T("cmdClose"))) ->SetOnClickNotify(OnCloseClicked); ((WndButton *)wf->FindByName(_T("cmdQuit")))->SetOnClickNotify(OnQuit); dfe->ScanDirectoryTop(_T("*.prf")); dfe->Lookup(startProfileFile); wp->RefreshDisplay(); if (dfe->GetNumFiles() <= 2) { delete wf; delete logo; return true; } if (wf->ShowModal() != mrOK) { delete wf; delete logo; return false; } const TCHAR *path = dfe->GetPathFile(); if (!string_is_empty(path)) { _tcscpy(startProfileFile, path); /* When a profile from a secondary data path is used, this path becomes the primary data path */ TCHAR temp[MAX_PATH]; SetPrimaryDataPath(DirName(path, temp)); } delete wf; delete logo; return true; }
static void SelectProfile(const TCHAR *path) { if (string_is_empty(path)) return; Profile::SetFiles(path); /* When a profile from a secondary data path is used, this path becomes the primary data path */ TCHAR temp[MAX_PATH]; SetPrimaryDataPath(DirName(path, temp)); }
static void SelectProfile(const TCHAR *path) { if (StringIsEmpty(path)) return; Profile::SetFiles(path); if (RelativePath(path) == nullptr) { /* When a profile from a secondary data path is used, this path becomes the primary data path */ TCHAR temp[MAX_PATH]; SetPrimaryDataPath(DirName(path, temp)); } File::Touch(path); }
/** * Load topology from a plain file, load the other files from the same * directory. */ static bool LoadConfiguredTopologyFile(TopologyStore &store) { TCHAR file[MAX_PATH]; if (!Profile::GetPath(szProfileTopologyFile, file)) return false; FileLineReaderA reader(file); if (reader.error()) { LogStartUp(_T("No topology file: %s"), file); return false; } TCHAR buffer[MAX_PATH]; const TCHAR *directory = DirName(file, buffer); if (directory == NULL) return false; store.Load(reader, directory); return true; }
ichar * localpath(const ichar *ref, const ichar *name) { ichar *local; if (!ref || is_absolute_path(name)) local = istrdup(name); else { ichar buf[MAXPATHLEN]; DirName(ref, buf); istrcat(buf, DIRSEPSTR); istrcat(buf, name); local = istrdup(buf); } if (!local) sgml_nomem(); return local; }
//----------------------------------------------------------------------------- // Name: MakeDir() // Desc: 実験のファイル保存用のディレクトリを作る // Input: なし // Output: なし //----------------------------------------------------------------------------- void FileOperator::MakeFileDir() { //現在時刻をディレクトリ名に time_t nt; struct tm *t_st; char c[30]; //time(&nt); //現在時刻の取得 //t_st = localtime(&nt); //現在時刻を構造体に変換 localtime_s(t_st,&nt); strftime(c,sizeof(c),"%Y-%m-%d",t_st); //ファイル保存用のpath pass = "******"; // ディレクトリ作成 dirpass = pass; std::string DirName(c); dirpass.insert(dirpass.size(),DirName); CreateDirectory(dirpass.c_str(),NULL); return; }
void SW_F_construct(const char *firstfile) { /* =================================================== */ /* 10-May-02 (cwb) enhancement allows model to be run * in one directory while getting its input from another. * This was done mostly in support of STEPWAT but * it could be useful in a standalone run. */ char *c, *p; init(firstfile); if ((c = DirName(firstfile))) { strcpy(_ProjDir, c); c = (char *) firstfile; p = c + strlen(_ProjDir); while (*p) *(c++) = *(p++); *c = '\0'; } else _ProjDir[0] = '\0'; }
// check size of archive files to get total backed up data size // find all backup image files of a given partition and increment Backup_Size // Backup_Size is set to 0 at start of nandroid_restore() process so that we do not print size progress on void check_restore_size(const char* backup_file_image, const char* backup_path) { // refresh target partition size if (Get_Size_Via_statfs(backup_path) != 0) { Backup_Size = 0; return; } Before_Used_Size = Used_Size; char tmp[PATH_MAX]; char filename[PATH_MAX]; char** files; int numFiles = 0; sprintf(tmp, "%s/", DirName(backup_file_image)); files = gather_files(tmp, "", &numFiles); // if it's a twrp multi volume backup, ensure we remove trailing 000: strlen("000") = 3 if (strlen(backup_file_image) > strlen("win000") && strcmp(backup_file_image + strlen(backup_file_image) - strlen("win000"), "win000") == 0) snprintf(tmp, strlen(backup_file_image) - 3, "%s", backup_file_image); else strcpy(tmp, backup_file_image); sprintf(filename, "%s", BaseName(tmp)); int i; unsigned long fsize; for(i = 0; i < numFiles; i++) { if (strstr(files[i], filename) != NULL) { fsize = Get_File_Size(files[i]); // check if it is a compressed archive and increase size by 45% // this needs a better implementation to do later if (is_gzip_file(files[i]) > 0) fsize += (fsize * 45) / 100; Backup_Size += fsize; } } free_string_array(files); }
Bool RemoveFiles(const char *fspec) { /* delete files matching fspec. ASSUMES terminal element * describes files, ie, is not a directory. * fspec may contain leading path (eg, here/and/now/files) * fspec can't be too complicated because I'm not including the * full regexp library. Specifically you can include a * * anywhere in the terminal path member, * eg: /here/now/fi*les, /here/now/files* * or /here/now/files * Returns TRUE if all files removed, FALSE otherwise. * Check errno if return is FALSE. */ char **flist, fname[1024]; int i, nfiles, dlen, result = TRUE; if (fspec == NULL ) return TRUE; if ((flist = getfiles(fspec, &nfiles))) { strcpy(fname, DirName(fspec)); dlen = strlen(fname); for (i = 0; i < nfiles; i++) { strcpy(fname + dlen, flist[i]); if (0 != remove(fname)) { result = FALSE; break; } } } for (i = 0; i < nfiles; i++) Mem_Free(flist[i]); Mem_Free(flist); return result; }
bool CWII_IPC_HLE_Device_fs::IOCtlV(u32 _CommandAddress) { u32 ReturnValue = FS_RESULT_OK; SIOCtlVBuffer CommandBuffer(_CommandAddress); // Prepare the out buffer(s) with zeros as a safety precaution // to avoid returning bad values for(u32 i = 0; i < CommandBuffer.NumberPayloadBuffer; i++) { Memory::Memset(CommandBuffer.PayloadBuffer[i].m_Address, 0, CommandBuffer.PayloadBuffer[i].m_Size); } switch(CommandBuffer.Parameter) { case IOCTLV_READ_DIR: { // the wii uses this function to define the type (dir or file) std::string DirName(HLE_IPC_BuildFilename((const char*)Memory::GetPointer( CommandBuffer.InBuffer[0].m_Address), CommandBuffer.InBuffer[0].m_Size)); INFO_LOG(WII_IPC_FILEIO, "FS: IOCTL_READ_DIR %s", DirName.c_str()); if (!File::Exists(DirName)) { WARN_LOG(WII_IPC_FILEIO, "FS: Search not found: %s", DirName.c_str()); ReturnValue = FS_FILE_NOT_EXIST; break; } else if (!File::IsDirectory(DirName)) { // It's not a directory, so error. // Games don't usually seem to care WHICH error they get, as long as it's < // Well the system menu CARES! WARN_LOG(WII_IPC_FILEIO, "\tNot a directory - return FS_RESULT_FATAL"); ReturnValue = FS_RESULT_FATAL; break; } // make a file search CFileSearch::XStringVector Directories; Directories.push_back(DirName); CFileSearch::XStringVector Extensions; Extensions.push_back("*.*"); CFileSearch FileSearch(Extensions, Directories); // it is one if ((CommandBuffer.InBuffer.size() == 1) && (CommandBuffer.PayloadBuffer.size() == 1)) { size_t numFile = FileSearch.GetFileNames().size(); INFO_LOG(WII_IPC_FILEIO, "\t%lu files found", (unsigned long)numFile); Memory::Write_U32((u32)numFile, CommandBuffer.PayloadBuffer[0].m_Address); } else { u32 MaxEntries = Memory::Read_U32(CommandBuffer.InBuffer[0].m_Address); memset(Memory::GetPointer(CommandBuffer.PayloadBuffer[0].m_Address), 0, CommandBuffer.PayloadBuffer[0].m_Size); size_t numFiles = 0; char* pFilename = (char*)Memory::GetPointer((u32)(CommandBuffer.PayloadBuffer[0].m_Address)); for (size_t i=0; i<FileSearch.GetFileNames().size(); i++) { if (i >= MaxEntries) break; std::string name, ext; SplitPath(FileSearch.GetFileNames()[i], NULL, &name, &ext); std::string FileName = name + ext; // Decode entities of invalid file system characters so that // games (such as HP:HBP) will be able to find what they expect. for (const Common::replace_t& r : replacements) { for (size_t j = 0; (j = FileName.find(r.second, j)) != FileName.npos; ++j) FileName.replace(j, r.second.length(), 1, r.first); } strcpy(pFilename, FileName.c_str()); pFilename += FileName.length(); *pFilename++ = 0x00; // termination numFiles++; INFO_LOG(WII_IPC_FILEIO, "\tFound: %s", FileName.c_str()); } Memory::Write_U32((u32)numFiles, CommandBuffer.PayloadBuffer[1].m_Address); } ReturnValue = FS_RESULT_OK; } break; case IOCTLV_GETUSAGE: { _dbg_assert_(WII_IPC_FILEIO, CommandBuffer.PayloadBuffer.size() == 2); _dbg_assert_(WII_IPC_FILEIO, CommandBuffer.PayloadBuffer[0].m_Size == 4); _dbg_assert_(WII_IPC_FILEIO, CommandBuffer.PayloadBuffer[1].m_Size == 4); // this command sucks because it asks of the number of used // fsBlocks and inodes // It should be correct, but don't count on it... const char *relativepath = (const char*)Memory::GetPointer(CommandBuffer.InBuffer[0].m_Address); std::string path(HLE_IPC_BuildFilename(relativepath, CommandBuffer.InBuffer[0].m_Size)); u32 fsBlocks = 0; u32 iNodes = 0; INFO_LOG(WII_IPC_FILEIO, "IOCTL_GETUSAGE %s", path.c_str()); if (File::IsDirectory(path)) { // LPFaint99: After I found that setting the number of inodes to the number of children + 1 for the directory itself // I decided to compare with sneek which has the following 2 special cases which are // Copyright (C) 2009-2011 crediar http://code.google.com/p/sneek/ if ((memcmp(relativepath, "/title/00010001", 16 ) == 0 ) || (memcmp(relativepath, "/title/00010005", 16) == 0 )) { fsBlocks = 23; // size is size/0x4000 iNodes = 42; // empty folders return a FileCount of 1 } else { File::FSTEntry parentDir; // add one for the folder itself, allows some games to create their save files // R8XE52 (Jurassic: The Hunted), STEETR (Tetris Party Deluxe) now create their saves with this change iNodes = 1 + File::ScanDirectoryTree(path, parentDir); u64 totalSize = ComputeTotalFileSize(parentDir); // "Real" size, to be converted to nand blocks fsBlocks = (u32)(totalSize / (16 * 1024)); // one bock is 16kb } ReturnValue = FS_RESULT_OK; INFO_LOG(WII_IPC_FILEIO, "FS: fsBlock: %i, iNodes: %i", fsBlocks, iNodes); } else { fsBlocks = 0; iNodes = 0; ReturnValue = FS_RESULT_OK; WARN_LOG(WII_IPC_FILEIO, "FS: fsBlock failed, cannot find directory: %s", path.c_str()); } Memory::Write_U32(fsBlocks, CommandBuffer.PayloadBuffer[0].m_Address); Memory::Write_U32(iNodes, CommandBuffer.PayloadBuffer[1].m_Address); } break; default: PanicAlert("CWII_IPC_HLE_Device_fs::IOCtlV: %i", CommandBuffer.Parameter); break; } Memory::Write_U32(ReturnValue, _CommandAddress+4); return true; }
s32 CWII_IPC_HLE_Device_fs::ExecuteCommand(u32 _Parameter, u32 _BufferIn, u32 _BufferInSize, u32 _BufferOut, u32 _BufferOutSize) { switch(_Parameter) { case IOCTL_GET_STATS: { if (_BufferOutSize < 0x1c) return -1017; WARN_LOG(WII_IPC_FILEIO, "FS: GET STATS - returning static values for now"); NANDStat fs; //TODO: scrape the real amounts from somewhere... fs.BlockSize = 0x4000; fs.FreeUserBlocks = 0x5DEC; fs.UsedUserBlocks = 0x1DD4; fs.FreeSysBlocks = 0x10; fs.UsedSysBlocks = 0x02F0; fs.Free_INodes = 0x146B; fs.Used_Inodes = 0x0394; *(NANDStat*)Memory::GetPointer(_BufferOut) = fs; return FS_RESULT_OK; } break; case IOCTL_CREATE_DIR: { _dbg_assert_(WII_IPC_FILEIO, _BufferOutSize == 0); u32 Addr = _BufferIn; u32 OwnerID = Memory::Read_U32(Addr); Addr += 4; u16 GroupID = Memory::Read_U16(Addr); Addr += 2; std::string DirName(HLE_IPC_BuildFilename((const char*)Memory::GetPointer(Addr), 64)); Addr += 64; Addr += 9; // owner attribs, permission u8 Attribs = Memory::Read_U8(Addr); INFO_LOG(WII_IPC_FILEIO, "FS: CREATE_DIR %s, OwnerID %#x, GroupID %#x, Attributes %#x", DirName.c_str(), OwnerID, GroupID, Attribs); DirName += DIR_SEP; File::CreateFullPath(DirName); _dbg_assert_msg_(WII_IPC_FILEIO, File::IsDirectory(DirName), "FS: CREATE_DIR %s failed", DirName.c_str()); return FS_RESULT_OK; } break; case IOCTL_SET_ATTR: { u32 Addr = _BufferIn; u32 OwnerID = Memory::Read_U32(Addr); Addr += 4; u16 GroupID = Memory::Read_U16(Addr); Addr += 2; std::string Filename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn), 64); Addr += 64; u8 OwnerPerm = Memory::Read_U8(Addr); Addr += 1; u8 GroupPerm = Memory::Read_U8(Addr); Addr += 1; u8 OtherPerm = Memory::Read_U8(Addr); Addr += 1; u8 Attributes = Memory::Read_U8(Addr); Addr += 1; INFO_LOG(WII_IPC_FILEIO, "FS: SetAttrib %s", Filename.c_str()); DEBUG_LOG(WII_IPC_FILEIO, " OwnerID: 0x%08x", OwnerID); DEBUG_LOG(WII_IPC_FILEIO, " GroupID: 0x%04x", GroupID); DEBUG_LOG(WII_IPC_FILEIO, " OwnerPerm: 0x%02x", OwnerPerm); DEBUG_LOG(WII_IPC_FILEIO, " GroupPerm: 0x%02x", GroupPerm); DEBUG_LOG(WII_IPC_FILEIO, " OtherPerm: 0x%02x", OtherPerm); DEBUG_LOG(WII_IPC_FILEIO, " Attributes: 0x%02x", Attributes); return FS_RESULT_OK; } break; case IOCTL_GET_ATTR: { _dbg_assert_msg_(WII_IPC_FILEIO, _BufferOutSize == 76, " GET_ATTR needs an 76 bytes large output buffer but it is %i bytes large", _BufferOutSize); u32 OwnerID = 0; u16 GroupID = 0x3031; // this is also known as makercd, 01 (0x3031) for nintendo and 08 (0x3038) for MH3 etc std::string Filename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn), 64); u8 OwnerPerm = 0x3; // read/write u8 GroupPerm = 0x3; // read/write u8 OtherPerm = 0x3; // read/write u8 Attributes = 0x00; // no attributes if (File::IsDirectory(Filename)) { INFO_LOG(WII_IPC_FILEIO, "FS: GET_ATTR Directory %s - all permission flags are set", Filename.c_str()); } else { if (File::Exists(Filename)) { INFO_LOG(WII_IPC_FILEIO, "FS: GET_ATTR %s - all permission flags are set", Filename.c_str()); } else { INFO_LOG(WII_IPC_FILEIO, "FS: GET_ATTR unknown %s", Filename.c_str()); return FS_FILE_NOT_EXIST; } } // write answer to buffer if (_BufferOutSize == 76) { u32 Addr = _BufferOut; Memory::Write_U32(OwnerID, Addr); Addr += 4; Memory::Write_U16(GroupID, Addr); Addr += 2; memcpy(Memory::GetPointer(Addr), Memory::GetPointer(_BufferIn), 64); Addr += 64; Memory::Write_U8(OwnerPerm, Addr); Addr += 1; Memory::Write_U8(GroupPerm, Addr); Addr += 1; Memory::Write_U8(OtherPerm, Addr); Addr += 1; Memory::Write_U8(Attributes, Addr); Addr += 1; } return FS_RESULT_OK; } break; case IOCTL_DELETE_FILE: { _dbg_assert_(WII_IPC_FILEIO, _BufferOutSize == 0); int Offset = 0; std::string Filename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn+Offset), 64); Offset += 64; if (File::Delete(Filename)) { INFO_LOG(WII_IPC_FILEIO, "FS: DeleteFile %s", Filename.c_str()); } else if (File::DeleteDir(Filename)) { INFO_LOG(WII_IPC_FILEIO, "FS: DeleteDir %s", Filename.c_str()); } else { WARN_LOG(WII_IPC_FILEIO, "FS: DeleteFile %s - failed!!!", Filename.c_str()); } return FS_RESULT_OK; } break; case IOCTL_RENAME_FILE: { _dbg_assert_(WII_IPC_FILEIO, _BufferOutSize == 0); int Offset = 0; std::string Filename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn+Offset), 64); Offset += 64; std::string FilenameRename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn+Offset), 64); Offset += 64; // try to make the basis directory File::CreateFullPath(FilenameRename); // if there is already a file, delete it if (File::Exists(Filename) && File::Exists(FilenameRename)) { File::Delete(FilenameRename); } // finally try to rename the file if (File::Rename(Filename, FilenameRename)) { INFO_LOG(WII_IPC_FILEIO, "FS: Rename %s to %s", Filename.c_str(), FilenameRename.c_str()); } else { ERROR_LOG(WII_IPC_FILEIO, "FS: Rename %s to %s - failed", Filename.c_str(), FilenameRename.c_str()); return FS_FILE_NOT_EXIST; } return FS_RESULT_OK; } break; case IOCTL_CREATE_FILE: { _dbg_assert_(WII_IPC_FILEIO, _BufferOutSize == 0); u32 Addr = _BufferIn; u32 OwnerID = Memory::Read_U32(Addr); Addr += 4; u16 GroupID = Memory::Read_U16(Addr); Addr += 2; std::string Filename(HLE_IPC_BuildFilename((const char*)Memory::GetPointer(Addr), 64)); Addr += 64; u8 OwnerPerm = Memory::Read_U8(Addr); Addr++; u8 GroupPerm = Memory::Read_U8(Addr); Addr++; u8 OtherPerm = Memory::Read_U8(Addr); Addr++; u8 Attributes = Memory::Read_U8(Addr); Addr++; INFO_LOG(WII_IPC_FILEIO, "FS: CreateFile %s", Filename.c_str()); DEBUG_LOG(WII_IPC_FILEIO, " OwnerID: 0x%08x", OwnerID); DEBUG_LOG(WII_IPC_FILEIO, " GroupID: 0x%04x", GroupID); DEBUG_LOG(WII_IPC_FILEIO, " OwnerPerm: 0x%02x", OwnerPerm); DEBUG_LOG(WII_IPC_FILEIO, " GroupPerm: 0x%02x", GroupPerm); DEBUG_LOG(WII_IPC_FILEIO, " OtherPerm: 0x%02x", OtherPerm); DEBUG_LOG(WII_IPC_FILEIO, " Attributes: 0x%02x", Attributes); // check if the file already exist if (File::Exists(Filename)) { WARN_LOG(WII_IPC_FILEIO, "\tresult = FS_RESULT_EXISTS"); return FS_FILE_EXIST; } // create the file File::CreateFullPath(Filename); // just to be sure bool Result = File::CreateEmptyFile(Filename); if (!Result) { ERROR_LOG(WII_IPC_FILEIO, "CWII_IPC_HLE_Device_fs: couldn't create new file"); PanicAlert("CWII_IPC_HLE_Device_fs: couldn't create new file"); return FS_RESULT_FATAL; } INFO_LOG(WII_IPC_FILEIO, "\tresult = FS_RESULT_OK"); return FS_RESULT_OK; } break; case IOCTL_SHUTDOWN: { INFO_LOG(WII_IPC_FILEIO, "Wii called Shutdown()"); // TODO: stop emulation } break; default: ERROR_LOG(WII_IPC_FILEIO, "CWII_IPC_HLE_Device_fs::IOCtl: ni 0x%x", _Parameter); PanicAlert("CWII_IPC_HLE_Device_fs::IOCtl: ni 0x%x", _Parameter); break; } return FS_RESULT_FATAL; }
void dlgWayPointDetailsShowModal(SingleWindow &parent, const Waypoint& way_point, bool allow_navigation) { const NMEA_INFO &basic = CommonInterface::Basic(); const DERIVED_INFO &calculated = CommonInterface::Calculated(); const SETTINGS_COMPUTER &settings_computer = CommonInterface::SettingsComputer(); selected_waypoint = &way_point; wf = LoadDialog(CallBackTable, parent, Layout::landscape ? _T("IDR_XML_WAYPOINTDETAILS_L") : _T("IDR_XML_WAYPOINTDETAILS")); assert(wf != NULL); nTextLines = 0; TCHAR buffer[MAX_PATH]; const TCHAR *Directory = NULL; if (Profile::GetPath(szProfileWayPointFile, szWaypointFile)) Directory = DirName(szWaypointFile, buffer); if (Directory == NULL) Directory = _T(""); _stprintf(path_modis, _T("%s" DIR_SEPARATOR_S "modis-%03d.jpg"), Directory, selected_waypoint->original_id); _stprintf(path_google,_T("%s" DIR_SEPARATOR_S "google-%03d.jpg"), Directory, selected_waypoint->original_id); TCHAR sTmp[128]; _stprintf(sTmp, _T("%s: '%s'"), wf->GetCaption(), selected_waypoint->Name.c_str()); wf->SetCaption(sTmp); WndProperty *wp; wp = ((WndProperty *)wf->FindByName(_T("prpWpComment"))); wp->SetText(selected_waypoint->Comment.c_str()); Units::LongitudeToString(selected_waypoint->Location.Longitude, sTmp, sizeof(sTmp)-1); ((WndProperty *)wf->FindByName(_T("prpLongitude"))) ->SetText(sTmp); Units::LatitudeToString(selected_waypoint->Location.Latitude, sTmp, sizeof(sTmp)-1); ((WndProperty *)wf->FindByName(_T("prpLatitude"))) ->SetText(sTmp); Units::FormatUserAltitude(selected_waypoint->Altitude, sTmp, sizeof(sTmp)-1); ((WndProperty *)wf->FindByName(_T("prpAltitude"))) ->SetText(sTmp); SunEphemeris sun; sun.CalcSunTimes(selected_waypoint->Location, basic.DateTime, fixed(GetUTCOffset()) / 3600); int sunsethours = (int)sun.TimeOfSunSet; int sunsetmins = (int)((sun.TimeOfSunSet - fixed(sunsethours)) * 60); _stprintf(sTmp, _T("%02d:%02d"), sunsethours, sunsetmins); ((WndProperty *)wf->FindByName(_T("prpSunset")))->SetText(sTmp); GeoVector gv = basic.Location.distance_bearing(selected_waypoint->Location); TCHAR DistanceText[MAX_PATH]; Units::FormatUserDistance(gv.Distance, DistanceText, 10); ((WndProperty *)wf->FindByName(_T("prpDistance"))) ->SetText(DistanceText); _stprintf(sTmp, _T("%d")_T(DEG), iround(gv.Bearing.value_degrees())); ((WndProperty *)wf->FindByName(_T("prpBearing"))) ->SetText(sTmp); if (protected_task_manager != NULL) { GlidePolar glide_polar = settings_computer.glide_polar_task; const GlidePolar &safety_polar = calculated.glide_polar_safety; UnorderedTaskPoint t(way_point, settings_computer); GlideResult r; // alt reqd at current mc const AIRCRAFT_STATE aircraft_state = ToAircraftState(basic, calculated); r = TaskSolution::glide_solution_remaining(t, aircraft_state, glide_polar); wp = (WndProperty *)wf->FindByName(_T("prpMc2")); if (wp) { _stprintf(sTmp, _T("%.0f %s"), (double)Units::ToUserAltitude(r.AltitudeDifference), Units::GetAltitudeName()); wp->SetText(sTmp); } // alt reqd at mc 0 glide_polar.set_mc(fixed_zero); r = TaskSolution::glide_solution_remaining(t, aircraft_state, glide_polar); wp = (WndProperty *)wf->FindByName(_T("prpMc0")); if (wp) { _stprintf(sTmp, _T("%.0f %s"), (double)Units::ToUserAltitude(r.AltitudeDifference), Units::GetAltitudeName()); wp->SetText(sTmp); } // alt reqd at safety mc r = TaskSolution::glide_solution_remaining(t, aircraft_state, safety_polar); wp = (WndProperty *)wf->FindByName(_T("prpMc1")); if (wp) { _stprintf(sTmp, _T("%.0f %s"), (double)Units::ToUserAltitude(r.AltitudeDifference), Units::GetAltitudeName()); wp->SetText(sTmp); } } wf->SetKeyDownNotify(FormKeyDown); ((WndButton *)wf->FindByName(_T("cmdClose")))->SetOnClickNotify(OnCloseClicked); wInfo = ((WndFrame *)wf->FindByName(_T("frmInfos"))); wCommand = ((WndFrame *)wf->FindByName(_T("frmCommands"))); wImage = ((WndOwnerDrawFrame *)wf->FindByName(_T("frmImage"))); wDetails = (WndListFrame*)wf->FindByName(_T("frmDetails")); wDetails->SetPaintItemCallback(OnPaintDetailsListItem); assert(wInfo != NULL); assert(wCommand != NULL); assert(wImage != NULL); assert(wDetails != NULL); nTextLines = TextToLineOffsets(way_point.Details.c_str(), LineOffsets, MAXLINES); wDetails->SetLength(nTextLines); wCommand->hide(); wImage->SetOnPaintNotify(OnImagePaint); if (!allow_navigation) { WndButton* butnav = NULL; butnav = (WndButton *)wf->FindByName(_T("cmdPrev")); assert(butnav); butnav->hide(); butnav = (WndButton *)wf->FindByName(_T("cmdNext")); assert(butnav); butnav->hide(); butnav = (WndButton *)wf->FindByName(_T("cmdGoto")); assert(butnav); butnav->hide(); } WndButton *wb; wb = ((WndButton *)wf->FindByName(_T("cmdGoto"))); if (wb) wb->SetOnClickNotify(OnGotoClicked); wb = ((WndButton *)wf->FindByName(_T("cmdReplace"))); if (wb) wb->SetOnClickNotify(OnReplaceClicked); wb = ((WndButton *)wf->FindByName(_T("cmdNewHome"))); if (wb) wb->SetOnClickNotify(OnNewHomeClicked); wb = ((WndButton *)wf->FindByName(_T("cmdInserInTask"))); if (wb) wb->SetOnClickNotify(OnInsertInTaskClicked); wb = ((WndButton *)wf->FindByName(_T("cmdAppendInTask"))); if (wb) wb->SetOnClickNotify(OnAppendInTaskClicked); wb = ((WndButton *)wf->FindByName(_T("cmdRemoveFromTask"))); if (wb) wb->SetOnClickNotify(OnRemoveFromTaskClicked); /* JMW disabled until 6.2 work, see #996 wb = ((WndButton *)wf->FindByName(_T("cmdGotoAndClearTask"))); if (wb) wb->SetOnClickNotify(OnGotoAndClearTaskClicked); */ wb = ((WndButton *)wf->FindByName(_T("cmdActivatePan"))); if (wb) wb->SetOnClickNotify(OnActivatePanClicked); hasimage1 = jpgimage1.load_file(path_modis); hasimage2 = jpgimage2.load_file(path_google); page = 0; NextPage(0); // JMW just to turn proper pages on/off wf->ShowModal(); delete wf; jpgimage1.reset(); jpgimage2.reset(); }
static char * findHome(const char *symbols, int argc, const char **argv) { const char *home = NULL; char envbuf[MAXPATHLEN]; char plp[MAXPATHLEN]; const char *val; if ( (val=longopt("home", argc, argv)) ) { if ( (home=PrologPath(val, plp, sizeof(plp))) ) return store_string(home); return NULL; } if ( (val = exec_var("homevar")) && (home = Getenv(val, envbuf, sizeof(envbuf))) && (home = PrologPath(home, plp, sizeof(plp))) ) return store_string(home); if ( (val = exec_var("home")) && (home = PrologPath(val, plp, sizeof(plp))) ) return store_string(home); #ifdef PLHOMEVAR_1 if ( !(home = Getenv(PLHOMEVAR_1, envbuf, sizeof(envbuf))) ) { #ifdef PLHOMEVAR_2 home = Getenv(PLHOMEVAR_2, envbuf, sizeof(envbuf)); #endif } if ( home && (home = PrologPath(home, plp, sizeof(plp))) && ExistsDirectory(home) ) return store_string(home); #endif #ifdef PLHOMEFILE if ( (home = symbols) ) { char buf[MAXPATHLEN]; char parent[MAXPATHLEN]; IOSTREAM *fd; strcpy(parent, DirName(DirName(AbsoluteFile(home, buf), buf), buf)); Ssprintf(buf, "%s/" PLHOMEFILE, parent); if ( (fd = Sopen_file(buf, "r")) ) { if ( Sfgets(buf, sizeof(buf), fd) ) { size_t l = strlen(buf); while(l > 0 && buf[l-1] <= ' ') l--; buf[l] = EOS; #if O_XOS { char buf2[MAXPATHLEN]; _xos_canonical_filename(buf, buf2, MAXPATHLEN, 0); strcpy(buf, buf2); } #endif if ( !IsAbsolutePath(buf) ) { char buf2[MAXPATHLEN]; Ssprintf(buf2, "%s/%s", parent, buf); home = AbsoluteFile(buf2, plp); } else home = AbsoluteFile(buf, plp); if ( ExistsDirectory(home) ) { Sclose(fd); return store_string(home); } } Sclose(fd); } } #endif /*PLHOMEFILE*/ if ( (home = PrologPath(PLHOME, plp, sizeof(plp))) && ExistsDirectory(home) ) return store_string(home); return NULL; }
// custom raw restore handler // used to restore efs in raw mode or modem.bin files // for now, only called directly from outside functions (not from nandroid_restore()) // user selects an image file to restore, so backup_file_image path is already mounted int dd_raw_restore_handler(const char* backup_file_image, const char* root) { ui_print("\n>> Restoring %s...\n", root); Volume *vol = volume_for_path(root); if (vol == NULL || vol->fs_type == NULL) { ui_print("volume not found! Skipping raw restore of %s...\n", root); return 0; } ui_set_background(BACKGROUND_ICON_INSTALLING); ui_show_indeterminate_progress(); // make sure we have a valid image file name int i = 0; char errmsg[PATH_MAX]; char tmp[PATH_MAX]; char filename[PATH_MAX]; const char *raw_image_format[] = { ".img", ".bin", NULL }; sprintf(filename, "%s", BaseName(backup_file_image)); while (raw_image_format[i] != NULL) { if (strlen(filename) > strlen(raw_image_format[i]) && strcmp(filename + strlen(filename) - strlen(raw_image_format[i]), raw_image_format[i]) == 0 && strncmp(filename, vol->mount_point + 1, strlen(vol->mount_point)-1) == 0) { break; } i++; } if (raw_image_format[i] == NULL) { sprintf(errmsg, "invalid image file! Failed to restore %s to %s\n", filename, root); return print_and_error(errmsg, NANDROID_ERROR_GENERAL); } //make sure file exists if (!file_found(backup_file_image)) { sprintf(errmsg, "%s not found. Skipping restore of %s\n", backup_file_image, root); return print_and_error(errmsg, NANDROID_ERROR_GENERAL); } //restore raw image int ret = 0; char* device_mmcblk; ui_print("Restoring %s to %s\n", filename, vol->mount_point); if (strstr(vol->blk_device, "/dev/block/mmcblk") != NULL || strstr(vol->blk_device, "/dev/block/mtdblock") != NULL) { sprintf(tmp, "raw-backup.sh -r '%s' %s %s", backup_file_image, vol->blk_device, vol->mount_point); } else if (vol->blk_device2 != NULL && (strstr(vol->blk_device2, "/dev/block/mmcblk") != NULL || strstr(vol->blk_device2, "/dev/block/mtdblock") != NULL)) { sprintf(tmp, "raw-backup.sh -r '%s' %s %s", backup_file_image, vol->blk_device2, vol->mount_point); } else if ((device_mmcblk = readlink_device_blk(root)) != NULL) { sprintf(tmp, "raw-backup.sh -r '%s' %s %s", backup_file_image, device_mmcblk, vol->mount_point); free(device_mmcblk); } else { sprintf(errmsg, "raw restore: no device found (%s)\n", root); return print_and_error(errmsg, NANDROID_ERROR_GENERAL); } ret = __system(tmp); if (0 != ret) { sprintf(errmsg, "failed raw restore of %s to %s\n", filename, root); print_and_error(errmsg, ret); } else { finish_nandroid_job(); } sprintf(tmp, "%s/log.txt", DirName(backup_file_image)); ui_print_custom_logtail(tmp, 3); return ret; }
void dlgWayPointDetailsShowModal(SingleWindow &parent, const Waypoint& way_point) { selected_waypoint = &way_point; TCHAR sTmp[128]; int sunsethours; int sunsetmins; WndProperty *wp; wf = LoadDialog(CallBackTable, parent, Layout::landscape ? _T("IDR_XML_WAYPOINTDETAILS_L") : _T("IDR_XML_WAYPOINTDETAILS")); if (!wf) return; nTextLines = 0; TCHAR buffer[MAX_PATH]; const TCHAR *Directory = NULL; if (Profile::GetPath(szProfileWayPointFile, szWaypointFile)) Directory = DirName(szWaypointFile, buffer); if (Directory == NULL) Directory = _T(""); _stprintf(path_modis, _T("%s" DIR_SEPARATOR_S "modis-%03d.jpg"), Directory, selected_waypoint->id+1); _stprintf(path_google,_T("%s" DIR_SEPARATOR_S "google-%03d.jpg"), Directory, selected_waypoint->id+1); _stprintf(sTmp, _T("%s: '%s'"), wf->GetCaption(), selected_waypoint->Name.c_str()); wf->SetCaption(sTmp); wp = ((WndProperty *)wf->FindByName(_T("prpWpComment"))); wp->SetText(selected_waypoint->Comment.c_str()); Units::LongitudeToString(selected_waypoint->Location.Longitude, sTmp, sizeof(sTmp)-1); ((WndProperty *)wf->FindByName(_T("prpLongitude"))) ->SetText(sTmp); Units::LatitudeToString(selected_waypoint->Location.Latitude, sTmp, sizeof(sTmp)-1); ((WndProperty *)wf->FindByName(_T("prpLatitude"))) ->SetText(sTmp); Units::FormatUserAltitude(selected_waypoint->Altitude, sTmp, sizeof(sTmp)-1); ((WndProperty *)wf->FindByName(_T("prpAltitude"))) ->SetText(sTmp); SunEphemeris sun; sun.CalcSunTimes(selected_waypoint->Location, XCSoarInterface::Basic().DateTime, fixed(GetUTCOffset()) / 3600); sunsethours = (int)sun.TimeOfSunSet; sunsetmins = (int)((sun.TimeOfSunSet - fixed(sunsethours)) * 60); _stprintf(sTmp, _T("%02d:%02d"), sunsethours, sunsetmins); ((WndProperty *)wf->FindByName(_T("prpSunset")))->SetText(sTmp); fixed distance; Angle bearing; DistanceBearing(XCSoarInterface::Basic().Location, selected_waypoint->Location, &distance, &bearing); TCHAR DistanceText[MAX_PATH]; Units::FormatUserDistance(distance, DistanceText, 10); ((WndProperty *)wf->FindByName(_T("prpDistance"))) ->SetText(DistanceText); _stprintf(sTmp, _T("%d")_T(DEG), iround(bearing.value_degrees())); ((WndProperty *)wf->FindByName(_T("prpBearing"))) ->SetText(sTmp); GlidePolar glide_polar = protected_task_manager.get_glide_polar(); GlidePolar safety_polar = protected_task_manager.get_safety_polar(); UnorderedTaskPoint t(way_point, XCSoarInterface::SettingsComputer()); GlideResult r; // alt reqd at current mc const AIRCRAFT_STATE aircraft_state = ToAircraftState(XCSoarInterface::Basic()); r = TaskSolution::glide_solution_remaining(t, aircraft_state, glide_polar); wp = (WndProperty *)wf->FindByName(_T("prpMc2")); if (wp) { _stprintf(sTmp, _T("%.0f %s"), (double)Units::ToUserAltitude(r.AltitudeDifference), Units::GetAltitudeName()); wp->SetText(sTmp); } // alt reqd at mc 0 glide_polar.set_mc(fixed_zero); r = TaskSolution::glide_solution_remaining(t, aircraft_state, glide_polar); wp = (WndProperty *)wf->FindByName(_T("prpMc0")); if (wp) { _stprintf(sTmp, _T("%.0f %s"), (double)Units::ToUserAltitude(r.AltitudeDifference), Units::GetAltitudeName()); wp->SetText(sTmp); } // alt reqd at safety mc r = TaskSolution::glide_solution_remaining(t, aircraft_state, safety_polar); wp = (WndProperty *)wf->FindByName(_T("prpMc1")); if (wp) { _stprintf(sTmp, _T("%.0f %s"), (double)Units::ToUserAltitude(r.AltitudeDifference), Units::GetAltitudeName()); wp->SetText(sTmp); } wf->SetKeyDownNotify(FormKeyDown); ((WndButton *)wf->FindByName(_T("cmdClose")))->SetOnClickNotify(OnCloseClicked); wInfo = ((WndFrame *)wf->FindByName(_T("frmInfos"))); wCommand = ((WndFrame *)wf->FindByName(_T("frmCommands"))); wSpecial = ((WndFrame *)wf->FindByName(_T("frmSpecial"))); wImage = ((WndOwnerDrawFrame *)wf->FindByName(_T("frmImage"))); wDetails = (WndListFrame*)wf->FindByName(_T("frmDetails")); wDetails->SetPaintItemCallback(OnPaintDetailsListItem); assert(wInfo != NULL); assert(wCommand != NULL); assert(wSpecial != NULL); assert(wImage != NULL); assert(wDetails != NULL); nTextLines = TextToLineOffsets(way_point.Details.c_str(), LineOffsets, MAXLINES); wDetails->SetLength(nTextLines); /* TODO enhancement: wpdetails wp = ((WndProperty *)wf->FindByName(_T("prpWpDetails"))); wp->SetText(way_point.Details); */ wCommand->hide(); wSpecial->hide(); wImage->SetCaption(_("Blank!")); wImage->SetOnPaintNotify(OnImagePaint); WndButton *wb; wb = ((WndButton *)wf->FindByName(_T("cmdGoto"))); if (wb) wb->SetOnClickNotify(OnGotoClicked); wb = ((WndButton *)wf->FindByName(_T("cmdReplace"))); if (wb) wb->SetOnClickNotify(OnReplaceClicked); wb = ((WndButton *)wf->FindByName(_T("cmdNewHome"))); if (wb) wb->SetOnClickNotify(OnNewHomeClicked); wb = ((WndButton *)wf->FindByName(_T("cmdSetAlternate1"))); if (wb) wb->SetOnClickNotify(OnSetAlternate1Clicked); wb = ((WndButton *)wf->FindByName(_T("cmdSetAlternate2"))); if (wb) wb->SetOnClickNotify(OnSetAlternate2Clicked); wb = ((WndButton *)wf->FindByName(_T("cmdClearAlternates"))); if (wb) wb->SetOnClickNotify(OnClearAlternatesClicked); wb = ((WndButton *)wf->FindByName(_T("cmdTeamCode"))); if (wb) wb->SetOnClickNotify(OnTeamCodeClicked); wb = ((WndButton *)wf->FindByName(_T("cmdInserInTask"))); if (wb) wb->SetOnClickNotify(OnInsertInTaskClicked); wb = ((WndButton *)wf->FindByName(_T("cmdAppendInTask"))); if (wb) wb->SetOnClickNotify(OnAppendInTaskClicked); wb = ((WndButton *)wf->FindByName(_T("cmdRemoveFromTask"))); if (wb) wb->SetOnClickNotify(OnRemoveFromTaskClicked); hasimage1 = jpgimage1.load_file(path_modis); hasimage2 = jpgimage2.load_file(path_google); page = 0; NextPage(0); // JMW just to turn proper pages on/off wf->ShowModal(); delete wf; wf = NULL; }
static int test(const char* path, const char* expect) { char buffer[EXECUTOR_BUFFER_SIZE]; DirName(path, buffer); return strcmp(buffer, expect) == 0 ? 0 : -1; }
void TracePC::PrintCoverage() { if (!EF->__sanitizer_symbolize_pc || !EF->__sanitizer_get_module_and_offset_for_pc) { Printf("INFO: __sanitizer_symbolize_pc or " "__sanitizer_get_module_and_offset_for_pc is not available," " not printing coverage\n"); return; } std::map<std::string, std::vector<uintptr_t>> CoveredPCsPerModule; std::map<std::string, uintptr_t> ModuleOffsets; std::set<std::string> CoveredDirs, CoveredFiles, CoveredFunctions, CoveredLines; Printf("COVERAGE:\n"); for (size_t i = 1; i < GetNumPCs(); i++) { if (!PCs[i]) continue; std::string FileStr = DescribePC("%s", PCs[i]); if (!IsInterestingCoverageFile(FileStr)) continue; std::string FixedPCStr = DescribePC("%p", PCs[i]); std::string FunctionStr = DescribePC("%F", PCs[i]); std::string LineStr = DescribePC("%l", PCs[i]); char ModulePathRaw[4096] = ""; // What's PATH_MAX in portable C++? void *OffsetRaw = nullptr; if (!EF->__sanitizer_get_module_and_offset_for_pc( reinterpret_cast<void *>(PCs[i]), ModulePathRaw, sizeof(ModulePathRaw), &OffsetRaw)) continue; std::string Module = ModulePathRaw; uintptr_t FixedPC = std::stol(FixedPCStr, 0, 16); uintptr_t PcOffset = reinterpret_cast<uintptr_t>(OffsetRaw); ModuleOffsets[Module] = FixedPC - PcOffset; CoveredPCsPerModule[Module].push_back(PcOffset); CoveredFunctions.insert(FunctionStr); CoveredFiles.insert(FileStr); CoveredDirs.insert(DirName(FileStr)); if (!CoveredLines.insert(FileStr + ":" + LineStr).second) continue; Printf("COVERED: %s %s:%s\n", FunctionStr.c_str(), FileStr.c_str(), LineStr.c_str()); } std::string CoveredDirsStr; for (auto &Dir : CoveredDirs) { if (!CoveredDirsStr.empty()) CoveredDirsStr += ","; CoveredDirsStr += Dir; } Printf("COVERED_DIRS: %s\n", CoveredDirsStr.c_str()); for (auto &M : CoveredPCsPerModule) { std::set<std::string> UncoveredFiles, UncoveredFunctions; std::map<std::string, std::set<int> > UncoveredLines; // Func+File => lines auto &ModuleName = M.first; auto &CoveredOffsets = M.second; uintptr_t ModuleOffset = ModuleOffsets[ModuleName]; std::sort(CoveredOffsets.begin(), CoveredOffsets.end()); Printf("MODULE_WITH_COVERAGE: %s\n", ModuleName.c_str()); // sancov does not yet fully support DSOs. // std::string Cmd = "sancov -print-coverage-pcs " + ModuleName; std::string Cmd = "objdump -d " + ModuleName + " | grep 'call.*__sanitizer_cov_trace_pc_guard' | awk -F: '{print $1}'"; std::string SanCovOutput; if (!ExecuteCommandAndReadOutput(Cmd, &SanCovOutput)) { Printf("INFO: Command failed: %s\n", Cmd.c_str()); continue; } std::istringstream ISS(SanCovOutput); std::string S; while (std::getline(ISS, S, '\n')) { uintptr_t PcOffset = std::stol(S, 0, 16); if (!std::binary_search(CoveredOffsets.begin(), CoveredOffsets.end(), PcOffset)) { uintptr_t PC = ModuleOffset + PcOffset; auto FileStr = DescribePC("%s", PC); if (!IsInterestingCoverageFile(FileStr)) continue; if (CoveredFiles.count(FileStr) == 0) { UncoveredFiles.insert(FileStr); continue; } auto FunctionStr = DescribePC("%F", PC); if (CoveredFunctions.count(FunctionStr) == 0) { UncoveredFunctions.insert(FunctionStr); continue; } std::string LineStr = DescribePC("%l", PC); uintptr_t Line = std::stoi(LineStr); std::string FileLineStr = FileStr + ":" + LineStr; if (CoveredLines.count(FileLineStr) == 0) UncoveredLines[FunctionStr + " " + FileStr].insert(Line); } } for (auto &FileLine: UncoveredLines) for (int Line : FileLine.second) Printf("UNCOVERED_LINE: %s:%d\n", FileLine.first.c_str(), Line); for (auto &Func : UncoveredFunctions) Printf("UNCOVERED_FUNC: %s\n", Func.c_str()); for (auto &File : UncoveredFiles) Printf("UNCOVERED_FILE: %s\n", File.c_str()); } }
IPCCommandResult CWII_IPC_HLE_Device_fs::IOCtlV(u32 _CommandAddress) { u32 ReturnValue = FS_RESULT_OK; SIOCtlVBuffer CommandBuffer(_CommandAddress); // Prepare the out buffer(s) with zeros as a safety precaution // to avoid returning bad values for (u32 i = 0; i < CommandBuffer.NumberPayloadBuffer; i++) { Memory::Memset(CommandBuffer.PayloadBuffer[i].m_Address, 0, CommandBuffer.PayloadBuffer[i].m_Size); } switch (CommandBuffer.Parameter) { case IOCTLV_READ_DIR: { const std::string relative_path = Memory::GetString(CommandBuffer.InBuffer[0].m_Address, CommandBuffer.InBuffer[0].m_Size); if (!IsValidWiiPath(relative_path)) { WARN_LOG(WII_IPC_FILEIO, "Not a valid path: %s", relative_path.c_str()); ReturnValue = FS_RESULT_FATAL; break; } // the Wii uses this function to define the type (dir or file) std::string DirName(HLE_IPC_BuildFilename(relative_path)); INFO_LOG(WII_IPC_FILEIO, "FS: IOCTL_READ_DIR %s", DirName.c_str()); if (!File::Exists(DirName)) { WARN_LOG(WII_IPC_FILEIO, "FS: Search not found: %s", DirName.c_str()); ReturnValue = FS_FILE_NOT_EXIST; break; } else if (!File::IsDirectory(DirName)) { // It's not a directory, so error. // Games don't usually seem to care WHICH error they get, as long as it's < // Well the system menu CARES! WARN_LOG(WII_IPC_FILEIO, "\tNot a directory - return FS_RESULT_FATAL"); ReturnValue = FS_RESULT_FATAL; break; } File::FSTEntry entry = File::ScanDirectoryTree(DirName, false); // it is one if ((CommandBuffer.InBuffer.size() == 1) && (CommandBuffer.PayloadBuffer.size() == 1)) { size_t numFile = entry.children.size(); INFO_LOG(WII_IPC_FILEIO, "\t%zu files found", numFile); Memory::Write_U32((u32)numFile, CommandBuffer.PayloadBuffer[0].m_Address); } else { for (File::FSTEntry& child : entry.children) { // Decode escaped invalid file system characters so that games (such as // Harry Potter and the Half-Blood Prince) can find what they expect. child.virtualName = Common::UnescapeFileName(child.virtualName); } std::sort(entry.children.begin(), entry.children.end(), [](const File::FSTEntry& one, const File::FSTEntry& two) { return one.virtualName < two.virtualName; }); u32 MaxEntries = Memory::Read_U32(CommandBuffer.InBuffer[0].m_Address); memset(Memory::GetPointer(CommandBuffer.PayloadBuffer[0].m_Address), 0, CommandBuffer.PayloadBuffer[0].m_Size); size_t numFiles = 0; char* pFilename = (char*)Memory::GetPointer((u32)(CommandBuffer.PayloadBuffer[0].m_Address)); for (size_t i = 0; i < entry.children.size() && i < MaxEntries; i++) { const std::string& FileName = entry.children[i].virtualName; strcpy(pFilename, FileName.c_str()); pFilename += FileName.length(); *pFilename++ = 0x00; // termination numFiles++; INFO_LOG(WII_IPC_FILEIO, "\tFound: %s", FileName.c_str()); } Memory::Write_U32((u32)numFiles, CommandBuffer.PayloadBuffer[1].m_Address); } ReturnValue = FS_RESULT_OK; } break; case IOCTLV_GETUSAGE: { _dbg_assert_(WII_IPC_FILEIO, CommandBuffer.PayloadBuffer.size() == 2); _dbg_assert_(WII_IPC_FILEIO, CommandBuffer.PayloadBuffer[0].m_Size == 4); _dbg_assert_(WII_IPC_FILEIO, CommandBuffer.PayloadBuffer[1].m_Size == 4); // this command sucks because it asks of the number of used // fsBlocks and inodes // It should be correct, but don't count on it... std::string relativepath = Memory::GetString(CommandBuffer.InBuffer[0].m_Address, CommandBuffer.InBuffer[0].m_Size); if (!IsValidWiiPath(relativepath)) { WARN_LOG(WII_IPC_FILEIO, "Not a valid path: %s", relativepath.c_str()); ReturnValue = FS_RESULT_FATAL; break; } std::string path(HLE_IPC_BuildFilename(relativepath)); u32 fsBlocks = 0; u32 iNodes = 0; INFO_LOG(WII_IPC_FILEIO, "IOCTL_GETUSAGE %s", path.c_str()); if (File::IsDirectory(path)) { // LPFaint99: After I found that setting the number of inodes to the number of children + 1 // for the directory itself // I decided to compare with sneek which has the following 2 special cases which are // Copyright (C) 2009-2011 crediar http://code.google.com/p/sneek/ if ((relativepath.compare(0, 16, "/title/00010001") == 0) || (relativepath.compare(0, 16, "/title/00010005") == 0)) { fsBlocks = 23; // size is size/0x4000 iNodes = 42; // empty folders return a FileCount of 1 } else { File::FSTEntry parentDir = File::ScanDirectoryTree(path, true); // add one for the folder itself iNodes = 1 + (u32)parentDir.size; u64 totalSize = ComputeTotalFileSize(parentDir); // "Real" size, to be converted to nand blocks fsBlocks = (u32)(totalSize / (16 * 1024)); // one bock is 16kb } ReturnValue = FS_RESULT_OK; INFO_LOG(WII_IPC_FILEIO, "FS: fsBlock: %i, iNodes: %i", fsBlocks, iNodes); } else { fsBlocks = 0; iNodes = 0; ReturnValue = FS_RESULT_OK; WARN_LOG(WII_IPC_FILEIO, "FS: fsBlock failed, cannot find directory: %s", path.c_str()); } Memory::Write_U32(fsBlocks, CommandBuffer.PayloadBuffer[0].m_Address); Memory::Write_U32(iNodes, CommandBuffer.PayloadBuffer[1].m_Address); } break; default: PanicAlert("CWII_IPC_HLE_Device_fs::IOCtlV: %i", CommandBuffer.Parameter); break; } Memory::Write_U32(ReturnValue, _CommandAddress + 4); return GetFSReply(); }