diff options
author | Andre Heider | 2009-09-05 17:53:55 +0000 |
---|---|---|
committer | Andre Heider | 2009-09-05 17:53:55 +0000 |
commit | 0b002beccd31fa2796a319427624af1b2ad580b6 (patch) | |
tree | e625a36d21708cb2105e2979bbb9a29934ef03c0 /backends/fs | |
parent | 549e2b054092d3ba2ef1c53245227107d406b4c8 (diff) | |
download | scummvm-rg350-0b002beccd31fa2796a319427624af1b2ad580b6.tar.gz scummvm-rg350-0b002beccd31fa2796a319427624af1b2ad580b6.tar.bz2 scummvm-rg350-0b002beccd31fa2796a319427624af1b2ad580b6.zip |
Support for SMB shares, cleaned up async FS functions.
svn-id: r43965
Diffstat (limited to 'backends/fs')
-rw-r--r-- | backends/fs/wii/wii-fs-factory.cpp | 161 | ||||
-rw-r--r-- | backends/fs/wii/wii-fs-factory.h | 39 | ||||
-rw-r--r-- | backends/fs/wii/wii-fs.cpp | 67 |
3 files changed, 201 insertions, 66 deletions
diff --git a/backends/fs/wii/wii-fs-factory.cpp b/backends/fs/wii/wii-fs-factory.cpp index c9513f7784..4595e93555 100644 --- a/backends/fs/wii/wii-fs-factory.cpp +++ b/backends/fs/wii/wii-fs-factory.cpp @@ -27,8 +27,22 @@ #include "backends/fs/wii/wii-fs-factory.h" #include "backends/fs/wii/wii-fs.cpp" +#ifdef USE_WII_DI +#include <di/di.h> +#endif + +#ifdef USE_WII_SMB +#include <network.h> +#include <smb.h> +#endif + DECLARE_SINGLETON(WiiFilesystemFactory); +WiiFilesystemFactory::WiiFilesystemFactory() : + _dvdMounted(false), + _smbMounted(false) { +} + AbstractFSNode *WiiFilesystemFactory::makeRootFileNode() const { return new WiiFilesystemNode(); } @@ -46,8 +60,151 @@ AbstractFSNode *WiiFilesystemFactory::makeFileNodePath(const Common::String &pat return new WiiFilesystemNode(path); } -void WiiFilesystemFactory::asyncHandler(bool mount, const Common::String *path) { - WiiFilesystemNode::asyncHandler(mount, path); +void WiiFilesystemFactory::asyncInit() { +#ifdef USE_WII_SMB + asyncInitNetwork(); +#endif +} + +void WiiFilesystemFactory::asyncDeinit() { +#ifdef USE_WII_DI + umount(kDVD); + DI_Close(); +#endif +#ifdef USE_WII_SMB + umount(kSMB); + net_deinit(); +#endif +} + +#ifdef USE_WII_SMB +void WiiFilesystemFactory::asyncInitNetwork() { + net_init_async(NULL, NULL); +} + +void WiiFilesystemFactory::setSMBLoginData(const String &server, + const String &share, + const String &username, + const String &password) { + _smbServer = server; + _smbShare = share; + _smbUsername = username; + _smbPassword = password; +} +#endif + +bool WiiFilesystemFactory::isMounted(FileSystemType type) { + switch (type) { + case kDVD: + return _dvdMounted; + case kSMB: + return _smbMounted; + } + + return false; +} + +void WiiFilesystemFactory::mount(FileSystemType type) { + switch (type) { + case kDVD: +#ifdef USE_WII_DI + if (_dvdMounted) + break; + + printf("mount dvd\n"); + DI_Mount(); + + while (DI_GetStatus() & DVD_INIT) + usleep(20 * 1000); + + if (!(DI_GetStatus() & DVD_READY)) { + DI_StopMotor(); + printf("error mounting dvd\n"); + break; + } + + printf("mount ISO9660\n"); + if (ISO9660_Mount()) { + _dvdMounted = true; + printf("ISO9660 mounted\n"); + } else { + DI_StopMotor(); + printf("ISO9660 mount failed\n"); + } +#endif + break; + + case kSMB: +#ifdef USE_WII_SMB + if (_smbMounted) + break; + + printf("mount smb\n"); + + if (net_get_status()) { + printf("network not inited\n"); + break; + } + + if (smbInit(_smbUsername.c_str(), _smbPassword.c_str(), + _smbShare.c_str(), _smbServer.c_str())) { + _smbMounted = true; + printf("smb mounted\n"); + } else { + printf("error mounting smb\n"); + } +#endif + break; + } +} + +void WiiFilesystemFactory::umount(FileSystemType type) { + switch (type) { + case kDVD: +#ifdef USE_WII_DI + if (!_dvdMounted) + break; + + printf("umount dvd\n"); + + ISO9660_Unmount(); + DI_StopMotor(); + + _dvdMounted = false; +#endif + break; + + case kSMB: +#ifdef USE_WII_SMB + if (!_smbMounted) + break; + + printf("umount smb\n"); + + if (smbClose("smb:")) + printf("smb umounted\n"); + else + printf("error umounting smb\n"); + + _smbMounted = false; +#endif + break; + } +} + +void WiiFilesystemFactory::mountByPath(const String &path) { + if (path.hasPrefix("dvd:/")) + mount(kDVD); + else if (path.hasPrefix("smb:/")) + mount(kSMB); +} + +void WiiFilesystemFactory::umountUnused(const String &path) { + if (!path.hasPrefix("dvd:/")) + umount(kDVD); + + if (!path.hasPrefix("smb:/")) + umount(kSMB); } #endif diff --git a/backends/fs/wii/wii-fs-factory.h b/backends/fs/wii/wii-fs-factory.h index f58371d194..0e7f87a783 100644 --- a/backends/fs/wii/wii-fs-factory.h +++ b/backends/fs/wii/wii-fs-factory.h @@ -23,9 +23,12 @@ #ifndef _WII_FILESYSTEM_FACTORY_H_ #define _WII_FILESYSTEM_FACTORY_H_ +#include "common/str.h" #include "common/singleton.h" #include "backends/fs/fs-factory.h" +#include <gctypes.h> + /** * Creates WiiFilesystemNode objects. * @@ -33,17 +36,49 @@ */ class WiiFilesystemFactory : public FilesystemFactory, public Common::Singleton<WiiFilesystemFactory> { public: + typedef Common::String String; + + enum FileSystemType { + kDVD, + kSMB + }; + virtual AbstractFSNode *makeRootFileNode() const; virtual AbstractFSNode *makeCurrentDirectoryFileNode() const; virtual AbstractFSNode *makeFileNodePath(const Common::String &path) const; - static void asyncHandler(bool mount, const Common::String *path); + void asyncInit(); + void asyncDeinit(); + +#ifdef USE_WII_SMB + void asyncInitNetwork(); + void setSMBLoginData(const String &server, const String &share, + const String &username, const String &password); +#endif + + bool isMounted(FileSystemType type); + + void mount(FileSystemType type); + void umount(FileSystemType type); + + void mountByPath(const String &path); + void umountUnused(const String &path); protected: - WiiFilesystemFactory() {}; + WiiFilesystemFactory(); private: friend class Common::Singleton<SingletonBaseType>; + + bool _dvdMounted; + bool _smbMounted; + +#ifdef USE_WII_SMB + String _smbServer; + String _smbShare; + String _smbUsername; + String _smbPassword; +#endif }; #endif /*Wii_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/wii/wii-fs.cpp b/backends/fs/wii/wii-fs.cpp index 7a144cddbf..e6ba2a4aa0 100644 --- a/backends/fs/wii/wii-fs.cpp +++ b/backends/fs/wii/wii-fs.cpp @@ -29,14 +29,11 @@ #include <sys/dir.h> #include <sys/types.h> #include <sys/stat.h> +#include <errno.h> #include <unistd.h> #include <gctypes.h> -#ifdef USE_WII_DI -#include <di/di.h> -#endif - /** * Implementation of the ScummVM file system API based on Wii. * @@ -81,60 +78,8 @@ public: virtual Common::SeekableReadStream *createReadStream(); virtual Common::WriteStream *createWriteStream(); - - static void asyncHandler(bool umount, const Common::String *path); }; -void WiiFilesystemNode::asyncHandler(bool mount, const Common::String *path) { -#ifdef USE_WII_DI - static bool di_tryMount = true; - static bool di_isMounted = false; - - // umount not required filesystems - if (!mount) { - if (di_isMounted && (!path || (path && !path->hasPrefix("dvd:/")))) { - printf("umount ISO9660\n"); - ISO9660_Unmount(); - DI_StopMotor(); - di_tryMount = false; - di_isMounted = false; - } - - if (!path) - return; - } - - // re-mount DVD if data from its path has been requested. in this case, we - // have to wait for DI_Mount() to finish - if (!di_tryMount && !di_isMounted && path && path->hasPrefix("dvd:/")) { - printf("remount ISO9660\n"); - DI_Mount(); - - while (DI_GetStatus() & DVD_INIT) - usleep(20 * 1000); - - di_tryMount = true; - } - - if (!di_tryMount) - return; - - // check if the async DI_Mount() call has finished - if (DI_GetStatus() & DVD_READY) { - di_tryMount = false; - - printf("mount ISO9660\n"); - if (ISO9660_Mount()) { - di_isMounted = true; - printf("ISO9660 mounted\n"); - } else { - DI_StopMotor(); - printf("ISO9660 mount failed\n"); - } - } -#endif -} - // gets all registered devoptab devices bool WiiFilesystemNode::getDevopChildren(AbstractFSList &list, ListMode mode, bool hidden) const { u8 i; @@ -143,8 +88,6 @@ bool WiiFilesystemNode::getDevopChildren(AbstractFSList &list, ListMode mode, bo if (mode == Common::FSNode::kListFilesOnly) return true; - asyncHandler(true, NULL); - // skip in, out and err for (i = 3; i < STD_MAX; ++i) { dt = devoptab_list[i]; @@ -194,14 +137,14 @@ WiiFilesystemNode::WiiFilesystemNode(const Common::String &p) { _path = Common::normalizePath(p, '/'); - // "fat:" is not a valid directory, but "fat:/" is + WiiFilesystemFactory::instance().mountByPath(_path); + + // "sd:" is not a valid directory, but "sd:/" is if (_path.lastChar() == ':') _path += '/'; _displayName = lastPathComponent(_path, '/'); - asyncHandler(true, &_path); - struct stat st; if (!stat(_path.c_str(), &st)) setFlags(&st); @@ -217,7 +160,7 @@ WiiFilesystemNode::WiiFilesystemNode(const Common::String &p, const struct stat _path = Common::normalizePath(p, '/'); - // "fat:" is not a valid directory, but "fat:/" is + // "sd:" is not a valid directory, but "sd:/" is if (_path.lastChar() == ':') _path += '/'; |