const Path Browser::SelectDirectory() { Path path; path.Reserve( MAX_PATH*2 ); Object::Pod<BROWSEINFO> bi; bi.hwndOwner = Application::Instance::GetActiveWindow(); bi.pszDisplayName = path.Ptr(); bi.ulFlags = BIF_RETURNONLYFSDIRS; if (LPITEMIDLIST const idl = ::SHBrowseForFolder( &bi )) { if (::SHGetPathFromIDList( idl, path.Ptr() ) && path.Validate()) path.MakePretty( true ); else path.Clear(); IMalloc* pMalloc; if (SUCCEEDED(::SHGetMalloc( &pMalloc ))) { pMalloc->Free( idl ); pMalloc->Release(); } } else { path.Clear(); } return path; }
const Path Instance::GetTmpPath(GenericString file) { Path path; path.Reserve( 255 ); if (uint length = ::GetTempPath( path.Capacity() + 1, path.Ptr() )) { if (length > path.Capacity() + 1) { path.Reserve( length - 1 ); length = ::GetTempPath( path.Capacity() + 1, path.Ptr() ); } if (length) path = GetLongPath( path.Ptr() ); } if (path.Length()) path.MakePretty( true ); else path << ".\\"; if (file.Empty()) file = L"nestopia.tmp"; path << file; return path; }
const Path Browser::SaveFile(wchar_t* const filter,Path initial) { Path path; path.Reserve( MAX_PATH*2 ); const Path extension( initial.Extension() ); if (initial.File().Length() && initial.File()[0] != '.') path = initial.File(); initial.File().Clear(); Object::Pod<OPENFILENAME> ofn; ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = Application::Instance::GetActiveWindow(); ofn.lpstrFile = path.Ptr(); ofn.nMaxFile = path.Capacity(); ofn.lpstrInitialDir = initial.Length() ? initial.Ptr() : L"."; ofn.Flags = OFN_EXPLORER|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY; if (filter) { for (uint i=0; filter[i]; ++i) { if (filter[i] == '\t') filter[i] = '\0'; } ofn.lpstrFilter = filter; ofn.nFilterIndex = 1; } if (extension.Length()) ofn.lpstrDefExt = extension.Ptr(); if (::GetSaveFileName( &ofn )) path.Validate(); else path.Clear(); return path; }
const Path Instance::GetLongPath(wcstring const shortPath) { Path longPath; longPath.Reserve( 255 ); uint length = ::GetLongPathName( shortPath, longPath.Ptr(), longPath.Capacity() + 1 ); if (length > longPath.Capacity() + 1) { longPath.Reserve( length - 1 ); length = ::GetLongPathName( shortPath, longPath.Ptr(), longPath.Capacity() + 1 ); } if (!length) return shortPath; const wchar_t slashed = GenericString(shortPath).Back(); longPath.ShrinkTo( length ); longPath.MakePretty( slashed == '\\' || slashed == '/' ); return longPath; }
const Path Browser::OpenFile(wchar_t* const filter,const Path dir,const Path ext) { for (uint i=0; filter[i]; ++i) { if (filter[i] == '\t') filter[i] = '\0'; } Path path; path.Reserve( MAX_PATH*2 ); Object::Pod<OPENFILENAME> ofn; ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = Application::Instance::GetActiveWindow(); ofn.lpstrFile = path.Ptr(); ofn.nMaxFile = path.Capacity(); ofn.lpstrInitialDir = dir.Length() ? dir.Ptr() : L"."; ofn.Flags = OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; if (filter) { ofn.lpstrFilter = filter; ofn.nFilterIndex = 1; } if (ext.Length()) ofn.lpstrDefExt = ext.Ptr(); if (::GetOpenFileName( &ofn )) path.Validate(); else path.Clear(); return path; }
//============================================================================= void CAppPathing::DrawPath (const Path & path, const Color & color) { Graphics::IRenderTarget * backbuffer = Graphics::GetContext()->Backbuffer(); const Point2 * prev = path.Ptr(); const Point2 * curr = prev + 1; const Point2 * term = path.Term(); for ( ; curr < term; prev = curr, ++curr) { backbuffer->Arrow( *prev, *curr, color, 2.0f ); } }
void Netplay::SaveFile() const { if (games.state == Games::DIRTY) { //const Path path( Application::Instance::GetExePath(L"netplaylist.xml") ); const Path path( Application::Instance::GetConfigPath(L"netplaylist.xml") );//bg if (!games.paths.empty()) { try { typedef Nes::Core::Xml Xml; Xml xml; Xml::Node root( xml.Create( L"netplaylist" ) ); root.AddAttribute( L"version", L"1.0" ); for (Games::Paths::const_iterator it(games.paths.begin()), end(games.paths.end()); it != end; ++it) root.AddChild( L"file", it->Ptr() ); Io::Stream::Out stream( path ); xml.Write( root, stream ); Io::Log() << "Netplay: saved game list to \"netplaylist.xml\"\r\n"; } catch (...) { Io::Log() << "Netplay: warning, couldn't save game list to \"netplaylist.xml\"!\r\n"; } } else if (path.FileExists()) { if (Io::File::Delete( path.Ptr() )) Io::Log() << "Netplay: game list empty, deleted \"netplaylist.xml\"\r\n"; else Io::Log() << "Netplay: warning, couldn't delete \"netplaylist.xml\"!\r\n"; } } }