Exemplo n.º 1
0
        /// <summary>
        /// 사용자가 입력한 폰트 파일을 저장한다.
        /// </summary>
        /// <param name="fontFile"></param>
        /// <returns></returns>
        public static async Task InstallFont(StorageFile fontFile, ObservableCollection <KeyName> fontListSource, TappedEventHandler tapped)
        {
            var folder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("Fonts", CreationCollisionOption.OpenIfExists);

            try
            {
                //폰트 복사(설치)
                var copy = await fontFile.CopyAsync(folder, Path.GetFileName(fontFile.Name), NameCollisionOption.FailIfExists);

                List <KeyName> addedFontList = new List <KeyName>();

                foreach (var fontItem in await GetFontItems(copy))
                {
                    fontItem.ItemTapped = tapped;
                    if (fontListSource != null)
                    {
                        if (!fontListSource.Any(x => x.Key == fontItem.Key))
                        {
                            var index = fontListSource.IndexOf(fontListSource.LastOrDefault(x => x.Name.CompareTo(fontItem.Name) < 0));
                            fontListSource.Insert(index + 1, fontItem);
                        }
                    }

                    if (FontList != null)
                    {
                        if (!FontList.Any(x => x.Key == fontItem.Key))
                        {
                            var index = FontList.IndexOf(FontList.Where(x => x.Type == FontTypes.App.ToString()).LastOrDefault(x => x.Name.CompareTo(fontItem.Name) < 0));
                            FontList.Insert(index + 1, fontItem);
                        }
                    }

                    if (!addedFontList.Contains(fontItem))
                    {
                        addedFontList.Add(fontItem);
                    }

                    if (fontItem.Payload is StorageFile)
                    {
                        var path = (fontItem.Payload as StorageFile).Path;
                        FontDAO.DeleteTempFont(new string[] { path });
                    }
                }

                //이벤트 처리
                if (FontFamilyListChanged != null)
                {
                    FontFamilyListChanged(FontList, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, addedFontList));
                }
            }
            catch (Exception) { }
        }