/// <summary> /// Select to delete /// </summary> /// <param file="file">File name to delete</param> public void Delete(QuestData.Quest q) { ValkyrieDebug.Log("INFO: Delete quest"); string toDelete = ""; if (Path.GetExtension(Path.GetFileName(q.path)) == ".valkyrie") { toDelete = ContentData.DownloadPath() + Path.DirectorySeparatorChar + Path.GetFileName(q.path); File.Delete(toDelete); // update quest status : downloaded/updated Game.Get().questsList.SetQuestAvailability(Path.GetFileNameWithoutExtension(q.path), false); } else { // this is not an archive, it is a local quest within a directory Directory.Delete(q.path, true); Game.Get().questsList.UnloadLocalQuests(); } Destroyer.Dialog(); // Pull up the quest selection page Game.Get().questSelectionScreen.Show(); }
// Copy a quest public void Copy(string key) { Game game = Game.Get(); string dataLocation = Game.AppData() + Path.DirectorySeparatorChar + Game.Get().gameType.TypeName() + "/Editor"; if (!Directory.Exists(dataLocation)) { Directory.CreateDirectory(dataLocation); } // Find a new unique directory name int i = 1; while (Directory.Exists(dataLocation + "/Editor" + game.gameType.QuestName().Translate() + i)) { i++; } string targetLocation = dataLocation + "/Editor" + game.gameType.QuestName().Translate() + i; // Fully extract this scenario before copy if this is a package if (Path.GetExtension(Path.GetFileName(key)) == ".valkyrie") { // extract the full package QuestLoader.ExtractSinglePackageFull(ContentData.DownloadPath() + Path.DirectorySeparatorChar + Path.GetFileName(key)); } // Copy files try { DirectoryCopy(key, targetLocation, true); // read new quest file string[] questData = File.ReadAllLines(targetLocation + "/quest.ini"); // Search for quest section bool questFound = false; for (i = 0; i < questData.Length; i++) { if (questData[i].Equals("[Quest]")) { // Inside quest section questFound = true; } if (questFound && questData[i].IndexOf("name=") == 0) { // Add copy to name questFound = false; questData[i] = questData[i] + " (Copy)"; } } // Write back to ini file File.WriteAllLines(targetLocation + "/quest.ini", questData); } catch (System.Exception) { ValkyrieDebug.Log("Error: Failed to copy quest."); Application.Quit(); } // Back to selection new QuestEditSelection(); }
// Return a single quest, quest name is without file extension public static QuestData.Quest GetSingleQuest(string questName, bool getHidden = false) { QuestData.Quest quest = null; Game game = Game.Get(); // Look in the user application data directory string dataLocation = Game.AppData(); mkDir(dataLocation); mkDir(ContentData.DownloadPath()); string path = ContentData.DownloadPath() + Path.DirectorySeparatorChar + questName + ".valkyrie"; QuestLoader.ExtractSinglePackagePartial(path); // load quest QuestData.Quest q = new QuestData.Quest(Path.Combine(ContentData.TempValyriePath, Path.GetFileName(path))); // Check quest is valid and of the right type if (q.valid && q.type.Equals(game.gameType.TypeName())) { // Is the quest hidden? if (!q.hidden || getHidden) { // Add quest to quest list quest = q; } } // Return list of available quests return(quest); }
// Return a dictionary of all available quests public static Dictionary <string, QuestData.Quest> GetQuests(bool getHidden = false) { Dictionary <string, QuestData.Quest> quests = new Dictionary <string, QuestData.Quest>(); Game game = Game.Get(); // Look in the user application data directory string dataLocation = Game.AppData(); mkDir(dataLocation); CleanTemp(); mkDir(ContentData.DownloadPath()); // Get a list of downloaded quest not packed List <string> questDirectories = GetQuests(ContentData.DownloadPath()); // Extract only required files from downloaded packages ExtractPackages(ContentData.DownloadPath()); // Get the list of extracted packages questDirectories.AddRange(GetQuests(ContentData.TempValyriePath)); // Add the list of editor quest if (game.gameType is MoMGameType) { dataLocation += "/MoM/Editor"; } if (game.gameType is D2EGameType) { dataLocation += "/D2E/Editor"; } if (game.gameType is IAGameType) { dataLocation += "/IA/Editor"; } questDirectories.AddRange(GetQuests(dataLocation)); // Go through all directories foreach (string p in questDirectories) { // load quest QuestData.Quest q = new QuestData.Quest(p); // Check quest is valid and of the right type if (q.valid && q.type.Equals(game.gameType.TypeName())) { // Is the quest hidden? if (!q.hidden || getHidden) { // Add quest to quest list quests.Add(p, q); } } } // Return list of available quests return(quests); }
private void CheckLocalAvailability() { // load information on local quests IniData localManifest = IniRead.ReadFromIni(ContentData.DownloadPath() + "/manifest.ini"); if (localManifest == null) { return; } // Update download status for each questData and check if update is available foreach (KeyValuePair <string, QuestData.Quest> quest_data in remote_quests_data) { if (localManifest.data.ContainsKey(quest_data.Key)) { quest_data.Value.downloaded = true; quest_data.Value.update_available = (localManifest.data[quest_data.Key]["version"] != quest_data.Value.version); } } }
// This is called when a quest is selected public void StartQuest(QuestData.Quest q) { if (Path.GetExtension(Path.GetFileName(q.path)) == ".valkyrie") { // extract the full package QuestLoader.ExtractSinglePackageFull(ContentData.DownloadPath() + Path.DirectorySeparatorChar + Path.GetFileName(q.path)); } // Fetch all of the quest data and initialise the quest quest = new Quest(q); // Draw the hero icons, which are buttons for selection heroCanvas.SetupUI(); // Add a finished button to start the quest UIElement ui = new UIElement(Game.HEROSELECT); ui.SetLocation(UIScaler.GetRight(-8.5f), UIScaler.GetBottom(-2.5f), 8, 2); ui.SetText(CommonStringKeys.FINISHED, Color.green); ui.SetFont(gameType.GetHeaderFont()); ui.SetFontSize(UIScaler.GetMediumFont()); ui.SetButton(EndSelection); new UIElementBorder(ui, Color.green); // Add a title to the page ui = new UIElement(Game.HEROSELECT); ui.SetLocation(8, 1, UIScaler.GetWidthUnits() - 16, 3); ui.SetText(new StringKey("val", "SELECT", gameType.HeroesName())); ui.SetFont(gameType.GetHeaderFont()); ui.SetFontSize(UIScaler.GetLargeFont()); heroCanvas.heroSelection = new HeroSelection(); ui = new UIElement(Game.HEROSELECT); ui.SetLocation(0.5f, UIScaler.GetBottom(-2.5f), 8, 2); ui.SetText(CommonStringKeys.BACK, Color.red); ui.SetFont(gameType.GetHeaderFont()); ui.SetFontSize(UIScaler.GetMediumFont()); ui.SetButton(Destroyer.QuestSelect); new UIElementBorder(ui, Color.red); }
/// <summary> /// Called after download finished to save to disk /// </summary> /// <param name="key">Quest id</param> public void Save(string key) { // in case of error during download, do nothing if (!string.IsNullOrEmpty(download.error) || download.bytesDownloaded <= 0) { return; } // Write to disk QuestLoader.mkDir(ContentData.DownloadPath()); using (BinaryWriter writer = new BinaryWriter(File.Open(ContentData.DownloadPath() + Path.DirectorySeparatorChar + key + ".valkyrie", FileMode.Create))) { writer.Write(download.bytes); writer.Close(); } // update local list of quest and current status game.questsList.SetQuestAvailability(key, true); // cleanup screen and go back to list of quests Destroyer.Dialog(); game.questSelectionScreen.Show(); }
public void SetQuestAvailability(string key, bool isAvailable) { // update list of local quest IniData localManifest = IniRead.ReadFromString(""); string saveLocation = ContentData.DownloadPath(); if (File.Exists(saveLocation + "/manifest.ini")) { localManifest = IniRead.ReadFromIni(saveLocation + "/manifest.ini"); } if (isAvailable) { IniData downloaded_quest = IniRead.ReadFromString(remote_quests_data[key].ToString()); localManifest.Remove(key); localManifest.Add(key, downloaded_quest.data["Quest"]); } else { if (localManifest.Get(key) != null) { localManifest.Remove(key); } // we need to delete /temp and reload list UnloadLocalQuests(); } if (File.Exists(saveLocation + "/manifest.ini")) { File.Delete(saveLocation + "/manifest.ini"); } File.WriteAllText(saveLocation + "/manifest.ini", localManifest.ToString()); // update status quest remote_quests_data[key].downloaded = isAvailable; remote_quests_data[key].update_available = false; }
/// <summary> /// Get download directory without trailing '/' /// </summary> /// <returns>location to save packages</returns> public string saveLocation() { return(ContentData.DownloadPath()); }