Exemplo n.º 1
0
        public static void AddBookmark(string book, Dialogue d)
        {
			var roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;

			roamingSettings.Values[book] = d.Line;

        }
Exemplo n.º 2
0
		public static async Task<ObservableCollection<Dialogue>> GetDialogues(string filename)
		{
			ObservableCollection<Dialogue> dialogues = new ObservableCollection<Dialogue>();

			try
			{
				string previousName = "";
				TextAlignment previousAlignment = TextAlignment.Right;

				// Get the file.
				//StorageFolder books = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Books");
				//StorageFile file = await books.GetFileAsync(filename);
				
				StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Books/" + filename));
				
				string text = await Windows.Storage.FileIO.ReadTextAsync(file);

				char[] sep = new char[] { '\r', '\n' };
				List<string> lines = new List<string>(text.Split(sep, StringSplitOptions.RemoveEmptyEntries));

				foreach (string line in lines)
				{
					var d = new Dialogue();
					var types = line.Split('#');

					d.LineType = (Constants.LineType)Enum.Parse(typeof(Constants.LineType), types[0]);

					switch (d.LineType)
					{
						case Constants.LineType.Banner:
							d.Alignment = TextAlignment.Center;
							break;
						case Constants.LineType.Notice:
							d.Alignment = TextAlignment.Center;
							break;
						case Constants.LineType.Dialogue:
							d.Alignment = TextAlignment.Left;
							break;
					}

					var speaker = types[1].Split('=');

					d.Name = speaker[0];
					if (string.IsNullOrEmpty(d.Name))
						d.Name = "Commentator";

					if (speaker.Length > 1)
						d.Line = speaker[1];

					if (d.LineType == Constants.LineType.Dialogue)
					{
						if (d.Name == previousName)
						{
							d.Alignment = previousAlignment;
						}
						else
						{
							if (previousAlignment == TextAlignment.Left)
								d.Alignment = TextAlignment.Right;
							else d.Alignment = TextAlignment.Left;
						}

						previousName = d.Name;
						previousAlignment = d.Alignment;
					}

					dialogues.Add(d);
				}

				return dialogues;
			}
			catch (Exception ex)
			{
				System.Diagnostics.Debug.WriteLine("Customformat error:" + ex.Message);
				throw ex;
			}
		}