public void SaveMission(string path) { string dirPath = Path.GetDirectoryName(path); string missionName = Path.GetFileNameWithoutExtension(path); // Save mission file using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) using (StreamWriter writer = new StreamWriter(fs)) { // Write mission file System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(MissionRoot)); using (MemoryStream stream = new MemoryStream()) { serializer.WriteObject(stream, mission); stream.Position = 0; using (StreamReader reader = new StreamReader(stream)) writer.Write(Utility.JsonFormatter.Format(reader.ReadToEnd())); } } //MissionReader.WriteMissionData(path, mission); // Save map file map.Write(Path.Combine(dirPath, mission.levelDetails.mapName)); // Save plugin file PluginExporter.ExportPlugin(Path.Combine(dirPath, missionName + ".dll"), mission.sdkVersion, mission.levelDetails); }
private void OnExportPluginPath(string path) { interactable = true; // OP2 does not support plugins with more than 7 characters. if (Path.GetFileNameWithoutExtension(path).Length > 7) { Debug.Log("Plugin filename cannot be longer than 7 characters."); return; } PluginExporter.ExportPlugin(path, UserData.current.mission.sdkVersion, UserData.current.mission.levelDetails); Debug.Log("Plugin exported to \"" + path + "\"."); }
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; }