Provides a static metadata description and cache of a Cartridge.
Inheritance: INotifyPropertyChanged
 /// <summary>
 /// Constructs a new savegame metadata container for a Cartridge.
 /// </summary>
 /// <param name="cartridge">Cartridge to save.</param>
 public CartridgeSavegame(CartridgeTag tag)
 {
     ModelVersion = GeneratedModelVersion;
     Timestamp = DateTime.Now;
     Name = Timestamp.Ticks.ToString();
     SetFileProperties(tag.Cartridge.Filename, tag.Guid);
 }
		/// <summary>
		/// Constructs a new savegame metadata container for a Cartridge, using metadata
		/// from a GWS metadata container.
		/// </summary>
		/// <param name="tag">Cartridge to save.</param>
		/// <param name="gwsMetadata">Metadata of a GWS file.</param>
		public CartridgeSavegame(CartridgeTag tag, WF.Player.Core.Formats.GWS.Metadata gwsMetadata, string gwsFilename)
		{
			Timestamp = gwsMetadata.SaveCreateDate;
			Name = gwsMetadata.SaveName;
			HashColor = GetHashColor(Name);
			SetFileProperties(tag, gwsFilename);
		}
 /// <summary>
 /// Constructs a new savegame metadata container for a Cartridge.
 /// </summary>
 /// <param name="cartridge">Cartridge to save.</param>
 public CartridgeSavegame(CartridgeTag tag)
 {
     Timestamp = DateTime.Now;
     Name = GetDefaultName(tag);
     HashColor = GetHashColor(Name);
     SetFileProperties(tag);
 }
 /// <summary>
 /// Constructs a new savegame metadata container for a Cartridge.
 /// </summary>
 /// <param name="cartridge">Cartridge to save.</param>
 public CartridgeSavegame(CartridgeTag tag)
 {
     Timestamp = DateTime.Now;
     Name      = GetDefaultName(tag);
     HashColor = GetHashColor(Name);
     SetFileProperties(tag);
 }
 /// <summary>
 /// Constructs a new savegame metadata container for a Cartridge and a name.
 /// </summary>
 /// <param name="cartridge">Cartridge to save.</param>
 /// <param name="name"></param>
 public CartridgeSavegame(CartridgeTag tag, string name)
 {
     Timestamp = DateTime.Now;
     Name = name;
     HashColor = GetHashColor(Name);
     SetFileProperties(tag);
 }
 /// <summary>
 /// Constructs a new savegame metadata container for a Cartridge and a name.
 /// </summary>
 /// <param name="cartridge">Cartridge to save.</param>
 /// <param name="name"></param>
 public CartridgeSavegame(CartridgeTag tag, string name)
 {
     Timestamp = DateTime.Now;
     Name      = name;
     HashColor = GetHashColor(Name);
     SetFileProperties(tag);
 }
 /// <summary>
 /// Constructs a new savegame metadata container for a Cartridge, using metadata
 /// from a GWS metadata container.
 /// </summary>
 /// <param name="tag">Cartridge to save.</param>
 /// <param name="gwsMetadata">Metadata of a GWS file.</param>
 public CartridgeSavegame(CartridgeTag tag, WF.Player.Core.Formats.GWS.Metadata gwsMetadata, string gwsFilename)
 {
     Timestamp = gwsMetadata.SaveCreateDate;
     Name      = gwsMetadata.SaveName;
     HashColor = GetHashColor(Name);
     SetFileProperties(tag, gwsFilename);
 }
        /// <summary>
        /// Removes a cartridge from the store, and wipes all its related content, including
        /// cache, logs and savegames.
        /// </summary>
        /// <param name="tag"></param>
        public void DeleteCartridgeAndContent(CartridgeTag tag)
        {
            // Clears the history for this tag.
            History.RemoveAllOf(tag.Guid);

            // Removes it from the store.
            CartridgeStore.RemoveCartridgeTag(tag, true);
        }
Example #9
0
        /// <summary>
        /// Constructs a history entry of a particular type, populating
        /// its fields with the contents of a cartridge tag, and using
        /// <code>DateTime.Now</code> as timestamp.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="cartTag"></param>
        public HistoryEntry(HistoryEntry.Type type, CartridgeTag cartTag)
        {
            EntryType = type;
            RelatedCartridgeFilename = cartTag.Cartridge.Filename;
            RelatedCartridgeGuid     = cartTag.Guid;
            RelatedCartridgeName     = cartTag.Title;

            BitmapSource thumb = (BitmapSource)cartTag.Icon;

            RelatedCartridgeThumbnailBase64 = thumb == null ? null : Utils.ImageUtils.ToBase64String(thumb, ThumbnailWidth, ThumbnailWidth);

            Timestamp = DateTime.Now;
        }
        /// <summary>
        /// Changes the name of this savegame.
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="name"></param>
        public void Rename(CartridgeTag tag, string name, IsolatedStorageFile isf)
        {
            string oldGwsFile = SavegameFile;
            string oldMdFile  = MetadataFile;

            // Changes the properties.
            Name = name;
            SetFileProperties(tag);

            // Renames the files.
            if (isf.FileExists(oldGwsFile))
            {
                isf.MoveFile(oldGwsFile, SavegameFile);
            }
            if (isf.FileExists(oldMdFile))
            {
                isf.MoveFile(oldMdFile, MetadataFile);
            }
        }
 private void SetFileProperties(CartridgeTag tag, string saveFilename = null)
 {
     if (saveFilename == null)
     {
         string fname = System.IO.Path.GetFileNameWithoutExtension(tag.Cartridge.Filename);
         SavegameFile = String.Format("{0}/{1}_{2}.gws",
                                      tag.PathToSavegames,
                                      Name.ReplaceInvalidFileNameChars(),
                                      fname.ReplaceInvalidFileNameChars()
                                      );
     }
     else
     {
         SavegameFile = String.Format("{0}/{1}", tag.PathToSavegames, saveFilename);
         if (!SavegameFile.EndsWith(".gws", StringComparison.InvariantCultureIgnoreCase))
         {
             SavegameFile += ".gws";
         }
     }
     MetadataFile = SavegameFile + ".mf";
 }
        /// <summary>
        /// Initializes quick and auto savegames for a new game session.
        /// </summary>
        /// <param name="tag">Cartridge being played</param>
        /// <param name="savegameCandidate">Savegame that started the game session, or null if it is a new game.</param>
        public void InitSessionSavegames(CartridgeTag tag, CartridgeSavegame savegameCandidate)
        {
            // Inits the session's quick save from the restored savegame if it is a quicksave, or makes a new one if not.
            if (savegameCandidate != null && savegameCandidate.IsQuicksave)
            {
                _quickSaves[tag] = savegameCandidate;
            }
            else
            {
                CreateQuickSavegame(tag);
            }

            // Inits the session's auto save from the restored savegame if it is an autosave, or makes a new one if not.
            if (savegameCandidate != null && savegameCandidate.IsAutosave)
            {
                _autoSaves[tag] = savegameCandidate;
            }
            else
            {
                CreateAutoSavegame(tag);
            }
        }
        private string GetDefaultName(CartridgeTag tag)
        {
            // Gets a context-aware default name:
            // Proximity to the closest thing.
            Thing closestThing = null;
            try
            {
               closestThing = App.Current.Model.Core.VisibleThings
             .OrderBy(t => { if (t.VectorFromPlayer == null) { return -1; } else { return t.VectorFromPlayer.Distance.Value; } })
             .FirstOrDefault();
            }
            catch (Exception)
            {

            }

            if (closestThing != null)
            {
                string proximity = "By";

                if (closestThing is Zone)
                {
                    PlayerZoneState state = ((Zone)closestThing).State;
                    if (state == PlayerZoneState.Inside)
                    {
                        proximity = "Inside";
                    }
                    else if (state == PlayerZoneState.Proximity)
                    {
                        proximity = "Close to";
                    }
                    else if (state == PlayerZoneState.Distant)
                    {
                        proximity = "Away from";
                    }
                    else
                    {
                        proximity = null;
                    }
                }
                else if (closestThing is Character)
                {
                    proximity = "Close to";
                }

                if (proximity != null)
                {
                    return String.Format("{0} {1}", proximity, closestThing.Name); 
                }
            }

            // We've had no luck finding a closest thing.
            return String.Format("MySavegame{0}{1}{2}{3}",
                Timestamp.DayOfYear,
                Timestamp.Hour,
                Timestamp.Minute,
                Timestamp.Second);
        }
Example #14
0
 /// <summary>
 /// Constructs a history entry of a particular type, populating
 /// its fields with the contents of a cartridge tag and a cartridge
 /// savegame, and using <code>DateTime.Now</code> as timestamp.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="cartTag"></param>
 /// <param name="savegame"></param>
 public HistoryEntry(HistoryEntry.Type type, CartridgeTag cartTag, CartridgeSavegame savegame)
     : this(type, cartTag)
 {
     RelatedSavegameHashColor = savegame.HashColor;
     RelatedSavegameName = savegame.Name;
 }
        private void SaveCore(
            CartridgeTag tag,
            CartridgeSavegame cs,
            Action<CartridgeTag, CartridgeSavegame> continuation,
            bool displayError)
        {
            try
            {
                // Performs the savegame.
                _appViewModel.Model.Core.SaveAsync(cs)
                    .ContinueWith(t =>
                    {
                        // Continues.
                        continuation(tag, cs);

                    }, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());
            }
            catch (Exception ex)
            {
                // Keeps track of the error.
                DebugUtils.DumpException(ex);

                // Displays an error if needed.
                if (displayError)
                {
                    MessageBox.Show("An error occured while preparing the savegame. Please try again.", "Error", MessageBoxButton.OK);
                }
            }
        }
        private CartridgeSavegame CreateSavegame(CartridgeTag tag, string nameRoot, string suffixFormat, bool isQuickSave, bool isAutoSave, Dictionary<CartridgeTag, CartridgeSavegame> dict)
        {
            if (!isQuickSave && !isAutoSave)
            {
                throw new InvalidOperationException("Savegame must be either quick save or auto save");
            }
            
            // Makes a savegame.
            string intPattern = " {0}";
            int saveId = tag.GetLastSavegameNameInteger(nameRoot, intPattern) + 1;
            CartridgeSavegame cs = new CartridgeSavegame(tag, nameRoot + String.Format(intPattern, saveId))
            {
                IsQuicksave = isQuickSave,
                IsAutosave = isAutoSave
            };

            // Sets it as the current save for the tag.
            dict[tag] = cs;

            // Returns
            return cs;
        }
        private string GetDefaultName(CartridgeTag tag)
        {
            // Gets a context-aware default name:
            // Proximity to the closest thing.
            Thing closestThing = null;

            try
            {
                closestThing = App.Current.Model.Core.VisibleThings
                               .OrderBy(t => { if (t.VectorFromPlayer == null)
                                               {
                                                   return(-1);
                                               }
                                               else
                                               {
                                                   return(t.VectorFromPlayer.Distance.Value);
                                               } })
                               .FirstOrDefault();
            }
            catch (Exception)
            {
            }

            if (closestThing != null)
            {
                string proximity = "By";

                if (closestThing is Zone)
                {
                    PlayerZoneState state = ((Zone)closestThing).State;
                    if (state == PlayerZoneState.Inside)
                    {
                        proximity = "Inside";
                    }
                    else if (state == PlayerZoneState.Proximity)
                    {
                        proximity = "Close to";
                    }
                    else if (state == PlayerZoneState.Distant)
                    {
                        proximity = "Away from";
                    }
                    else
                    {
                        proximity = null;
                    }
                }
                else if (closestThing is Character)
                {
                    proximity = "Close to";
                }

                if (proximity != null)
                {
                    return(String.Format("{0} {1}", proximity, closestThing.Name));
                }
            }

            // We've had no luck finding a closest thing.
            return(String.Format("MySavegame{0}{1}{2}{3}",
                                 Timestamp.DayOfYear,
                                 Timestamp.Hour,
                                 Timestamp.Minute,
                                 Timestamp.Second));
        }
        private void DeleteCartridge(CartridgeTag tag)
        {
            /// Makes a confirmation message.

            ICartridgeProvider provider = Model.CartridgeStore.GetCartridgeTagProvider(tag);
            int savegameCount = tag.Savegames.Count();
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            sb.AppendFormat("Geowigo will delete {0} and all its contents", tag.Title);
            if (savegameCount > 0)
            {
                sb.AppendFormat(", including {0} savegames.", savegameCount);
            }
            else
            {
                sb.Append(".");
            }
            sb.AppendLine();
            sb.AppendLine();

            if (provider != null)
            {
                sb.AppendFormat(
                    "Since {0} was downloaded from {1}, it may be downloaded again the next time Geowigo will sync with {1}, unless you remove it from the Geowigo folder on your {1}.",
                    tag.Title,
                    provider.ServiceName);
                sb.AppendLine();
                sb.AppendLine();
            }

            sb.AppendLine("Do you want to continue?");

            /// Asks for confirmation.
            if (System.Windows.MessageBox.Show(sb.ToString(), "Delete " + tag.Title, MessageBoxButton.OKCancel) != System.Windows.MessageBoxResult.OK)
            {
                // Cancels.
                return;
            }

            /// Deletes everything.
            Model.DeleteCartridgeAndContent(tag);
        }
 private CartridgeSavegame CreateAutoSavegame(CartridgeTag tag)
 {
     return CreateSavegame(tag, "Auto Save", " {0}", false, true, _autoSaves);
 }
 private string GetDefaultName(CartridgeTag tag)
 {
     return String.Format("MySavegame{0}{1}{2}{3}",
         Timestamp.DayOfYear,
         Timestamp.Hour,
         Timestamp.Minute,
         Timestamp.Second);
 }
        private void SaveCore(
            CartridgeTag tag,
            Dictionary<CartridgeTag, CartridgeSavegame> savegameDict,
            Func<CartridgeTag, CartridgeSavegame> generator,
            bool displayError)
        {
            // Gets the current session' preferred save for the cartridge.
            CartridgeSavegame savegame;
            if (!savegameDict.TryGetValue(tag, out savegame))
            {
                // If there's none, makes one.
                savegame = generator(tag);
            }

            // Saves the game, updates the savegame metadata and cleans the history.
            SaveCore(tag, savegame, (t, s) =>
            {
                // Updates the savegame's attributes.
                s.Timestamp = DateTime.Now;

                // Saves the savegame to the store and adds it to the tag if needed.
                t.RefreshOrAddSavegame(s);

                // Ensures there's a unique history entry for this savegame.
                History history = _appViewModel.Model.History;
                history.RemoveAllOf(t.Guid, s.Name, HistoryEntry.Type.Saved);
                history.AddSavedGame(t, s);
            }, displayError);
        }
 private void SetFileProperties(CartridgeTag tag)
 {
     string fname = System.IO.Path.GetFileNameWithoutExtension(tag.Cartridge.Filename);
     SavegameFile = String.Format("/{0}/{1}_{2}.gws",
         tag.PathToSavegames,
         Name,
         fname
     );
     MetadataFile = SavegameFile + ".mf";
 }
		/// <summary>
		/// Displays a message when the async initialization failed,
		/// and returns back to the main menu.
		/// </summary>
		/// <param name="ex"></param>
		/// <param name="tag"></param>
		/// <param name="isRestore"></param>
		private void FailInit(AggregateException ex, CartridgeTag tag, bool isRestore = false)
		{
			// Let the app view model handle this crash.
			App.Current.ViewModel.HandleGameCrash(
				isRestore ? AppViewModel.CrashMessageType.Restore : AppViewModel.CrashMessageType.NewGame,
				ex,
				tag.Cartridge
				);
		}
 private void ShowCartridgeInfo(CartridgeTag cartTag)
 {
     // Show the cartridge info!
     App.Current.ViewModel.NavigationManager.NavigateToCartridgeInfo(cartTag);
 }
 /// <summary>
 /// Removes a cartridge from the store, and wipes all its related content, including
 /// cache, logs and savegames.
 /// </summary>
 /// <param name="tag"></param>
 public void DeleteCartridgeAndContent(CartridgeTag tag)
 {
     // Clears the history for this tag.
     History.RemoveAllOf(tag.Guid);
     
     // Removes it from the store.
     CartridgeStore.RemoveCartridgeTag(tag, true);
 }
Example #26
0
 /// <summary>
 /// Constructs a history entry of a particular type, populating
 /// its fields with the contents of a cartridge tag and a cartridge
 /// savegame, and using <code>DateTime.Now</code> as timestamp.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="cartTag"></param>
 /// <param name="savegame"></param>
 public HistoryEntry(HistoryEntry.Type type, CartridgeTag cartTag, CartridgeSavegame savegame)
     : this(type, cartTag)
 {
     RelatedSavegameHashColor = savegame.HashColor;
     RelatedSavegameName      = savegame.Name;
 }
 private void StartCartridge(CartridgeTag cartTag)
 {
     // Starts the cartridge!
     App.Current.ViewModel.NavigationManager.NavigateToGameHome(cartTag.Cartridge.Filename);
 }
Example #28
0
 /// <summary>
 /// Adds a history entry for a game that has been started.
 /// </summary>
 /// <param name="tag"></param>
 public void AddStartedGame(CartridgeTag tag)
 {
     Add(new HistoryEntry(HistoryEntry.Type.Started, tag));
 }
Example #29
0
        /// <summary>
        /// Constructs a history entry of a particular type, populating
        /// its fields with the contents of a cartridge tag, and using
        /// <code>DateTime.Now</code> as timestamp.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="cartTag"></param>
        public HistoryEntry(HistoryEntry.Type type, CartridgeTag cartTag)
        {
            EntryType = type;
            RelatedCartridgeFilename = cartTag.Cartridge.Filename;
            RelatedCartridgeGuid = cartTag.Guid;
            RelatedCartridgeName = cartTag.Title;

            BitmapSource thumb = (BitmapSource)cartTag.Thumbnail;
            RelatedCartridgeThumbnailBase64 = thumb == null ? null : Utils.ImageUtils.ToBase64String(thumb, ThumbnailWidth, ThumbnailWidth);

            Timestamp = DateTime.Now;
        }
Example #30
0
 /// <summary>
 /// Adds a history entry for a game that has been saved.
 /// </summary>
 /// <param name="tag"></param>
 /// <param name="savegame"></param>
 public void AddSavedGame(CartridgeTag tag, CartridgeSavegame savegame)
 {
     Add(new HistoryEntry(HistoryEntry.Type.Saved, tag, savegame));
 }
        /// <summary>
        /// Changes the name of this savegame.
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="name"></param>
        public void Rename(CartridgeTag tag, string name, IsolatedStorageFile isf)
        {
            string oldGwsFile = SavegameFile;
            string oldMdFile = MetadataFile;
            
            // Changes the properties.
            Name = name;
            SetFileProperties(tag);

            // Renames the files.
            if (isf.FileExists(oldGwsFile))
            {
                isf.MoveFile(oldGwsFile, SavegameFile);
            }
            if (isf.FileExists(oldMdFile))
            {
                isf.MoveFile(oldMdFile, MetadataFile);
            }
        }
Example #32
0
 /// <summary>
 /// Adds a history entry for a game that has been completed.
 /// </summary>
 /// <param name="tag"></param>
 public void AddCompletedGame(CartridgeTag tag)
 {
     Add(new HistoryEntry(HistoryEntry.Type.Completed, tag));
 }
        private void SetFileProperties(CartridgeTag tag, string saveFilename = null)
        {
			if (saveFilename == null)
			{
				string fname = System.IO.Path.GetFileNameWithoutExtension(tag.Cartridge.Filename);
				SavegameFile = String.Format("{0}/{1}_{2}.gws",
					tag.PathToSavegames,
					Name,
					fname
				);
			}
			else
			{
				SavegameFile = String.Format("{0}/{1}", tag.PathToSavegames, saveFilename);
				if (!SavegameFile.EndsWith(".gws", StringComparison.InvariantCultureIgnoreCase))
				{
					SavegameFile += ".gws";
				}
			}
            MetadataFile = SavegameFile + ".mf";
        }
		/// <summary>
		/// Navigates the app to the info page of a cartridge.
		/// </summary>
		public void NavigateToCartridgeInfo(CartridgeTag tag)
		{
			NavigateCore(new Uri(String.Format("/Views/CartridgeInfoPage.xaml?{0}={1}&{2}={3}", CartridgeInfoViewModel.CartridgeFilenameKey, tag.Cartridge.Filename, CartridgeInfoViewModel.CartridgeIdKey, tag.Guid), UriKind.Relative));
		}
 private CartridgeSavegame CreateQuickSavegame(CartridgeTag tag)
 {
     return CreateSavegame(tag, "Quick Save", " {0}", true, false, _quickSaves);
 }
 /// <summary>
 /// Called when a game started.
 /// </summary>
 /// <param name="tag">Cartridge that started.</param>
 /// <param name="savegame">Optional savegame restored when the game started.</param>
 public void HandleGameStarted(CartridgeTag tag, CartridgeSavegame savegame = null)
 {
     // Resets the session quick save.
     SavegameManager.InitSessionSavegames(tag, savegame);
 }