Ejemplo n.º 1
0
        private void InstallFile(string fileName, string srcPath, bool overwrite = false)
        {
            FileReference.AddReference(fileName);

            string destPath = Path.Combine(UserPrefs.gameDirectory, fileName);

            if (!overwrite && File.Exists(destPath))
            {
                return;
            }

            File.Copy(srcPath, destPath);
        }
Ejemplo n.º 2
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;
        }