public void emptyDirectory(bool preserveTree)
        {
            if (_fileType == FileType.INTERNAL_)
            {
                IOException exception = new IOException();
                exception._init_("You can't emptyDirectory() an INTERNAL file");
                throw exception;
            }

            foreach (var child in list())
            {
                if (!preserveTree)
                {
                    child.deleteDirectory();
                }
                else
                {
                    if (child.isDirectory())
                    {
                        child.emptyDirectory(false);
                    }
                    else
                    {
                        child.delete();
                    }
                }
            }
        }
        public bool deleteDirectory()
        {
            if (_fileType == FileType.INTERNAL_)
            {
                IOException exception = new IOException();
                exception._init_("You can't deleteDirectory() an INTERNAL file");
                throw exception;
            }

            if (_isDirectory)
            {
                try
                {
                    _directoryInfo.Delete(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            else
            {
                try
                {
                    _fileInfo.Delete();
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            return(true);
        }
        public void writeString(Java.Lang.String str, bool append, Java.Lang.String encoding)
        {
            if (_isDirectory)
            {
                IOException exception = new IOException();
                exception._init_("Can't write string to a directory");
                throw exception;
            }

            if (type() == FileType.INTERNAL_)
            {
                IOException exception = new IOException();
                exception._init_("Can't write in an INTERNAL file");
                throw exception;
            }

            if (append)
            {
                File.AppendAllText(pathWithPrefix(), str, Encoding.GetEncoding((string)encoding));
            }
            else
            {
                File.WriteAllText(pathWithPrefix(), str, Encoding.GetEncoding((string)encoding));
            }
        }
        public bool delete()
        {
            if (_fileType == FileType.INTERNAL_)
            {
                IOException exception = new IOException();
                exception._init_("You can't delete() an INTERNAL file");
                throw exception;
            }

            if (_isDirectory)
            {
                if (_directoryInfo.GetDirectories().Length + _directoryInfo.GetFiles().Length != 0)
                {
                    return(false);
                }

                _directoryInfo.Delete();
            }
            else
            {
                _fileInfo.Delete();
            }

            return(true);
        }
        public void writeBytes(sbyte[] bytes, int offset, int size, bool append)
        {
            if (_isDirectory)
            {
                IOException exception = new IOException();
                exception._init_("Can't write bytes to directory");
            }

            if (type() == FileType.INTERNAL_)
            {
                IOException exception = new IOException();
                exception._init_("Can't write in an INTERNAL file");
                throw exception;
            }

            var fileStream = new FileStream(pathWithPrefix(), append ? FileMode.Append : FileMode.OpenOrCreate, FileAccess.Write);

            fileStream.Seek(offset, SeekOrigin.Begin);
            using (var streamWriter = new StreamWriter(fileStream))
            {
                for (var i = offset; i < offset + size; i++)
                {
                    streamWriter.Write(bytes[i]);
                }
            }
            _totalBytes = bytes.Length;
        }
        public sbyte[] readBytes()
        {
            if (_isDirectory)
            {
                IOException exception = new IOException();
                exception._init_("Can't read bytes from a directory");
                throw exception;
            }

            if (_fileType == FileType.INTERNAL_)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    ((MonoGameFiles)Mdx.files_)._contentManager.OpenStream(path()).CopyTo(ms);
                    byte [] rawResult = ms.ToArray();
                    sbyte[] result    = new sbyte[rawResult.Length];
                    for (int i = 0; i < rawResult.Length; i++)
                    {
                        result[i] = (sbyte)rawResult[i];
                    }
                    return(result);
                }
            }

            var fileBytes = new sbyte[_totalBytes];

            readBytes(fileBytes, 0, _totalBytes);
            return(fileBytes);
        }
        public void emptyDirectory()
        {
            if (_fileType == FileType.INTERNAL_)
            {
                IOException exception = new IOException();
                exception._init_("You can't emptyDirectory() an INTERNAL file");
                throw exception;
            }

            emptyDirectory(false);
        }
        public void mkdirs()
        {
            if (_fileType == FileType.INTERNAL_)
            {
                IOException exception = new IOException();
                exception._init_("You can't mkdirs() an INTERNAL file");
                throw exception;
            }

            _directoryInfo = Directory.CreateDirectory(_fileInfo.ToString());
            _isDirectory   = true;
        }
        public Java.Lang.String readString(Java.Lang.String encoding)
        {
            if (_isDirectory)
            {
                IOException exception = new IOException();
                exception._init_("Can't read string from a directory");
                throw exception;
            }

            if (_fileType == FileType.INTERNAL_)
            {
                return(readString());
            }

            return(File.ReadAllText(pathWithPrefix(), Encoding.GetEncoding((string)encoding)));
        }
示例#10
0
        public Java.Lang.String readString()
        {
            if (_isDirectory)
            {
                IOException exception = new IOException();
                exception._init_("Can't read string from a directory");
                throw exception;
            }

            if (_fileType == FileType.INTERNAL_)
            {
                using (StreamReader reader = new StreamReader(((MonoGameFiles)Mdx.files_)._contentManager.OpenStream(path())))
                {
                    return(reader.ReadToEnd());
                }
            }

            return(File.ReadAllText(pathWithPrefix()));
        }
示例#11
0
        public void moveTo(FileHandle dest)
        {
            if (_fileType == FileType.INTERNAL_ || dest.type() == FileType.INTERNAL_)
            {
                IOException exception = new IOException();
                exception._init_("You can't moveTo() an INTERNAL file");
                throw exception;
            }

            if (dest.exists())
            {
                dest.deleteDirectory();
            }

            if (_isDirectory)
            {
                _directoryInfo.MoveTo(dest.ToString());
            }
            else
            {
                _fileInfo.MoveTo(dest.ToString());
            }
        }
示例#12
0
        public byte[] readBytesAsByteArray()
        {
            if (_isDirectory)
            {
                IOException exception = new IOException();
                exception._init_("Can't read bytes from a directory");
                throw exception;
            }

            if (_fileType == FileType.INTERNAL_)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    ((MonoGameFiles)Mdx.files_)._contentManager.OpenStream(path()).CopyTo(ms);
                    return(ms.ToArray());
                }
            }

            var fileBytes = new byte[_totalBytes];

            readBytes(fileBytes, 0, (int)_totalBytes);
            return(fileBytes);
        }
示例#13
0
        public int readBytes(sbyte[] fileBytes, int offset, int size)
        {
            if (_isDirectory)
            {
                IOException exception = new IOException();
                exception._init_("Can't read bytes from a directory");
                throw exception;
            }

            var    readBytesNumber = 0;
            Stream byteStream;

            if (_fileType == FileType.INTERNAL_)
            {
                byteStream = ((MonoGameFiles)Mdx.files_)._contentManager.OpenStream(path());
            }
            else
            {
                byteStream = _fileInfo.OpenRead();
            }

            for (var i = offset; i < offset + size; i++)
            {
                var readByte = byteStream.ReadByte();
                if (readByte == -1)
                {
                    break;
                }

                fileBytes[i] = (sbyte)readByte;
                readBytesNumber++;
            }
            byteStream.Close();

            return(readBytesNumber);
        }