void StartLoadingLevel() { string levelFile = buttFileToOpen; if (!System.IO.Path.HasExtension(levelFile)) { levelFile = levelFile + ".butt"; } if (levelFile != lastButt || forceLoad) { levelRawString = null; MPFile file = new MPFile(new UnityDiskPlatform(), MPFile.DataPath.StreamingAssets); if (!file.Exists(levelFile)) { return; } byte[] data = file.ReadAllBytes(levelFile); if (System.IO.Path.GetExtension(levelFile) == ".png") { // do a dumb search for the PNG EOF token byte[] token = new byte[] { 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82 }; int buttIndex = 0; for (int i = 0; i < data.Length; ++i) { bool tokenFound = true; for (int j = 0; j < token.Length; ++j, ++i) { if (data[i] != token[j]) { tokenFound = false; break; } } if (tokenFound) { buttIndex = i; break; } } // found EOF, now ignore the png, we only want the .butt data. data = data.ShallowCopyRange <byte>(buttIndex); if (data.Length == 0) { // There's no .butt!? who would do such a thing!? forceLoad = false; return; } } levelRawString = System.Text.Encoding.UTF8.GetString(data); Regex r = new Regex(@"\s+|\r|\n|\r\n", RegexOptions.Multiline | RegexOptions.CultureInvariant); levelRawString = r.Replace(levelRawString, string.Empty); lastButt = levelFile; forceLoad = false; levelToCreate = this.RawToItemList(levelRawString); levelRawString = null; } }
public void TestAddFile() { string sourceFile = @"c:\tmp\2\ViewModeSwitcher.mpe1"; using (ISession session = DatabaseHelper.GetCurrentSession()) { using (ITransaction transaction = session.BeginTransaction()) { MPFile file = new MPFile(); file.Location = sourceFile; session.SaveOrUpdate(file); transaction.Commit(); } DatabaseHelper.CloseSession(session); } }
protected void versionDataSource_Inserted(object sender, ObjectDataSourceStatusEventArgs e) { string filename = (string)ViewState["TargetFileName"]; string location = (string)ViewState["TargetFileLocation"]; MPRSession session = MPRController.StartSession(); MPItemVersion version = MPRController.RetrieveById <MPItemVersion>(session, (Int64)e.ReturnValue); // Add the new file to the Repository MPFile mpfile = new MPFile(); mpfile.ItemVersion = version; mpfile.Filename = filename; mpfile.Location = location; version.Files.Add(mpfile); MPRController.Save <MPItemVersion>(session, version); MPRController.EndSession(session, true); ViewState.Remove("TargetFileName"); ViewState.Remove("TargetFileLocation"); }
/// <summary> /// Handle the actual creation of the entity /// </summary> /// <param name="filename">the name of the local file</param> /// <returns>success or failure</returns> protected bool AddFileToRepository(string filename) { MPRSession session = MPRController.StartSession(); MPUser user = SessionUtils.GetCurrentUser(); MPItem item = new MPItem(); item.Name = titleTextBox.Text; Int64 typeId; if (!Int64.TryParse(typesList.SelectedValue, out typeId)) { return UploadFail(String.Format("Invalid item type {0}", typesList.SelectedValue)); } item.Type = MPRController.RetrieveById<MPItemType>(session, typeId); if (item.Type == null) { return UploadFail(String.Format("Unable to find item type {0} ({1})", typesList.SelectedItem, typeId)); } List<Int64> categoryIds = new List<Int64>(); foreach (ListItem categoryItem in categoriesList.Items) { if (categoryItem.Selected) { Int64 id; if (Int64.TryParse(categoryItem.Value, out id)) { categoryIds.Add(id); } } } IList<MPCategory> categories = MPRController.RetrieveByIdList<MPCategory>(session, categoryIds); foreach (MPCategory category in categories) { item.Categories.Add(category); } item.Description = descriptionTextBox.Text; item.DescriptionShort = descriptionShortTextBox.Text; item.License = licenseTextBox.Text; item.LicenseMustAccept = licenseMustAccessCheckBox.Checked; item.Author = authorTextBox.Text; item.Homepage = homepageTextbox.Text; item.Tags = MPRController.GetTags(session, tagsTextBox.Text); // create ItemVersion MPItemVersion itemVersion = new MPItemVersion(); itemVersion.Item = item; itemVersion.Uploader = user; itemVersion.DevelopmentStatus = (MPItemVersion.MPDevelopmentStatus) Enum.Parse(typeof(MPItemVersion.MPDevelopmentStatus), developmentStatusDropDownList.SelectedValue); itemVersion.MPVersionMin = mpVersionMinTextBox.Text; itemVersion.MPVersionMax = mpVersionMaxTextBox.Text; itemVersion.Version = versionTextBox.Text; MPFile mpfile = new MPFile(); mpfile.ItemVersion = itemVersion; mpfile.Filename = System.IO.Path.GetFileName(fileUpload.PostedFile.FileName); mpfile.Location = filename; itemVersion.Files.Add(mpfile); item.Versions.Add(itemVersion); // Save item (and sub-items) to database try { MPRController.Save<MPItem>(session, item); MPRController.EndSession(session, true); } catch (Exception ex) { MPRController.EndSession(session, false); return UploadFail("Unable to save item: " + ex.ToString()); } return true; }
/// <summary> /// Handle the actual creation of the entity /// </summary> /// <param name="filename">the name of the local file</param> /// <returns>success or failure</returns> protected bool AddFileToRepository(string filename) { MPRSession session = MPRController.StartSession(); MPUser user = SessionUtils.GetCurrentUser(); MPItem item = new MPItem(); item.Name = titleTextBox.Text; Int64 typeId; if (!Int64.TryParse(typesList.SelectedValue, out typeId)) { return(UploadFail(String.Format("Invalid item type {0}", typesList.SelectedValue))); } item.Type = MPRController.RetrieveById <MPItemType>(session, typeId); if (item.Type == null) { return(UploadFail(String.Format("Unable to find item type {0} ({1})", typesList.SelectedItem, typeId))); } List <Int64> categoryIds = new List <Int64>(); foreach (ListItem categoryItem in categoriesList.Items) { if (categoryItem.Selected) { Int64 id; if (Int64.TryParse(categoryItem.Value, out id)) { categoryIds.Add(id); } } } IList <MPCategory> categories = MPRController.RetrieveByIdList <MPCategory>(session, categoryIds); foreach (MPCategory category in categories) { item.Categories.Add(category); } item.Description = descriptionTextBox.Text; item.DescriptionShort = descriptionShortTextBox.Text; item.License = licenseTextBox.Text; item.LicenseMustAccept = licenseMustAccessCheckBox.Checked; item.Author = authorTextBox.Text; item.Homepage = homepageTextbox.Text; item.Tags = MPRController.GetTags(session, tagsTextBox.Text); // create ItemVersion MPItemVersion itemVersion = new MPItemVersion(); itemVersion.Item = item; itemVersion.Uploader = user; itemVersion.DevelopmentStatus = (MPItemVersion.MPDevelopmentStatus)Enum.Parse(typeof(MPItemVersion.MPDevelopmentStatus), developmentStatusDropDownList.SelectedValue); itemVersion.MPVersionMin = mpVersionMinTextBox.Text; itemVersion.MPVersionMax = mpVersionMaxTextBox.Text; itemVersion.Version = versionTextBox.Text; MPFile mpfile = new MPFile(); mpfile.ItemVersion = itemVersion; mpfile.Filename = System.IO.Path.GetFileName(fileUpload.PostedFile.FileName); mpfile.Location = filename; itemVersion.Files.Add(mpfile); item.Versions.Add(itemVersion); // Save item (and sub-items) to database try { MPRController.Save <MPItem>(session, item); MPRController.EndSession(session, true); } catch (Exception ex) { MPRController.EndSession(session, false); return(UploadFail("Unable to save item: " + ex.ToString())); } return(true); }
void Update() { if (Input.GetKeyDown(KeyCode.F12)) { Scene scene = SceneManager.GetSceneAt(0); bool overlayLoaded = false; for (int i = 0; i < SceneManager.sceneCount; ++i) { scene = SceneManager.GetSceneAt(i); if (scene.isLoaded && scene.name == EDITOR_OVERLAY_SCENE) { overlayLoaded = true; break; } } if (overlayLoaded) { SceneManager.UnloadScene(scene); } else { SceneManager.LoadScene(EDITOR_OVERLAY_SCENE, UnityEngine.SceneManagement.LoadSceneMode.Additive); } } else if (Input.GetKeyDown(KeyCode.F6)) { string leveldata = string.Empty; if (customPrefabs != null && customPrefabs.Count > 0) { leveldata += Utils.SerializeButtEntities(customPrefabs); } if (levelToCreate != null && levelToCreate.Count > 0) { leveldata += Utils.SerializeButtEntities(levelToCreate); } if (customBehaviours != null && customBehaviours.Count > 0) { leveldata += Utils.SerializeButtEntities(customBehaviours); } MPFile file = new MPFile(new UnityDiskPlatform(), MPFile.DataPath.StreamingAssets); string buttFile = buttFileToOpen; if (!buttFile.EndsWith(".butt")) { buttFile += ".butt"; } file.WriteAllBytes(buttFile, System.Text.Encoding.ASCII.GetBytes(leveldata)); } else if (Input.GetKeyDown(KeyCode.F7)) { forceLoad = true; this.state = State.Waiting; xa.re.cleanLoadLevel(Restart.RestartFrom.RESTART_FROM_START, UnityEngine.SceneManagement.SceneManager.GetActiveScene().name); } switch (state) { case State.Done: break; case State.Waiting: if (FrEdLibrary.instance != null && instance != null) { state = State.LoadingLevel; } break; case State.LoadingLevel: StartLoadingLevel(); state = State.WaitForLevelRawToLoad; break; case State.WaitForLevelRawToLoad: if (levelToCreate != null && levelToCreate.Count > 0) { state = State.CreatingLevel; } break; case State.CreatingLevel: //Create the level, if the levelToCreate != null if (levelToCreate != null) { state = State.HandlingLateCreations; CreateLevel(levelToCreate); } break; case State.HandlingLateCreations: //Switch to loading the test level HandleCreateLate(); break; } }