Ejemplo n.º 1
0
        // Returns the SDK version specified in the .OPM file. Otherwise, returns null
        public static string GetSDKVersion(MissionData missionData)
        {
            string missionPath = Path.Combine(GetCachePath(), missionData.missionID.ToString());

            // DLL or OPM
            string dllName           = missionData.fileNames.FirstOrDefault((filename) => filename.IndexOf(".dll", System.StringComparison.OrdinalIgnoreCase) >= 0);
            string opmName           = missionData.fileNames.FirstOrDefault((filename) => filename.IndexOf(".opm", System.StringComparison.OrdinalIgnoreCase) >= 0);
            bool   isStandardMission = string.IsNullOrEmpty(dllName) && !string.IsNullOrEmpty(opmName);

            if (isStandardMission)
            {
                // Get the SDK version from the mission file
                try
                {
                    string      filePath = Path.Combine(missionPath, opmName);
                    MissionRoot root     = MissionReader.GetMissionData(filePath);
                    return(root.sdkVersion);
                }
                catch (System.Exception ex)
                {
                    Debug.LogError(ex);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
 private MissionRoot GetMissionData(string path)
 {
     try
     {
         return(MissionReader.GetMissionData(path));
     }
     catch (System.Exception ex)
     {
         Debug.LogException(ex);
         return(null);
     }
 }
Ejemplo n.º 3
0
        private MissionRoot LoadMission(string path)
        {
            MissionRoot missionRoot = null;

            // Load mission
            try
            {
                missionRoot = MissionReader.GetMissionData(path);
            }
            catch (System.Exception ex)
            {
                Debug.LogException(ex);
            }

            return(missionRoot);
        }
Ejemplo n.º 4
0
        private void LoadMissions()
        {
            _MissionListBox.Clear();

            // Read missions in "ColonyGames" directory
            if (!Directory.Exists("ColonyGames"))
            {
                return;
            }

            // Add missions to list box
            foreach (string file in Directory.EnumerateFiles("ColonyGames", "*.opm", SearchOption.AllDirectories))
            {
                try
                {
                    MissionRoot mission = MissionReader.GetMissionData(file);
                    _MissionListBox.AddItem(mission.levelDetails.description, new ListBoxItemContents(file, mission));
                }
                catch (System.Exception ex)
                {
                    Debug.LogException(ex);
                }
            }
        }
Ejemplo n.º 5
0
        public void OnClick_Install()
        {
            // Get the cached mission details
            string      json       = File.ReadAllText(CachePath.GetMissionDetailsFilePath(missionData.missionID));
            MissionData localData  = JsonUtility.FromJson <MissionData>(json);
            string      sdkVersion = CachePath.GetSDKVersion(localData);

            // Do not allow installation if mission files already exist
            foreach (string fileName in localData.fileNames)
            {
                string filePath = Path.Combine(UserPrefs.gameDirectory, fileName);

                if (File.Exists(filePath))
                {
                    InfoDialog.Create("Installation Failed", "The file '" + fileName + "' already exists in your game directory. Please remove it to continue.");
                    return;
                }
            }

            List <string> installedFiles = new List <string>();

            // Need to export plugin for standard mission OPM file
            if (m_IsStandardMission)
            {
                string opmFileName = localData.fileNames.FirstOrDefault((string fileName) => Path.GetExtension(fileName).ToLowerInvariant().Contains("opm"));
                string opmFilePath = Path.Combine(CachePath.GetMissionDirectory(localData.missionID), opmFileName);

                string pluginFileName = Path.ChangeExtension(opmFileName, ".dll");
                string pluginPath     = Path.Combine(UserPrefs.gameDirectory, pluginFileName);

                // Don't allow install if the plugin will overwrite another DLL of the same name
                if (File.Exists(pluginPath))
                {
                    InfoDialog.Create("Install Failed", "There is already a plugin named " + pluginFileName);
                    return;
                }

                // Export plugin
                MissionRoot root = MissionReader.GetMissionData(opmFilePath);
                PluginExporter.ExportPlugin(pluginPath, root.sdkVersion, root.levelDetails);

                FileReference.AddReference(pluginFileName);

                installedFiles.Add(pluginFileName);
            }

            // Install mission from cache into game folder
            foreach (string fileName in localData.fileNames)
            {
                string filePath = Path.Combine(CachePath.GetMissionDirectory(localData.missionID), fileName);

                InstallFile(fileName, filePath);

                installedFiles.Add(fileName);
            }

            // Install SDK
            if (!string.IsNullOrEmpty(sdkVersion))
            {
                InstallFile(CachePath.GetSDKFileName(sdkVersion), CachePath.GetSDKFilePath(sdkVersion));
                InstallFile(CachePath.DotNetInteropFileName, CachePath.GetInteropFilePath(), true);

                installedFiles.Add(CachePath.GetSDKFileName(sdkVersion));
                installedFiles.Add(CachePath.DotNetInteropFileName);
            }

            // Write installed files to cache
            using (FileStream fs = new FileStream(CachePath.GetMissionInstalledMetaFilePath(localData.missionID), FileMode.Create, FileAccess.Write, FileShare.Read))
                using (StreamWriter writer = new StreamWriter(fs))
                {
                    foreach (string fileName in installedFiles)
                    {
                        writer.WriteLine(fileName);
                    }
                }

            // Set buttons
            m_BtnInstall.gameObject.SetActive(false);
            m_BtnUninstall.gameObject.SetActive(true);
            m_BtnDelete.interactable = false;
        }