Skip to content

Commit a8aaf56

Browse files
committed
Move a function
1 parent 51853ea commit a8aaf56

File tree

3 files changed

+39
-31
lines changed

3 files changed

+39
-31
lines changed

render_pipeline/rpcore/mount_manager.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ class RenderPipeline;
1111
class RENDER_PIPELINE_DECL MountManager : public RPObject
1212
{
1313
public:
14+
/**
15+
* Convert virtual path to physical path.
16+
*
17+
* This function converts the path of Panda3D virutal file system to that of physical filesystem.
18+
* If failed, this will return empty string.
19+
*/
20+
static std::string convert_to_physical_path(const std::string& path);
21+
1422
MountManager(RenderPipeline& pipeline);
1523
~MountManager(void);
1624

src/rpcore/mount_manager.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#include "render_pipeline/rpcore/mount_manager.hpp"
22

3+
#include <dcast.h>
34
#include <filename.h>
45
#include <virtualFileSystem.h>
56
#include <virtualFileMountRamdisk.h>
7+
#include <virtualFileMountSystem.h>
68
#include <config_util.h>
79

810
#include <boost/filesystem.hpp>
911
#include <boost/dll/runtime_symbol_info.hpp>
1012

13+
#include <spdlog/fmt/ostr.h>
14+
1115
#include "render_pipeline/rppanda/stdpy/file.hpp"
1216

1317
namespace rpcore {
@@ -297,4 +301,29 @@ void MountManager::unmount(void)
297301
throw std::runtime_error("TODO");
298302
}
299303

304+
std::string MountManager::convert_to_physical_path(const std::string& path)
305+
{
306+
Filename plugin_dir_in_vfs(path);
307+
plugin_dir_in_vfs.standardize();
308+
309+
VirtualFileSystem* vfs = VirtualFileSystem::get_global_ptr();
310+
for (int k=0, k_end=vfs->get_num_mounts(); k < k_end; ++k)
311+
{
312+
const std::string mount_point = vfs->get_mount(k)->get_mount_point().to_os_specific();
313+
const std::string plugin_dir_in_vfs_string = plugin_dir_in_vfs.to_os_specific();
314+
315+
// /{mount_point}/...
316+
if (mount_point.substr(0, 2) == std::string("$$") && plugin_dir_in_vfs_string.find(mount_point) == 1)
317+
{
318+
boost::filesystem::path physical_plugin_dir = DCAST(VirtualFileMountSystem, vfs->get_mount(k))->get_physical_filename().to_os_specific();
319+
physical_plugin_dir /= plugin_dir_in_vfs_string.substr(1+mount_point.length());
320+
return physical_plugin_dir.string();
321+
}
322+
}
323+
324+
RPObject::global_error("MountManager", fmt::format("Cannot convert to physical path from Panda Path ({}).", path.c_str()));
325+
326+
return "";
327+
}
328+
300329
}

src/rpcore/pluginbase/manager.cpp

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
#include <unordered_set>
44

5-
#include <virtualFileSystem.h>
6-
#include <virtualFileMountSystem.h>
7-
85
#include <boost/detail/winapi/dll.hpp>
96
#include <boost/dll/import.hpp>
107

118
#include <spdlog/fmt/fmt.h>
129

10+
#include "render_pipeline/rpcore/mount_manager.hpp"
1311
#include "render_pipeline/rpcore/render_pipeline.hpp"
1412
#include "render_pipeline/rpcore/stage_manager.hpp"
1513
#include "render_pipeline/rpcore/pluginbase/day_setting_types.hpp"
@@ -30,8 +28,6 @@ struct PluginManager::Impl
3028
/** Internal method to load a plugin. */
3129
std::shared_ptr<BasePlugin> load_plugin(const std::string& plugin_id);
3230

33-
std::string convert_to_physical_path(const Filename& path) const;
34-
3531
PluginManager& self_;
3632
RenderPipeline& pipeline_;
3733
std::string plugin_dir_;
@@ -113,31 +109,6 @@ std::shared_ptr<BasePlugin> PluginManager::Impl::load_plugin(const std::string&
113109
// TODO: implement
114110
}
115111

116-
std::string PluginManager::Impl::convert_to_physical_path(const Filename& path) const
117-
{
118-
Filename plugin_dir_in_vfs(path);
119-
plugin_dir_in_vfs.standardize();
120-
121-
VirtualFileSystem* vfs = VirtualFileSystem::get_global_ptr();
122-
for (int k=0, k_end=vfs->get_num_mounts(); k < k_end; ++k)
123-
{
124-
const std::string mount_point = vfs->get_mount(k)->get_mount_point().to_os_specific();
125-
const std::string plugin_dir_in_vfs_string = plugin_dir_in_vfs.to_os_specific();
126-
127-
// /{mount_point}/...
128-
if (mount_point.substr(0, 2) == std::string("$$") && plugin_dir_in_vfs_string.find(mount_point) == 1)
129-
{
130-
boost::filesystem::path physical_plugin_dir = DCAST(VirtualFileMountSystem, vfs->get_mount(k))->get_physical_filename().to_os_specific();
131-
physical_plugin_dir /= plugin_dir_in_vfs_string.substr(1+mount_point.length());
132-
return physical_plugin_dir.string();
133-
}
134-
}
135-
136-
self_.error(fmt::format("Cannot convert to physical path from Panda Path ({}).", path.c_str()));
137-
138-
return "";
139-
}
140-
141112
// ************************************************************************************************
142113

143114
PluginManager::PluginManager(RenderPipeline& pipeline): RPObject("PluginManager"), impl_(std::make_unique<Impl>(*this, pipeline))
@@ -199,7 +170,7 @@ void PluginManager::load_base_settings(const Filename& plugin_dir)
199170
{
200171
trace(fmt::format("Loading base setting from '{}'", plugin_dir.c_str()));
201172

202-
impl_->plugin_dir_ = impl_->convert_to_physical_path(plugin_dir);
173+
impl_->plugin_dir_ = MountManager::convert_to_physical_path(plugin_dir);
203174
if (impl_->plugin_dir_.empty())
204175
{
205176
error(fmt::format("Cannot find plugin directory ({}).", plugin_dir.c_str()));

0 commit comments

Comments
 (0)