Exemplo n.º 1
0
        private void OnExtractFileArchivePath(string path)
        {
            // Get the appropriate archive type
            string      extension = Path.GetExtension(path);
            ArchiveFile archive;

            switch (extension.ToLower())
            {
            case ".vol":    archive = new VolFile(path);    break;

            case ".clm":    archive = new ClmFile(path);    break;

            default:
                interactable = true;
                Debug.Log("Invalid archive selected.");
                return;
            }

            // Get list of files from the archive
            List <string> fileNames = new List <string>();

            for (int i = 0; i < archive.GetCount(); ++i)
            {
                fileNames.Add(archive.GetName(i));
            }

            // Open list of file names for selection
            ListSelectDialog.Create(fileNames, "Extract File", "Select", (string fileName) => OnExtractFileSelected(archive, fileName), () => OnExtractFileCanceled(archive));
        }
Exemplo n.º 2
0
        private void OnImportMapPath(string path)
        {
            string extension = Path.GetExtension(path);

            switch (extension.ToLower())
            {
            case ".vol":
                List <string> fileNames = new List <string>();

                // Get list of map names from the archive
                VolFile vol = new VolFile(path);
                for (int i = 0; i < vol.GetCount(); ++i)
                {
                    string name = vol.GetName(i);
                    if (Path.GetExtension(name).ToLower() == ".map")
                    {
                        fileNames.Add(name);
                    }
                }

                // Open list of map names for selection
                ListSelectDialog.Create(fileNames, "Select Map", "Import", (string mapName) => OnImportMapSelected(vol, mapName), () =>
                {
                    interactable = true;
                    vol.Dispose();
                });

                break;

            default:
                CreateNew_NoRefresh();

                interactable = true;

                if (UserData.current.ImportMap(path))
                {
                    interactable = false;

                    m_MapRenderer.Refresh(() =>
                    {
                        interactable = true;
                        Debug.Log("Import Complete.");
                    });
                }
                else
                {
                    // Import failed
                    interactable = false;

                    m_MapRenderer.Refresh(() =>
                    {
                        interactable = true;
                        Debug.LogError("Failed to read map: " + path);
                    });
                }
                break;
            }
        }
Exemplo n.º 3
0
        bool IPackageLoader.TryParsePackage(Stream s, string filename, FS context, out IReadOnlyPackage package)
        {
            if (!filename.EndsWith(".vol", StringComparison.InvariantCultureIgnoreCase))
            {
                package = null;
                return(false);
            }

            package = new VolFile(s, filename);
            return(true);
        }
Exemplo n.º 4
0
        public void GetArchiveFilenames()
        {
            string archiveName = "./Test.vol";

            VolFile.CreateArchive(archiveName, new string[0]);

            // Scope block to ensures ResourceManager is destructed after use
            // This ensures the VOL file is closed before attempting to delete it
            // This is needed for Windows filesystem semantics
            using (ResourceManager resourceManager = new ResourceManager("./"))
            {
                CollectionAssert.AreEqual(new string[] { archiveName }, resourceManager.GetArchiveFilenames());
            }

            File.Delete(archiveName);
        }
Exemplo n.º 5
0
        private void CreateArchive(string srcDirectory, string archivePath)
        {
            interactable = true;

            string[] files = Directory.GetFiles(srcDirectory, "*.*", SearchOption.TopDirectoryOnly);

            // Cull file names that are too long
            List <string> culledFiles = new List <string>(files.Length);

            foreach (string name in files)
            {
                string noExt = Path.GetFileNameWithoutExtension(name);

                if (noExt.Length <= 8)
                {
                    culledFiles.Add(name);
                }
            }


            string extension = Path.GetExtension(archivePath);

            switch (extension)
            {
            case ".vol":    VolFile.CreateArchive(archivePath, culledFiles);        break;

            case ".clm":    ClmFile.CreateArchive(archivePath, culledFiles);        break;

            default:
                Debug.Log("Invalid archive type selected.");
                return;
            }

            if (files.Length == culledFiles.Count)
            {
                Debug.Log(Path.GetFileName(archivePath) + " created successfully.");
            }
            else
            {
                int filesRemoved = files.Length - culledFiles.Count;
                Debug.Log(filesRemoved.ToString() + " files exceeded 8 character limit and were not archived.");
            }
        }
Exemplo n.º 6
0
        public void VolFile_EmptyArchive()
        {
            const string archiveFilename = "EmptyArchive.vol";

            {
                // Create an empty archive
                List <string> filesToPack = new List <string>();
                VolFile.CreateArchive(archiveFilename, filesToPack);

                using (VolFile archiveFile = new VolFile(archiveFilename))
                {
                    //SCOPED_TRACE("Empty Volume File");
                    TestEmptyArchive(archiveFile, archiveFilename);

                    Assert.ThrowsException <ArgumentOutOfRangeException>(() => archiveFile.GetCompressionCode(0));
                }
            }

            File.Delete(archiveFilename);
        }
Exemplo n.º 7
0
        private void OnImportMapSelected(VolFile volFile, string mapName)
        {
            interactable = true;

            Stream mapStream = volFile.OpenStream(mapName);

            if (!UserData.current.ImportMap(mapStream))
            {
                Debug.LogError("Failed to read map: " + mapName);
                volFile.Dispose();
                return;
            }

            volFile.Dispose();

            interactable = false;

            m_MapRenderer.Refresh(() =>
            {
                interactable = true;
                Debug.Log("Import map complete.");
            });
        }
Exemplo n.º 8
0
        private void OnExtractAllFilesSavePathSelected(string archivePath, string destDirectory)
        {
            interactable = true;

            // Get the appropriate archive type
            string      extension = Path.GetExtension(archivePath);
            ArchiveFile archive;

            switch (extension.ToLower())
            {
            case ".vol":    archive = new VolFile(archivePath);     break;

            case ".clm":    archive = new ClmFile(archivePath);     break;

            default:
                Debug.Log("Invalid archive selected.");
                return;
            }

            archive.ExtractAllFiles(destDirectory);
            archive.Dispose();

            Debug.Log("Files extracted successfully.");
        }
Exemplo n.º 9
0
        private static IEnumerator LoadSoundsRoutine(string archivePath)
        {
            float startTime = Time.realtimeSinceStartup;
            float curTime   = startTime;

            // Get file names from legacy sound archive.
            // We do this to cache the sounds used by the game engine.
            List <string> soundFileNames = new List <string>();

            try
            {
                VolFile soundArchive = new VolFile(archivePath);
                int     count        = soundArchive.GetCount();
                for (int i = 0; i < count; ++i)
                {
                    soundFileNames.Add(Path.GetFileNameWithoutExtension(soundArchive.GetName(i)));
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogWarning(ex);
            }

            // Load sounds
            foreach (string soundFileName in soundFileNames)
            {
                AudioClip soundClip = GetAssetFromModBundle <AudioClip>(soundFileName);

                if (soundClip != null)
                {
                    _SoundLookup[soundFileName] = soundClip;
                }
                else if (_LegacyAssets != null)
                {
                    // Load legacy sound
                    try
                    {
                        byte[] wavData = _LegacyAssets.GetResource(soundFileName + ".wav");
                        if (wavData != null)
                        {
                            _SoundLookup[soundFileName] = WavUtility.ToAudioClip(wavData, 0, soundFileName);
                        }
                        else
                        {
                            Debug.LogWarning("Could not find resource with name: " + soundFileName);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        Debug.LogException(ex);
                        Debug.LogError("Sound File: " + soundFileName);
                    }
                }
                else
                {
                    // Could not find sound!
                    Debug.LogWarning("Could not find sound with name: " + soundFileName);
                }

                // Every X seconds, take a break to render the screen
                if (curTime + 0.25f < Time.realtimeSinceStartup)
                {
                    yield return(null);

                    curTime = Time.realtimeSinceStartup;
                }
            }

            Debug.Log("Sounds Load Time: " + (Time.realtimeSinceStartup - startTime).ToString("N2") + " seconds");
        }