コード例 #1
0
        // SDK location: /user/pspiofilemgr.h:448
        // SDK declaration: int sceIoGetDevType(SceUID fd);
        public int sceIoGetDevType(int fd)
        {
            KFile handle = _kernel.GetHandle <KFile>(fd);

            if (handle == null)
            {
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoGetDevType: kernel handle {0} not found", fd);
                return(-1);
            }

            if (handle.Device != null)
            {
                switch (handle.Device.Device.MediaType)
                {
                default:
                case MediaType.Umd:
                    return(4);

                case MediaType.MemoryStick:
                    return(16);
                }
            }
            else
            {
                return(4);
            }
        }
コード例 #2
0
ファイル: Utils.cs プロジェクト: Kyklos-Italy/bcl-tests
        private static async Task <AdminUser[]> ReadAdminUsers()
        {
            const string AdminCredentialsFilename = "admin_users.txt";

            try
            {
                return((await
                        KFile
                        .ReadAllLinesAsync(AdminCredentialsFilename)
                        .ConfigureAwait(false))
                       .Select
                       (
                           line =>
                {
                    var parts = line.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    return new AdminUser(parts[0], parts[1]);
                }
                       )
                       .ToArray());
            }
            catch (Exception exception)
            {
                await Console.Out.WriteLineAsync($"Could not read admin users from {AdminCredentialsFilename}: {exception.Message}").ConfigureAwait(false);

                return(null);
            }
        }
コード例 #3
0
        // SDK location: /user/pspiofilemgr.h:109
        // SDK declaration: int sceIoRead(SceUID fd, void *data, SceSize size);
        public int sceIoRead(int fd, int data, int size)
        {
            if (data == 0)
            {
                return(-1);
            }

            KFile handle = _kernel.GetHandle <KFile>(fd);

            if (handle == null)
            {
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoRead: kernel file handle not found: {0:X}", fd);
                return(-1);
            }

            if (fd == 0)
            {
                // stdin - ignored
                return(0);
            }

            int scalar = (handle.IsBlockAccess == true) ? 2048 : 1;

            size *= scalar;

            int end    = ( int )handle.Stream.Length - ( int )handle.Stream.Position;
            int length = (size < end) ? size : end;

            _memory.WriteStream(data, handle.Stream, length);

            handle.Result = length;

            return(length);
        }
コード例 #4
0
        // SDK location: /user/pspiofilemgr.h:141
        // SDK declaration: int sceIoWrite(SceUID fd, const void *data, SceSize size);
        public int sceIoWrite(int fd, int data, int size)
        {
            KFile handle = _kernel.GetHandle <KFile>(fd);

            if (handle == null)
            {
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoWrite: kernel file handle not found: {0:X}", fd);
                return(-1);
            }

            int scalar = (handle.IsBlockAccess == true) ? 2048 : 1;

            size *= scalar;

            if (handle is KStdFile)
            {
                // Handle stdout/err write
                (( KStdFile )handle).Write(( uint )data, size);
            }
            else
            {
                // Probably not the most efficient way ever
                _memory.ReadStream(data, handle.Stream, size);
            }

            handle.Result = size;

            return(size);
        }
コード例 #5
0
        // SDK location: /user/pspiofilemgr.h:419
        // SDK declaration: int sceIoPollAsync(SceUID fd, SceInt64 *res);
        public unsafe int sceIoPollAsync(int fd, int res)
        {
            KFile handle = _kernel.GetHandle <KFile>(fd);

            if (handle == null)
            {
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoPollAsync: kernel file handle not found: {0}", fd);
                return(-1);
            }

            long *pres = ( long * )_memorySystem.Translate(( uint )res);

            *pres = handle.Result;
            handle.Result = 0;

            if (handle.PendingClose == true)
            {
                _kernel.Handles.Remove(handle.UID);
            }

            if (handle.IsValid == false)
            {
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoPollAsync: kernel file handle not valid -> {0:X}, {1:X8}", handle.UID, handle.Result);
                return(0);
            }

            return(0);
        }
コード例 #6
0
        protected async Task CreateZipFromFileContentListCore()
        {
            string        methodName       = GetTempDirectory();
            string        dummyFileZip     = "dummyZip.zip";
            string        dummyFolderPath  = Utils.CreateDummyDirectory(_mockData.ResourceFolder, methodName, cleanFolder: true);
            string        dummyFileZipPath = Path.Combine(dummyFolderPath, dummyFileZip);
            List <string> files            = new List <string>
            {
                Path.Combine(dummyFolderPath, "dummy1.txt"),
                Path.Combine(dummyFolderPath, "dummy2.txt"),
                Path.Combine(dummyFolderPath, "dummy3.txt")
            };

            files.ForEach(file => Utils.CreateDummyFile(dummyFolderPath, Path.GetFileName(file), cleanFolder: false));
            Zipper.CreateZipFileFromFileListWithFileNameOnly(dummyFileZipPath, files);
            byte[] bytesOfZip = await KFile.ReadAllBytesAsync(dummyFileZipPath);

            IList <Core.Support.Pair <string, byte[]> > actualUnzippedFiles = UnZipper.GetFileContentsFromZipFile(bytesOfZip);

            byte[] bytesOfZipFile = Zipper.CreateZipFromFileContentList(actualUnzippedFiles);
            IList <Core.Support.Pair <string, byte[]> > expectedUnzippedFiles = UnZipper.GetFileContentsFromZipFile(dummyFileZipPath);

            Assert.True(expectedUnzippedFiles.Count == actualUnzippedFiles.Count);
            Utils.RemoveDir(dummyFolderPath);
        }
コード例 #7
0
        private void btnCompare_Click(object sender, EventArgs e)
        {
            ListComparer c = new ListComparer();

            c.compareFile = (itemA, itemB) =>
            {
                KFile fA = (KFile)itemA;
                KFile fB = (KFile)itemB;

                if (fA.Size != fB.Size)
                {
                    return(Operation.CHANGED);
                }
                if (string.IsNullOrEmpty(fA.Checksum) || string.IsNullOrEmpty(fB.Checksum))
                {
                    return(Operation.UNKNOWN);
                }
                if (fA.Checksum.Equals(fB.Checksum, StringComparison.OrdinalIgnoreCase))
                {
                    return(Operation.NOCHANGE);
                }
                else
                {
                    return(Operation.CHANGED);
                }
            };
            var res = c.CompareFolder(rootLocal.Children[0], currentItem);

            show_folder_grid((KFile)res);
        }
コード例 #8
0
        public static void TestPath()
        {
            Debug.Assert(KFile.GetUnixFilePath("", true) == "");
            Debug.Assert(KFile.GetUnixFilePath("", false) == "");
            Debug.Assert(KFile.GetUnixFilePath("a", true) == "a/");
            Debug.Assert(KFile.GetUnixFilePath("a/", true) == "a/");
            Debug.Assert(KFile.GetUnixFilePath("a", false) == "a");
            Debug.Assert(KFile.GetUnixFilePath("a/", false) == "a");
            Debug.Assert(KFile.GetUnixFilePath("a\\b", true) == "a/b/");

            String[] SA = KFile.SplitRelativePath("a/b/");
            Debug.Assert(SA.Length == 2);
            Debug.Assert(SA[0] == "a");
            Debug.Assert(SA[1] == "b");

            Debug.Assert(KFile.DirName("") == "");
            Debug.Assert(KFile.DirName("a") == "");
            Debug.Assert(KFile.DirName("a/") == "a/");
            Debug.Assert(KFile.DirName("a/b") == "a/");

            Debug.Assert(KFile.BaseName("") == "");
            Debug.Assert(KFile.BaseName("a") == "a");
            Debug.Assert(KFile.BaseName("a/") == "");
            Debug.Assert(KFile.BaseName("a/b") == "b");

            Debug.Assert(KFile.StripTrailingDelim("") == "");
            Debug.Assert(KFile.StripTrailingDelim("/") == "");
            Debug.Assert(KFile.StripTrailingDelim("a") == "a");
            Debug.Assert(KFile.StripTrailingDelim("a/") == "a");
        }
コード例 #9
0
        private async void frmMain_DragDrop(object sender, DragEventArgs e)
        {
            lbDir.Text = dirCompare = ((string[])e.Data.GetData(DataFormats.FileDrop))[0];

            var dir = await JobWalkDirectories.LoadFolderAsync(dirCompare);

            rootLocal = new KFile();
            rootLocal.Children.Add(dir);
            dir.Parent = rootLocal;
            show_folder_grid(rootLocal);

            load_local_checksum(dir);
        }
コード例 #10
0
        /// <summary>
        /// Compare two rows
        /// </summary>
        /// <param name="x">row1</param>
        /// <param name="y">row2</param>
        /// <returns>An ordering indication: -1, 0, 1</returns>
        public int Compare(KFile x, KFile y)
        {
            if (this.sortOrder == SortOrder.None)
            {
                return(0);
            }

            if (x.Name == "..")
            {
                return(-1);
            }
            else if (y.Name == "..")
            {
                return(1);
            }

            int fol = x.IsFolder.CompareTo(y.IsFolder);

            if (fol != 0)
            {
                return(-fol);
            }

            int    result = 0;
            object x1     = this.column.GetValue(x);
            object y1     = this.column.GetValue(y);

            // Handle nulls. Null values come last
            bool xIsNull = (x1 == null || x1 == System.DBNull.Value);
            bool yIsNull = (y1 == null || y1 == System.DBNull.Value);

            if (xIsNull && yIsNull)
            {
                result = 0;
            }
            else if (xIsNull || yIsNull)
            {
                result = (xIsNull ? -1 : 1);
            }
            else
            {
                result = this.CompareValues(x1, y1);
            }

            if (this.sortOrder == SortOrder.Descending)
            {
                result = 0 - result;
            }

            return(result);
        }
コード例 #11
0
        protected async Task ZipStringCore()
        {
            string tempDir         = GetTempDirectory();
            string dummyFileName   = "dummy.txt";
            string dummyFolderPath = Utils.CreateDummyDirectory(_mockData.ResourceFolder, tempDir, cleanFolder: true);

            Utils.CreateDummyFile(dummyFolderPath, dummyFileName, cleanFolder: true);
            string originalString = await KFile.ReadAllTextAsync(Path.Combine(dummyFolderPath, dummyFileName));

            string zippedString = Zipper.ZipString(originalString);

            Assert.Equal(Zipper.UnZipString(zippedString), originalString);
            Utils.RemoveDir(dummyFolderPath);
        }
コード例 #12
0
        // SDK location: /user/pspiofilemgr.h:288
        // SDK declaration: int sceIoDclose(SceUID fd);
        public int sceIoDclose(int fd)
        {
            KFile handle = _kernel.GetHandle <KFile>(fd);

            if (handle == null)
            {
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoDclose: kernel dir handle {0} not found", fd);
                return(-1);
            }

            handle.IsOpen = false;
            _kernel.Handles.Remove(handle.UID);

            return(0);
        }
コード例 #13
0
        protected async Task ZipByteArrayCore()
        {
            string tempDir         = GetTempDirectory();
            string dummyFileName   = "dummy.txt";
            string dummyFolderPath = Utils.CreateDummyDirectory(_mockData.ResourceFolder, tempDir, cleanFolder: true);
            string dummyFilePath   = Utils.CreateDummyFile(dummyFolderPath, dummyFileName, cleanFolder: true);

            byte[] expectedBytes = await KFile.ReadAllBytesAsync(dummyFilePath);

            byte[] zippedBytes         = Zipper.ZipByteArray(expectedBytes, "pippo");
            byte[] actualUnzippedBytes = await Zipper.UnZipSingleFileContentToByteArrayAsync(zippedBytes).ConfigureAwait(false);

            Assert.Equal(expectedBytes, actualUnzippedBytes);
            Utils.RemoveDir(dummyFolderPath);
        }
コード例 #14
0
ファイル: Utils.cs プロジェクト: Kyklos-Italy/bcl-tests
        private static async Task <string> _GetAPIKey()
        {
            string APIkeyFilename = "api_key.txt";

            try
            {
                return(await KFile.ReadAllTextAsync(APIkeyFilename).ConfigureAwait(false));
            }
            catch (Exception exception)
            {
                await Console.Out.WriteLineAsync($"Could not read admin APIs key from {APIkeyFilename}: {exception.Message}").ConfigureAwait(false);

                return(string.Empty);
            }
        }
コード例 #15
0
        private void olvFiles_DoubleClick(object sender, EventArgs e)
        {
            var item = (KFile)olvFiles.SelectedObjects[0];

            if (item.Name == "..")
            {
                show_folder_grid((KFile)item.Parent);
                olvFiles.SelectedObject = currentItem;
                currentItem             = (KFile)item.Parent;
            }
            else
            {
                show_folder_grid(item);
                currentItem = item;
            }
        }
コード例 #16
0
 void show_folder_grid(KFile item)
 {
     if (item.Parent != null)
     {
         KFile parentFolder = new KFile {
             Name = "..", Parent = item.Parent
         };
         var list = new List <KFile> {
             parentFolder
         };
         list.AddRange(item.Children.Cast <KFile>());
         olvFiles.SetObjects(list);
     }
     else
     {
         olvFiles.SetObjects(item.Children);
     }
 }
コード例 #17
0
        void load_local_checksum(KFile item)
        {
            string root          = Path.GetDirectoryName(item.Path);
            string file_checksum = Path.Combine(root, $"{item.Name}.MD5");

            if (!System.IO.File.Exists(file_checksum))
            {
                return;
            }

            Dictionary <string, string> dic_checksum = new Dictionary <string, string>();
            const string record_pattern_md5          = @"^(\w{32}) \*?(.+)$";

            using (var stream = System.IO.File.OpenText(file_checksum))
            {
                while (!stream.EndOfStream)
                {
                    string line = stream.ReadLine();
                    Match  m    = Regex.Match(line, record_pattern_md5);
                    if (m.Success)
                    {
                        dic_checksum[Path.Combine(root, m.Groups[2].Value)] = m.Groups[1].Value;
                    }
                }
            }

            update_checksum(item);

            void update_checksum(KFile folder)
            {
                foreach (KFile child in folder.Children)
                {
                    if (child.IsFolder)
                    {
                        update_checksum(child);
                    }
                    else if (dic_checksum.TryGetValue(child.Path, out string cs))
                    {
                        child.Checksum = cs;
                    }
                }
            }
        }
コード例 #18
0
        // SDK location: /user/pspiofilemgr.h:198
        // SDK declaration: int sceIoLseek32(SceUID fd, int offset, int whence);
        public int sceIoLseek32(int fd, int offset, int whence)
        {
            KFile handle = _kernel.GetHandle <KFile>(fd);

            if (handle == null)
            {
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoLseek32: kernel file handle not found: {0:X}", fd);
                return(-1);
            }

            int scalar = (handle.IsBlockAccess == true) ? 2048 : 1;

            SeekOrigin seekOrigin;

            switch (whence)
            {
            default:
            case 0:
                seekOrigin = SeekOrigin.Begin;
                if (offset > handle.Stream.Length)
                {
                    offset = 0;
                }
                break;

            case 1:
                seekOrigin = SeekOrigin.Current;
                Debug.Assert(handle.Stream.Position + offset <= handle.Stream.Length);
                break;

            case 2:
                seekOrigin = SeekOrigin.End;
                Debug.Assert(handle.Stream.Length + offset <= handle.Stream.Length);
                break;
            }

            int ret = ( int )handle.Stream.Seek(offset * scalar, seekOrigin);

            handle.Result = ret;
            return(ret);
        }
コード例 #19
0
        // SDK location: /user/pspiofilemgr.h:368
        // SDK declaration: int sceIoIoctl(SceUID fd, unsigned int cmd, void *indata, int inlen, void *outdata, int outlen);
        public unsafe int sceIoIoctl(int fd, int cmd, int indata, int inlen, int outdata, int outlen)
        {
            KFile handle = _kernel.GetHandle <KFile>(fd);

            if (handle == null)
            {
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoIoctl: kernel file handle not found: {0}", fd);
                return(-1);
            }

            byte *inp  = ( byte * )0;
            byte *outp = ( byte * )0;

            if (indata != 0)
            {
                inp = _memorySystem.Translate(( uint )indata);
            }
            if (outdata != 0)
            {
                outp = _memorySystem.Translate(( uint )outdata);
            }

            switch (cmd)
            {
            case IoctlGetSectorSize:
                Debug.Assert(outlen == 4);
                *( uint * )outp = 2048;
                return(0);

            case IoctlGetFilePointer:
                // Not sure if this is 64 or 32
                Debug.Assert(outlen == 8);
                Debug.Assert(handle.Stream != null);
                *( ulong * )outp = ( ulong )handle.Stream.Position;
                return(0);

            default:
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoIoctl: unknown command 0x" + cmd.ToString("X8"));
                return(0);
            }
        }
コード例 #20
0
        // SDK location: /user/pspiofilemgr.h:85
        // SDK declaration: int sceIoClose(SceUID fd);
        public int sceIoClose(int fd)
        {
            KFile handle = _kernel.GetHandle <KFile>(fd);

            if (handle == null)
            {
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoClose: kernel file handle not found: {0:X}", fd);
                return(-1);
            }

            Debug.Assert(handle.IsOpen == true);

            if (handle.Stream != null)
            {
                handle.Stream.Close();
            }
            handle.IsOpen = false;
            _kernel.Handles.Remove(handle.UID);

            return(0);
        }
コード例 #21
0
        // SDK location: /user/pspiofilemgr.h:267
        // SDK declaration: SceUID sceIoDopen(const char *dirname);
        public int sceIoDopen(int dirname)
        {
            string       path   = _kernel.ReadString(( uint )dirname);
            IMediaFolder folder = ( IMediaFolder )_kernel.FindPath(path);

            if (folder == null)
            {
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoDopen: could not find path {0}", path);
                return(-1);
            }

            KDevice dev = _kernel.FindDevice(folder.Device);

            KFile handle = new KFile(_kernel, dev, folder);

            handle.FolderOffset = -2;
            _kernel.AddHandle(handle);

            Log.WriteLine(Verbosity.Verbose, Feature.Bios, "sceIoDopen: opened {0} with ID {1:X}", path, handle.UID);

            return(( int )handle.UID);
        }
コード例 #22
0
        // SDK location: /user/pspmodulemgr.h:91
        // SDK declaration: SceUID sceKernelLoadModuleByID(SceUID fid, int flags, SceKernelLMOption *option);
        public int sceKernelLoadModuleByID(int fid, int flags, int option)
        {
            KFile handle = _kernel.GetHandle <KFile>(fid);

            if (handle == null)
            {
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceKernelLoadModuleByID: file handle {0} not found", fid);
                return(-1);
            }

            Debug.Assert(handle.IsOpen == true);

            if (handle.Item != null)
            {
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceKernelLoadModuleByID: loading module with file handle {0} (source: {1})", fid, handle.Item.AbsolutePath);
            }
            else
            {
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceKernelLoadModuleByID: loading module with file handle {0}", fid);
            }

            return(this.LoadModule(( IMediaFile )handle.Item, handle.Stream, flags, option));
        }
コード例 #23
0
        private void olvFiles_FormatRow(object sender, FormatRowEventArgs e)
        {
            KFile item = (KFile)e.Model;

            switch (item.operation)
            {
            case Operation.CHANGED:
                e.Item.ForeColor = Color.DarkMagenta;
                break;

            case Operation.NEW:
                e.Item.ForeColor = Color.RoyalBlue;
                break;

            case Operation.DELETE:
                e.Item.ForeColor = Color.Crimson;
                break;

            case Operation.UNKNOWN:
                e.Item.ForeColor = Color.Orange;
                break;
            }
        }
コード例 #24
0
        // SDK location: /user/pspiofilemgr.h:93
        // SDK declaration: int sceIoCloseAsync(SceUID fd);
        public int sceIoCloseAsync(int fd)
        {
            // Need to keep the handle alive until the poll somehow
            KFile handle = _kernel.GetHandle <KFile>(fd);

            if (handle == null)
            {
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoCloseAsync: kernel file handle not found: {0:X}", fd);
                return(-1);
            }

            Debug.Assert(handle.IsOpen == true);

            if (handle.Stream != null)
            {
                handle.Stream.Close();
            }
            handle.IsOpen = false;
            handle.Result = 0;

            handle.PendingClose = true;

            return(0);
        }
コード例 #25
0
        public int sceIoDopen( int dirname )
        {
            string path = _kernel.ReadString( ( uint )dirname );
            IMediaFolder folder = ( IMediaFolder )_kernel.FindPath( path );
            if( folder == null )
            {
                Log.WriteLine( Verbosity.Normal, Feature.Bios, "sceIoDopen: could not find path {0}", path );
                return -1;
            }

            KDevice dev = _kernel.FindDevice( folder.Device );

            KFile handle = new KFile( _kernel, dev, folder );
            handle.FolderOffset = -2;
            _kernel.AddHandle( handle );

            Log.WriteLine( Verbosity.Verbose, Feature.Bios, "sceIoDopen: opened {0} with ID {1:X}", path, handle.UID );

            return ( int )handle.UID;
        }
コード例 #26
0
        // SDK location: /user/pspiofilemgr.h:280
        // SDK declaration: int sceIoDread(SceUID fd, SceIoDirent *dir);
        public int sceIoDread(int fd, int dir)
        {
            KFile handle = _kernel.GetHandle <KFile>(fd);

            if (handle == null)
            {
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoDread: kernel dir handle {0:X} not found", fd);
                return(-1);
            }

            int offset = handle.FolderOffset;

            handle.FolderOffset++;

            IMediaFolder folder = ( IMediaFolder )handle.Item;

            if (offset == folder.Items.Length)
            {
                return(0);
            }

            // (d_stat)
            //	SceMode			st_mode
            //	unsigned int	st_attr
            //	SceOff			st_size  (64)
            //	ScePspDateTime	st_ctime
            //	ScePspDateTime	st_atime
            //	ScePspDateTime	st_mtime
            //	unsigned int	st_private [6]
            //char				d_name [256]
            //void*				d_private
            //int				dummy

            if ((offset == -2) ||
                (offset == -1))
            {
                int address = dir;
                _memory.WriteWord(address, 4, 0777);
                address += 4;

                uint attributes = 0x0010;
                _memory.WriteWord(address, 4, ( int )attributes);
                address += 4;

                _memory.WriteWord(address, 4, 0);
                _memory.WriteWord(address + 4, 4, 0);
                address += 8;

                address += _kernel.WriteTime(( uint )address, DateTime.Now);
                address += _kernel.WriteTime(( uint )address, DateTime.Now);
                address += _kernel.WriteTime(( uint )address, DateTime.Now);

                address += 6 * 4;                 // no private stat data - blank here?

                String name       = (offset == -2) ? "." : "..";
                int    nameLength = _kernel.WriteString(( uint )address, name);
                address += 256;                 // Maybe blank here?

                _memory.WriteWord(address, 4, 0);
                address += 4;                 // no private dir data

                _memory.WriteWord(address, 4, 0);
                address += 4;
            }
            else
            {
                IMediaItem   child       = folder.Items[offset];
                IMediaFolder childFolder = null;
                IMediaFile   childFile   = null;
                if (child.GetType().GetInterface("IMediaFolder", false) != null)
                {
                    childFolder = ( IMediaFolder )child;
                }
                else
                {
                    childFile = ( IMediaFile )child;
                }

                int address = dir;
                int mode    = 0777;             // | ( ( childFolder != null ) ? 0x10 : 0x20 );
                _memory.WriteWord(address, 4, mode);
                address += 4;

                uint attributes = 0;
                //if( ( child.Attributes & MediaItemAttributes.Hidden ) == MediaItemAttributes.Hidden )
                //	attributes |= 0;
                //if( ( child.Attributes & MediaItemAttributes.ReadOnly ) == MediaItemAttributes.ReadOnly )
                //	attributes |= 0;
                if (childFile != null)
                {
                    attributes |= 0x0020;
                }
                if (childFolder != null)
                {
                    attributes |= 0x0010;
                }
                if (child.IsSymbolicLink == true)
                {
                    attributes |= 0x0008;
                }
                _memory.WriteWord(address, 4, ( int )attributes);
                address += 4;

                if (childFile != null)
                {
                    _memory.WriteWord(address, 4, ( int )childFile.Length);
                }
                else
                {
                    _memory.WriteWord(address, 4, 0);
                }
                _memory.WriteWord(address + 4, 4, 0);
                address += 8;

                address += _kernel.WriteTime(( uint )address, child.CreationTime);
                address += _kernel.WriteTime(( uint )address, child.AccessTime);
                address += _kernel.WriteTime(( uint )address, child.ModificationTime);

                // private[ 0 ] = start sector on disk
                if (childFile != null)
                {
                    _memory.WriteWord(address, 4, ( int )( uint )childFile.LogicalBlockNumber);
                }
                else
                {
                    _memory.WriteWord(address, 4, 0);
                }
                address += 5 * 4;                 // no private stat data - blank here?

                int nameLength = _kernel.WriteString(( uint )address, child.Name);
                address += 256;                 // Maybe blank here?

                _memory.WriteWord(address, 4, 0);
                address += 4;                 // no private dir data

                _memory.WriteWord(address, 4, 0);
                address += 4;
            }

            // 0 to stop, 1 to keep going
            return(1);
        }
コード例 #27
0
		public int realIoOpen( int fileName, int flags, int mode, bool async )
		{
			string path = _kernel.ReadString( ( uint )fileName );
			if( string.IsNullOrEmpty( path ) == true )
				return -1;
			IMediaItem item = _kernel.FindPath( path );
			if( item is IMediaFolder )
			{
				// Block access?
				Debug.Assert( item.Device is IUmdDevice );
				IUmdDevice umd = ( IUmdDevice )item.Device;
				Stream stream = umd.OpenImageStream();
				if( stream == null )
				{
					Log.WriteLine( Verbosity.Normal, Feature.Bios, "sceIoOpen: could not open image stream '{0}'", path );

					if( async == true )
					{
						KFile fakehandle = new KFile( _kernel, false );
						fakehandle.Result = 0x80010002;
						fakehandle.PendingClose = true;
						_kernel.AddHandle( fakehandle );
						return ( int )fakehandle.UID;
					}

					return -1;
				}

				KDevice dev = _kernel.FindDevice( umd );
				Debug.Assert( dev != null );

				KFile handle = new KFile( _kernel, dev, item, stream );
				handle.IsBlockAccess = true;
				_kernel.AddHandle( handle );

				handle.Result = handle.UID;

				Log.WriteLine( Verbosity.Verbose, Feature.Bios, "sceIoOpen: opened block access on {0} with ID {1:X}", path, handle.UID );

				return ( int )handle.UID;
			}
			else
			{
				IMediaFile file = ( IMediaFile )item;
				if( file == null )
				{
					// Create if needed
					if( ( flags & 0x0200 ) != 0 )
					{
						string newName;
						IMediaFolder parent;
						if( path.IndexOf( '/' ) >= 0 )
						{
							string parentPath = path.Substring( 0, path.LastIndexOf( '/' ) );
							newName = path.Substring( path.LastIndexOf( '/' ) + 1 );
							parent = ( IMediaFolder )_kernel.FindPath( parentPath );
						}
						else
						{
							newName = path;
							parent = _kernel.CurrentPath;
						}
						if( parent == null )
						{
							Log.WriteLine( Verbosity.Normal, Feature.Bios, "sceIoOpen: could not find parent to create file '{0}' in on open", path );

							if( async == true )
							{
								KFile fakehandle = new KFile( _kernel, false );
								fakehandle.Result = 0x80010002;
								fakehandle.PendingClose = true;
								_kernel.AddHandle( fakehandle );
								return ( int )fakehandle.UID;
							}

							return -1;
						}
						file = parent.CreateFile( newName );
					}
					else
					{
						Log.WriteLine( Verbosity.Normal, Feature.Bios, "sceIoOpen: could not find path '{0}'", path );

						if( async == true )
						{
							KFile fakehandle = new KFile( _kernel, false );
							fakehandle.Result = 0x80010002;
							fakehandle.PendingClose = true;
							_kernel.AddHandle( fakehandle );
							return ( int )fakehandle.UID;
						}

						return unchecked( ( int )0x8002012f );
					}
				}
				/*
				 *	#define PSP_O_RDONLY	0x0001
					#define PSP_O_WRONLY	0x0002
					#define PSP_O_RDWR		(PSP_O_RDONLY | PSP_O_WRONLY)
					#define PSP_O_NBLOCK	0x0004
					#define PSP_O_DIROPEN	0x0008	// Internal use for dopen
					#define PSP_O_APPEND	0x0100
					#define PSP_O_CREAT		0x0200
					#define PSP_O_TRUNC		0x0400
					#define	PSP_O_EXCL		0x0800
					#define PSP_O_NOWAIT	0x8000*/
				MediaFileMode fileMode = MediaFileMode.Normal;
				if( ( flags & 0x0100 ) == 0x0100 )
					fileMode = MediaFileMode.Append;
				if( ( flags & 0x0400 ) == 0x0400 )
					fileMode = MediaFileMode.Truncate;
				MediaFileAccess fileAccess = MediaFileAccess.ReadWrite;
				if( ( flags & 0x0001 ) == 0x0001 )
					fileAccess = MediaFileAccess.Read;
				if( ( flags & 0x0002 ) == 0x0002 )
					fileAccess = MediaFileAccess.Write;
				if( ( flags & 0x0003 ) == 0x0003 )
					fileAccess = MediaFileAccess.ReadWrite;

				if( ( flags & 0x0800 ) != 0 )
				{
					// Exclusive O_EXCL
					//int x = 1;
				}
				if( ( flags & 0x8000 ) != 0 )
				{
					// Non-blocking O_NOWAIT
					//int x = 1;
				}
				if( ( flags & 0x0004 ) != 0 )
				{
					// ? O_NBLOCK
					//int x = 1;
				}

				Stream stream = file.Open( fileMode, fileAccess );
				if( stream == null )
				{
					Log.WriteLine( Verbosity.Normal, Feature.Bios, "sceIoOpen: could not open stream on file '{0}' for mode {1} access {2}", path, fileMode, fileAccess );
					return -1;
				}

				IMediaDevice device = file.Device;
				KDevice dev = _kernel.FindDevice( file.Device );
				Debug.Assert( dev != null );

				KFile handle = new KFile( _kernel, dev, file, stream );
				_kernel.AddHandle( handle );

				handle.Result = handle.UID;

				Log.WriteLine( Verbosity.Verbose, Feature.Bios, "sceIoOpen: opened file {0} with ID {1:X}", path, handle.UID );

				return ( int )handle.UID;
			}
		}
コード例 #28
0
 public static string SaveTextureAsPNG(Texture2D _texture, string _fullPath)
 {
     byte[] _bytes = _texture.EncodeToPNG();
     File.WriteAllBytes(_fullPath, _bytes);
     return(KFile.Format(_bytes.Length));
 }
コード例 #29
0
        public int realIoOpen(int fileName, int flags, int mode, bool async)
        {
            string path = _kernel.ReadString(( uint )fileName);

            if (string.IsNullOrEmpty(path) == true)
            {
                return(-1);
            }
            IMediaItem item = _kernel.FindPath(path);

            if (item is IMediaFolder)
            {
                // Block access?
                Debug.Assert(item.Device is IUmdDevice);
                IUmdDevice umd    = ( IUmdDevice )item.Device;
                Stream     stream = umd.OpenImageStream();
                if (stream == null)
                {
                    Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoOpen: could not open image stream '{0}'", path);

                    if (async == true)
                    {
                        KFile fakehandle = new KFile(_kernel, false);
                        fakehandle.Result       = 0x80010002;
                        fakehandle.PendingClose = true;
                        _kernel.AddHandle(fakehandle);
                        return(( int )fakehandle.UID);
                    }

                    return(-1);
                }

                KDevice dev = _kernel.FindDevice(umd);
                Debug.Assert(dev != null);

                KFile handle = new KFile(_kernel, dev, item, stream);
                handle.IsBlockAccess = true;
                _kernel.AddHandle(handle);

                handle.Result = handle.UID;

                Log.WriteLine(Verbosity.Verbose, Feature.Bios, "sceIoOpen: opened block access on {0} with ID {1:X}", path, handle.UID);

                return(( int )handle.UID);
            }
            else
            {
                IMediaFile file = ( IMediaFile )item;
                if (file == null)
                {
                    // Create if needed
                    if ((flags & 0x0200) != 0)
                    {
                        string       newName;
                        IMediaFolder parent;
                        if (path.IndexOf('/') >= 0)
                        {
                            string parentPath = path.Substring(0, path.LastIndexOf('/'));
                            newName = path.Substring(path.LastIndexOf('/') + 1);
                            parent  = ( IMediaFolder )_kernel.FindPath(parentPath);
                        }
                        else
                        {
                            newName = path;
                            parent  = _kernel.CurrentPath;
                        }
                        if (parent == null)
                        {
                            Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoOpen: could not find parent to create file '{0}' in on open", path);

                            if (async == true)
                            {
                                KFile fakehandle = new KFile(_kernel, false);
                                fakehandle.Result       = 0x80010002;
                                fakehandle.PendingClose = true;
                                _kernel.AddHandle(fakehandle);
                                return(( int )fakehandle.UID);
                            }

                            return(-1);
                        }
                        file = parent.CreateFile(newName);
                    }
                    else
                    {
                        Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoOpen: could not find path '{0}'", path);

                        if (async == true)
                        {
                            KFile fakehandle = new KFile(_kernel, false);
                            fakehandle.Result       = 0x80010002;
                            fakehandle.PendingClose = true;
                            _kernel.AddHandle(fakehandle);
                            return(( int )fakehandle.UID);
                        }

                        return(unchecked (( int )0x8002012f));
                    }
                }

                /*
                 *	#define PSP_O_RDONLY	0x0001
                 #define PSP_O_WRONLY	0x0002
                 #define PSP_O_RDWR		(PSP_O_RDONLY | PSP_O_WRONLY)
                 #define PSP_O_NBLOCK	0x0004
                 #define PSP_O_DIROPEN	0x0008	// Internal use for dopen
                 #define PSP_O_APPEND	0x0100
                 #define PSP_O_CREAT		0x0200
                 #define PSP_O_TRUNC		0x0400
                 #define	PSP_O_EXCL		0x0800
                 #define PSP_O_NOWAIT	0x8000*/
                MediaFileMode fileMode = MediaFileMode.Normal;
                if ((flags & 0x0100) == 0x0100)
                {
                    fileMode = MediaFileMode.Append;
                }
                if ((flags & 0x0400) == 0x0400)
                {
                    fileMode = MediaFileMode.Truncate;
                }
                MediaFileAccess fileAccess = MediaFileAccess.ReadWrite;
                if ((flags & 0x0001) == 0x0001)
                {
                    fileAccess = MediaFileAccess.Read;
                }
                if ((flags & 0x0002) == 0x0002)
                {
                    fileAccess = MediaFileAccess.Write;
                }
                if ((flags & 0x0003) == 0x0003)
                {
                    fileAccess = MediaFileAccess.ReadWrite;
                }

                if ((flags & 0x0800) != 0)
                {
                    // Exclusive O_EXCL
                    //int x = 1;
                }
                if ((flags & 0x8000) != 0)
                {
                    // Non-blocking O_NOWAIT
                    //int x = 1;
                }
                if ((flags & 0x0004) != 0)
                {
                    // ? O_NBLOCK
                    //int x = 1;
                }

                Stream stream = file.Open(fileMode, fileAccess);
                if (stream == null)
                {
                    Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoOpen: could not open stream on file '{0}' for mode {1} access {2}", path, fileMode, fileAccess);
                    return(-1);
                }

                IMediaDevice device = file.Device;
                KDevice      dev    = _kernel.FindDevice(file.Device);
                Debug.Assert(dev != null);

                KFile handle = new KFile(_kernel, dev, file, stream);
                _kernel.AddHandle(handle);

                handle.Result = handle.UID;

                Log.WriteLine(Verbosity.Verbose, Feature.Bios, "sceIoOpen: opened file {0} with ID {1:X}", path, handle.UID);

                return(( int )handle.UID);
            }
        }