Ejemplo n.º 1
0
        public void UnzipPlugin(string zipName)
        {
            if (!File.Exists(zipName))
            {
                return;
            }

            MyZipArchive.ExtractToDirectory(zipName, _pluginManager.PluginDir);
        }
Ejemplo n.º 2
0
        public void ExtractZipFileToFolder()
        {
            const string filename = @".\TestAssets\Sample World.sbw";
            const string folder   = @".\TestOutput\Sample World";

            Assert.IsTrue(File.Exists(filename), "Source file must exist");

            ZipTools.MakeClearDirectory(folder);

            // Keen's API doesn't know difference between file and folder.
            MyZipArchive.ExtractToDirectory(filename, folder);

            Assert.IsTrue(File.Exists(Path.Combine(folder, SpaceEngineersConsts.SandBoxCheckpointFilename)), "Destination file must exist");
        }
Ejemplo n.º 3
0
        public void ExtractZipAndRepack()
        {
            const string filename = @".\TestAssets\Sample World.sbw";
            const string folder   = @".\TestOutput\Sample World Repack";

            ZipTools.MakeClearDirectory(folder);

            // Keen's API doesn't know difference between file and folder.
            MyZipArchive.ExtractToDirectory(filename, folder);

            const string newFilename = @".\TestOutput\New World.sbw";

            MyZipArchive.CreateFromDirectory(folder, newFilename, DeflateOptionEnum.Maximum, false);

            Assert.IsTrue(File.Exists(newFilename), "Destination file must exist");
        }
Ejemplo n.º 4
0
        public bool Extract()
        {
            var sanitizedTitle = Path.GetInvalidFileNameChars().Aggregate(Title, (current, c) => current.Replace(c.ToString(), "_"));
            var dest           = Path.Combine(m_extractPath, string.Format("{0} {1} ({2})", Constants.SEWT_Prefix, sanitizedTitle, m_modId.ToString()));

            MySandboxGame.Log.WriteLineAndConsole(string.Format("Extracting item: '{0}' to: \"{1}\"", m_title, dest));
            if (Directory.Exists(m_modPath))
            {
                MyFileSystem.CopyAll(m_modPath, dest);
            }
            else
            {
                MyZipArchive.ExtractToDirectory(m_modPath, dest);
            }

            return(true);
        }
Ejemplo n.º 5
0
        public bool Extract()
        {
            string ext = ".sbm";

            if (m_tags.Contains(MySteamWorkshop.WORKSHOP_MOD_TAG))
            {
                ext = ".sbm";
            }
            else if (m_tags.Contains(MySteamWorkshop.WORKSHOP_BLUEPRINT_TAG))
            {
                ext = ".sbb";
            }
            else if (m_tags.Contains(WorkshopType.IngameScript.ToString()))
            {
                ext = ".sbs";
            }
            else if (m_tags.Contains(MySteamWorkshop.WORKSHOP_WORLD_TAG))
            {
                ext = ".sbw";
            }
            else if (m_tags.Contains(MySteamWorkshop.WORKSHOP_SCENARIO_TAG))
            {
                ext = ".sbs";
            }

            var sanitizedTitle = Path.GetInvalidFileNameChars().Aggregate(Title, (current, c) => current.Replace(c.ToString(), "_"));
            var source         = Path.Combine(m_modPath, m_modId.ToString() + ext);

            if (!File.Exists(source))
            {
                source = Path.Combine(m_modPath, @"..\workshop", m_modId.ToString() + ext);
            }

            var dest = Path.Combine(m_modPath, string.Format("{0} {1} ({2})", Constants.SEWT_Prefix, sanitizedTitle, m_modId.ToString()));

            MySandboxGame.Log.WriteLineAndConsole(string.Format("Extracting mod: '{0}' to: \"{1}\"", sanitizedTitle, dest));
            MyZipArchive.ExtractToDirectory(source, dest);
            return(true);
        }
Ejemplo n.º 6
0
        // Starts new session with campaign data
        public void LoadSessionFromActiveCampaign(string relativePath, Action afterLoad = null, string campaignDirectoryName = null)
        {
            var    savePath = relativePath;
            string absolutePath;

            // >> WORLD FILE OPERATIONS
            // Find the existing file in order of modded content to vanilla
            if (m_activeCampaign.IsVanilla || m_activeCampaign.IsDebug)
            {
                absolutePath = Path.Combine(MyFileSystem.ContentPath, savePath);

                if (!MyFileSystem.FileExists(absolutePath))
                {
                    MySandboxGame.Log.WriteLine("ERROR: Missing vanilla world file in campaign: " + m_activeCampaignName);
                    Debug.Fail("ERROR: Missing vanilla world file in campaign: " + m_activeCampaignName);
                    return;
                }
            }
            else
            {
                // Modded content
                absolutePath = Path.Combine(m_activeCampaign.ModFolderPath, savePath);
                // try finding respective vanilla file if the file does not exist
                if (!MyFileSystem.FileExists(absolutePath))
                {
                    absolutePath = Path.Combine(MyFileSystem.ContentPath, savePath);
                    if (!MyFileSystem.FileExists(absolutePath))
                    {
                        MySandboxGame.Log.WriteLine("ERROR: Missing world file in campaign: " + m_activeCampaignName);
                        Debug.Fail("ERROR: Missing world file in campaign: " + m_activeCampaignName);
                        return;
                    }
                }
            }

            // Copy the save and load the session
            if (string.IsNullOrEmpty(campaignDirectoryName))
            {
                campaignDirectoryName = ActiveCampaignName + " " + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
            }

            var directory       = new DirectoryInfo(Path.GetDirectoryName(absolutePath));
            var targetDirectory = Path.Combine(MyFileSystem.SavesPath, campaignDirectoryName, directory.Name);

            while (MyFileSystem.DirectoryExists(targetDirectory))
            {
                // Finid new unique name for the folder
                targetDirectory = Path.Combine(MyFileSystem.SavesPath, directory.Name + " " + MyUtils.GetRandomInt(int.MaxValue).ToString("########"));
            }

            if (File.Exists(absolutePath))
            {
                // It is a local mod or vanilla file
                MyUtils.CopyDirectory(directory.FullName, targetDirectory);
            }
            else
            {
                // Its is a workshop mod
                var tmpPath = Path.Combine(Path.GetTempPath(), "TMP_CAMPAIGN_MOD_FOLDER");
                var worldFolderAbsolutePath = Path.Combine(tmpPath, Path.GetDirectoryName(relativePath));

                // Extract the mod to temp, copy the world folder to target directory, remove the temp folder
                MyZipArchive.ExtractToDirectory(m_activeCampaign.ModFolderPath, tmpPath);
                MyUtils.CopyDirectory(worldFolderAbsolutePath, targetDirectory);
                Directory.Delete(tmpPath, true);
            }

            // >> LOCALIZATION
            // Set localization for loaded level in the after load event
            if (string.IsNullOrEmpty(m_selectedLanguage))
            {
                m_selectedLanguage = m_activeCampaign.DefaultLocalizationLanguage;

                if (string.IsNullOrEmpty(m_selectedLanguage) && m_activeCampaign.LocalizationLanguages.Count > 0)
                {
                    m_selectedLanguage = m_activeCampaign.LocalizationLanguages[0];
                }
            }

            if (!string.IsNullOrEmpty(m_selectedLanguage))
            {
                // Initilize the sessionComponent in after load event
                afterLoad += () =>
                {
                    var comp = MySession.Static.GetComponent <MyLocalizationSessionComponent>();
                    comp.LoadCampaignLocalization(m_activeCampaign.LocalizationPaths, m_activeCampaign.ModFolderPath);
                    comp.SwitchLanguage(m_selectedLanguage);
                };
            }

            // ATM only single player campaigns are supported
            if (!m_activeCampaign.IsMultiplayer)
            {
                afterLoad += () => MySession.Static.Save();
                MySessionLoader.LoadSingleplayerSession(targetDirectory, afterLoad);
            }
        }