Пример #1
0
        public IFileSystem ReadDisk(WorkspacePath path)
        {
            IFileSystem disk = null;

            // Found disk to load
            if (path.IsDirectory)
            {
                disk = new SubFileSystem(this, path);
            }
            else if (path.IsFile)
            {
                if (archiveExtensions.IndexOf(path.Path.Split('.').Last()) > -1)
                {
                    using (var stream = ZipFileSystem.Open(OpenFile(path, FileAccess.Read) as FileStream))
                    {
                        disk = stream;

                        // TODO need to see how we can close the stream?
//                        stream.Close();
                    }
                }
            }

            return(disk);
        }
Пример #2
0
        public string[] LoadGame(string path)
        {
            var filePath = WorkspacePath.Parse(path);
            var exits    = Exists(filePath);

            string[] files = null;

            if (exits)
            {
                // Found disk to load
                if (filePath.IsDirectory)
                {
                    currentDisk = new SubFileSystem(this, filePath);
                }
                else if (filePath.IsFile)
                {
                    // TODO need to figure out how to do this from a disk now without the currentDisk drive?
                    if (archiveExtensions.IndexOf(filePath.Path.Split('.').Last()) > -1)
                    {
                        using (var stream = OpenFile(filePath, FileAccess.ReadWrite))
                        {
                            if (stream is FileStream)
                            {
                                currentDisk = ZipFileSystem.Open((FileStream)stream);
                            }
                            else
                            {
                                currentDisk = ZipFileSystem.Open(stream, path);
                            }

                            stream.Close();
                        }
                    }
                }

                // We need to get a list of the current mounts

                if (Mounts is SortedList <WorkspacePath, IFileSystem> mounts)
                {
                    // Create a new mount point for the current game
                    var rootPath = WorkspacePath.Root.AppendDirectory("Game");

                    // Make sure we don't have a disk with the same name
                    if (mounts.ContainsKey(rootPath))
                    {
                        mounts.Remove(rootPath);
                    }

                    mounts.Add(rootPath, currentDisk);

                    // Filter out only the files we can use and convert this into a dictionary with the file name as the key and the path as the value
                    files = GetGameEntities(rootPath);
                }
            }

            return(files);
        }
Пример #3
0
        public string MountDisk(string path)
        {
            IFileSystem disk;

            string entityName;

            var attr = File.GetAttributes(path);

            if (attr.HasFlag(FileAttributes.Directory))
            {
                entityName = new DirectoryInfo(path).Name;
            }
            else
            {
                entityName = Path.GetFileNameWithoutExtension(path);
            }

            if (path.EndsWith(".pv8") || path.EndsWith(".zip"))
            {
                disk = ZipFileSystem.Open(path);
            }
            else
            {
                disk = new PhysicalFileSystem(path);
            }

            if (disk == null)
            {
                return(null);
            }

            // Test to see if the disk is a valid game
            if (ValidateGameInDir(disk) == false &&
                disk.Exists(WorkspacePath.Root.AppendFile("info.json")) == false)
            {
                return(null);
            }

            // Update the root path to just be the name of the entity
            var rootPath = WorkspacePath.Root.AppendDirectory("Disks").AppendDirectory(entityName);

            // Add the new disk
            AddDisk(rootPath, disk);

            // Return the disk name
            return(entityName);
        }
Пример #4
0
        static void Main(string[] args)
        {
            try
            {
                foreach (var path in Directory.EnumerateDirectories("."))
                {
                    CleanDirectory(path);
                    ProcessProfiles(DiskFileSystem.Folder(path), Path.Combine(path, "profiles.json"));
                }

                foreach (var zip in Directory.EnumerateFiles(".", "*.zip"))
                {
                    ProcessProfiles(ZipFileSystem.Open(zip), Path.ChangeExtension(zip, "json"));
                }
                ProcessProfiles(DiskFileSystem.Folder(PortableFrameworkProfileEnumerator.MachineProfilePath), "profiles.json");

                Console.WriteLine("Done.");
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
            }
            Console.ReadKey();
        }
Пример #5
0
        public Dictionary <string, byte[]> LoadGame(string path)
        {
            var filePath = WorkspacePath.Parse(path); //FileSystemPath.Root.AppendPath(fullPath);
            var exits    = Exists(filePath);

            Dictionary <string, byte[]> files = null;

            if (exits)
            {
                try
                {
                    // Found disk to load
                    if (filePath.IsDirectory)
                    {
                        currentDisk = new SubFileSystem(this, filePath);
                    }
                    else if (filePath.IsFile)
                    {
                        if (archiveExtensions.IndexOf(filePath.Path.Split('.').Last()) > -1)
                        {
                            using (var stream = OpenFile(filePath, FileAccess.ReadWrite))
                            {
                                if (stream is FileStream)
                                {
                                    currentDisk = ZipFileSystem.Open((FileStream)stream);
                                }
                                else
                                {
                                    currentDisk = ZipFileSystem.Open(stream, path);
                                }

                                stream.Close();
                            }
                        }
                    }

                    // We need to get a list of the current mounts
                    var mounts = Mounts as SortedList <WorkspacePath, IFileSystem>;

                    // Create a new mount point for the current game
                    var rootPath = WorkspacePath.Root.AppendDirectory("Game");

                    // Make sure we don't have a disk with the same name
                    if (mounts.ContainsKey(rootPath))
                    {
                        mounts.Remove(rootPath);
                    }

                    mounts.Add(rootPath, currentDisk);

                    files = ConvertDiskFilesToBytes(currentDisk);

                    IncludeLibDirectoryFiles(files);


                    try
                    {
                        // Convert the path to a system path
                        var tmpFilePath = WorkspacePath.Parse(path);


                        // TODO should we still try to load the saves file from a zip?

                        // If the path is a directory we are going to look for a save file in it
                        if (tmpFilePath.IsDirectory)
                        {
                            tmpFilePath = tmpFilePath.AppendFile("saves.json");

//                        if (WriteAccess(tmpFilePath) == false)
//                        {
                            // Check if save file is in tmp directory
                            var saveFile = WorkspacePath.Parse(FindValidSavePath(tmpFilePath.Path));

                            if (saveFile.Path != "/" && Exists(saveFile))
                            {
                                using (var memoryStream = new MemoryStream())
                                {
                                    using (var file = OpenFile(saveFile, FileAccess.Read))
                                    {
                                        file.CopyTo(memoryStream);
                                        file.Close();
                                    }

                                    var fileName = saveFile.EntityName;
                                    var data     = memoryStream.ToArray();

                                    if (files.ContainsKey(fileName))
                                    {
                                        files[fileName] = data;
                                    }
                                    else
                                    {
                                        files.Add(fileName, data);
                                    }

                                    memoryStream.Close();
                                }
                            }
                        }


//                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }


//                    return true;
                }
                catch
                {
                    //		        // TODO need to have a clearer messgae, like not a mount point or can't load from X because of Y
//                    Console.WriteLine("System Error: Could not load from path " + filePath.Path);
                }
            }

            return(files);
        }