示例#1
0
        handle open(const char* file_, const char* mode, error_policy ep)
        {
#ifdef OX_DEBUG
            if (!strstr(mode, "b"))
                log::warning("file::open for file '%s' should be called with 'b' (means binary) flag", file_);
#endif
            //OX_ASSERT(_openedFiles == 0);
            LOGD("open file: %s %s %d", file_, mode, _openedFiles);
            char file[512];
            path::normalize(file_, file);
            LOGD("q1");


            fileHandle* fh = 0;
            _nfs.open(file, mode, ep_ignore_error, fh);

            LOGD("q3");

            if (!fh)
            {
                handleErrorPolicy(ep, "can't open file: %s", file);
            }

            return (handle)fh;
        }
示例#2
0
        bool exists(const char* file_)
        {
            char file[512];
            path::normalize(file_, file);

            return _nfs.isExists(file);
        }
示例#3
0
        bool rename(const char* src, const char* dest, error_policy ep)
        {
            bool ok = _nfs.renameFile(src, dest) == FileSystem::status_ok;
            if (!ok)
            {
                handleErrorPolicy(ep, "can't rename file: %s to %s", src, dest);
            }

            return ok;
        }
示例#4
0
        bool deleteFile(const char* path, error_policy ep)
        {
            bool ok = _nfs.deleteFile(path) == FileSystem::status_ok;
            if (!ok)
            {
                handleErrorPolicy(ep, "can't delete file: %s", path);
            }

            return ok;
        }
示例#5
0
		void init()
		{
#ifdef __S3E__
			_nfs.setPath("rom://");
			_nfsWrite.setPath("ram://");
#endif

#ifdef __ANDROID__
			log::messageln("internal %s", SDL_AndroidGetInternalStoragePath());
			log::messageln("external %s", SDL_AndroidGetExternalStoragePath());
			_nfsWrite.setPath(SDL_AndroidGetInternalStoragePath());
#endif // __ANDROID__

#ifdef WIN32
			_mkdir("../data-ram/");
			_nfsWrite.setPath("../data-ram/");			
#endif

			_nfs.mount(&_nfsWrite);
			//_nfs.mount(&_nfsExtended);
		}
示例#6
0
        bool read(const char* file_, buffer& dest, error_policy ep)
        {
            LOGD("open file: %s %s %d", file_, mode, _openedFiles);
            char file[512];
            path::normalize(file_, file);

            dest.data.clear();
            bool ok = _nfs.read(file, dest, ep) == FileSystem::status_ok;
            if (!ok)
            {
                handleErrorPolicy(ep, "can't read file: %s to buffer", file);
            }
            return ok;
        }
示例#7
0
		handle open(const char *file_, const char *mode, error_policy ep)
		{
			//OX_ASSERT(_openedFiles == 0);
			LOGD("open file: %s %s %d", file_, mode, _openedFiles);
			char file[512];
			path::normalize(file_, file);
			LOGD("q1");


			fileHandle *fh = 0;
			_nfs.open(file, mode, ep_ignore_error, fh);

			LOGD("q3");

			if (!fh)
			{
				handleErrorPolicy(ep, "can't open file: %s", file);
			}

			return fh;
		}
示例#8
0
        void init(const char* company, const char* app)
        {
            if (_fsInitialized)
                return;
            _fsInitialized = true;

#ifdef __S3E__
            _nfs.setPath("rom://");
            _nfsWrite.setPath("ram://");
#elif EMSCRIPTEN
            //mkdir("data-ram/", S_IRWXU|S_IRWXG|S_IRWXO);
            //_nfsWrite.setPath("data-ram/");

#elif __ANDROID__
            log::messageln("internal %s", SDL_AndroidGetInternalStoragePath());
            log::messageln("external %s", SDL_AndroidGetExternalStoragePath());
            _nfsWrite.setPath(SDL_AndroidGetInternalStoragePath());
#elif OXYGINE_EDITOR
#elif __APPLE__
            _nfsWrite.setPath(getSupportFolder().c_str());
#else
            if (company && app && *company && *app)
            {
                char* base_path = SDL_GetPrefPath(company, app);
                if (base_path)
                {
                    _nfsWrite.setPath(base_path);
                    SDL_free(base_path);
                }
            }
            else
            {
#   ifdef _WIN32
                _mkdir("../data-ram/");
#   else
                mkdir("../data-ram/", ACCESSPERMS);
#   endif
                _nfsWrite.setPath("../data-ram/");
            }
#endif
            _nfs.mount(&_nfsWrite);
        }
示例#9
0
 void unmount(FileSystem* fs)
 {
     _nfs.unmount(fs);
 }
示例#10
0
 void mount(FileSystem* fs)
 {
     _nfs.mount(fs);
 }
示例#11
0
 void free()
 {
     _nfs.unmount(&_nfsWrite);
     _fsInitialized = false;
 }
示例#12
0
    namespace file
    {
        std::string _additionalFolder;

        STDFileSystem _nfs(true);
        STDFileSystem _nfsWrite(false);

        bool _fsInitialized = false;

        void init(const char* company, const char* app)
        {
            if (_fsInitialized)
                return;
            _fsInitialized = true;

#ifdef __S3E__
            _nfs.setPath("rom://");
            _nfsWrite.setPath("ram://");
#elif EMSCRIPTEN
            //mkdir("data-ram/", S_IRWXU|S_IRWXG|S_IRWXO);
            //_nfsWrite.setPath("data-ram/");

#elif __ANDROID__
            log::messageln("internal %s", SDL_AndroidGetInternalStoragePath());
            log::messageln("external %s", SDL_AndroidGetExternalStoragePath());
            _nfsWrite.setPath(SDL_AndroidGetInternalStoragePath());
#elif OXYGINE_EDITOR
#elif __APPLE__
            _nfsWrite.setPath(getSupportFolder().c_str());
#else
            if (company && app && *company && *app)
            {
                char* base_path = SDL_GetPrefPath(company, app);
                if (base_path)
                {
                    _nfsWrite.setPath(base_path);
                    SDL_free(base_path);
                }
            }
            else
            {
#   ifdef _WIN32
                _mkdir("../data-ram/");
#   else
                mkdir("../data-ram/", ACCESSPERMS);
#   endif
                _nfsWrite.setPath("../data-ram/");
            }
#endif
            _nfs.mount(&_nfsWrite);
        }

        void free()
        {
            _nfs.unmount(&_nfsWrite);
            _fsInitialized = false;
        }

        void mount(FileSystem* fs)
        {
            _nfs.mount(fs);
        }

        void unmount(FileSystem* fs)
        {
            _nfs.unmount(fs);
        }

        handle open(const char* file_, const char* mode, error_policy ep)
        {
#ifdef OX_DEBUG
            if (!strstr(mode, "b"))
                log::warning("file::open for file '%s' should be called with 'b' (means binary) flag", file_);
#endif
            //OX_ASSERT(_openedFiles == 0);
            LOGD("open file: %s %s %d", file_, mode, _openedFiles);
            char file[512];
            path::normalize(file_, file);
            LOGD("q1");


            fileHandle* fh = 0;
            _nfs.open(file, mode, ep_ignore_error, fh);

            LOGD("q3");

            if (!fh)
            {
                handleErrorPolicy(ep, "can't open file: %s", file);
            }

            return (handle)fh;
        }

        void close(handle h)
        {
            LOGD("close file %x", fh);
            fileHandle* fh = (fileHandle*)h;
            fh->release();
        }

        int seek(handle h, unsigned int offset, int whence)
        {
            fileHandle* fh = (fileHandle*)h;
            return fh->seek(offset, whence);
        }

        unsigned int tell(handle h)
        {
            fileHandle* fh = (fileHandle*)h;
            return fh->tell();
        }

        bool deleteFile(const char* path, error_policy ep)
        {
            bool ok = _nfs.deleteFile(path) == FileSystem::status_ok;
            if (!ok)
            {
                handleErrorPolicy(ep, "can't delete file: %s", path);
            }

            return ok;
        }

        bool rename(const char* src, const char* dest, error_policy ep)
        {
            bool ok = _nfs.renameFile(src, dest) == FileSystem::status_ok;
            if (!ok)
            {
                handleErrorPolicy(ep, "can't rename file: %s to %s", src, dest);
            }

            return ok;
        }

        unsigned int read(handle h, void* dest, unsigned int destSize)
        {
            fileHandle* fh = (fileHandle*)h;
            OX_ASSERT(fh && dest);
            LOGD("read file %x %d", fh, destSize);

            return fh->read(dest, destSize);
        }

        bool read(const char* file_, buffer& dest, error_policy ep)
        {
            LOGD("open file: %s %s %d", file_, mode, _openedFiles);
            char file[512];
            path::normalize(file_, file);

            dest.data.clear();
            bool ok = _nfs.read(file, dest, ep) == FileSystem::status_ok;
            if (!ok)
            {
                handleErrorPolicy(ep, "can't read file: %s to buffer", file);
            }
            return ok;
        }

        unsigned int read(handle fh_, buffer& dest)
        {
            fileHandle* fh = (fileHandle*)fh_;

            unsigned int size  = fh->getSize();
            if (!size)
                return 0;

            dest.data.resize(size);
            unsigned int t = fh->read(&dest.data[0], size);
            LOGD("read file %x %d", fh, t);
            return t;
        }

        void write(handle fh_, const void* data, unsigned int size)
        {
            fileHandle* fh = (fileHandle*)fh_;
            fh->write(data, size);
        }

        void write(const char* file, const buffer& data, error_policy ep)
        {
            write(file, data.getData(), data.getSize(), ep);
        }

        void write(const char* file, const void* data, unsigned int size, error_policy ep)
        {
            autoClose ac(open(file, "wb", ep));
            if (!ac.getHandle())
                return;
            write(ac.getHandle(), data, size);
        }

        unsigned int size(handle fh_)
        {
            fileHandle* fh = (fileHandle*)fh_;
            return fh->getSize();
        }


        bool exists(const char* file_)
        {
            char file[512];
            path::normalize(file_, file);

            return _nfs.isExists(file);
        }

        bool makeDirectory(const char* path)
        {
            return _nfs.makeDirectory(path) == FileSystem::status_ok;
        }

        void deleteDirectory(const char* path)
        {
            _nfs.deleteDirectory(path);
        }

        file::STDFileSystem& fs()
        {
            return _nfs;
        }

        file::STDFileSystem& wfs()
        {
            return _nfsWrite;
        }
    }
示例#13
0
 void deleteDirectory(const char* path)
 {
     _nfs.deleteDirectory(path);
 }
示例#14
0
 bool makeDirectory(const char* path)
 {
     return _nfs.makeDirectory(path) == FileSystem::status_ok;
 }
示例#15
0
	namespace file
	{
		string _additionalFolder;
		/*
		FileSystem &getFS()
		{
			static bool initialized = false;
			if (!initialized)
			{

			}
			return ;
		}
		*/
		STDFileSystem _nfs(true);
		STDFileSystem _nfsWrite(false);
		//STDFileSystem _nfsExtended(true);

		void init()
		{
#ifdef __S3E__
			_nfs.setPath("rom://");
			_nfsWrite.setPath("ram://");
#endif

#ifdef __ANDROID__
			log::messageln("internal %s", SDL_AndroidGetInternalStoragePath());
			log::messageln("external %s", SDL_AndroidGetExternalStoragePath());
			_nfsWrite.setPath(SDL_AndroidGetInternalStoragePath());
#endif // __ANDROID__

#ifdef WIN32
			_mkdir("../data-ram/");
			_nfsWrite.setPath("../data-ram/");			
#endif

			_nfs.mount(&_nfsWrite);
			//_nfs.mount(&_nfsExtended);
		}

		void mount(FileSystem *fs)
		{
			_nfs.mount(fs);
		}

		void unmount(FileSystem *fs)
		{
			_nfs.unmount(fs);
		}

		handle open(const char *file_, const char *mode, error_policy ep)
		{
			//OX_ASSERT(_openedFiles == 0);
			LOGD("open file: %s %s %d", file_, mode, _openedFiles);
			char file[512];
			path::normalize(file_, file);
			LOGD("q1");


			fileHandle *fh = 0;
			_nfs.open(file, mode, ep_ignore_error, fh);

			LOGD("q3");

			if (!fh)
			{
				handleErrorPolicy(ep, "can't open file: %s", file);
			}

			return fh;
		}

		void close(handle h)
		{
			LOGD("close file %x", fh);
			fileHandle *fh = (fileHandle *)h;
			fh->release();
		}

		int seek(handle h, unsigned int offset, int whence)
		{
			fileHandle *fh = (fileHandle *)h;
			return fh->seek(offset, whence);
		}

		unsigned int tell(handle h)
		{
			fileHandle *fh = (fileHandle *)h;
			return fh->tell();
		}

		bool deleteFile(const char *path, error_policy ep)
		{
			bool ok = _nfs.deleteFile(path) == FileSystem::status_ok;
			if (!ok)
			{
				handleErrorPolicy(ep, "can't delete file: %s", path);
			}

			return ok;
		}

		bool rename(const char *src, const char *dest, error_policy ep)
		{
			bool ok = _nfs.renameFile(src, dest) == FileSystem::status_ok;
			if (!ok)
			{
				handleErrorPolicy(ep, "can't rename file: %s to %s", src, dest);
			}

			return ok;
		}

		unsigned int read(handle h, void *dest, unsigned int destSize)
		{			
			fileHandle *fh = (fileHandle *)h;
			OX_ASSERT(fh && dest);
			LOGD("read file %x %d", fh, destSize);

			return fh->read(dest, destSize);
		}

		void read(const char *file, buffer &dest, error_policy ep)
		{
			dest.data.resize(0);

			autoClose ac(open(file, "rb", ep));
			if (ac.getHandle())
			{
				read(ac.getHandle(), dest);
			}
		}

		unsigned int read(handle fh_, buffer &dest)
		{
			fileHandle *fh = (fileHandle*)fh_;

			unsigned int size  = fh->getSize();
			if (!size)
				return 0;

			dest.data.resize(size);
			unsigned int t = fh->read(&dest.data[0], size);
			LOGD("read file %x %d", fh, t);
			return t;
		}

		void write(handle fh_, const void *data, unsigned int size)
		{
			fileHandle *fh = (fileHandle*)fh_;
			fh->write(data, size);
		}

		

		bool exists(const char *file)
		{
			return _nfs.isExists(file);
		}

		bool makeDirectory(const char *path)
		{
			return _nfs.makeDirectory(path) == FileSystem::status_ok;
		}

		void deleteDirectory(const char *path)
		{
#if __S3E__
			s3eFileDeleteDirectory(path);
#else
#ifdef WIN32
			_rmdir(path);
#else
			rmdir(path);
#endif
#endif
		}

		void write(const char *file, const buffer &data, error_policy ep)
		{
			autoClose ac(open(file, "w", ep));
			if (!ac.getHandle())
				return;
			write(ac.getHandle(), data.getData(), data.getSize());
		}
		/*

		void setExtendedFolder(const char *folder)
		{
			_nfsExtended.setPath(folder);			
		}
		*/

		file::STDFileSystem &fs()
		{
			return _nfs;
		}

		file::STDFileSystem &wfs()
		{
			return _nfsWrite;
		}
	}
示例#16
0
		bool exists(const char *file)
		{
			return _nfs.isExists(file);
		}