/// <summary> /// byte배열 형태의 폰트 데이터를 저장한다. (MKV 내의 폰트 등) /// </summary> /// <param name="fontsData"></param> /// <returns></returns> public static async void InstallFont(IEnumerable <KeyValuePair <string, byte[]> > fontsData, bool fireListChangedEvent) { var folder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("Fonts", CreationCollisionOption.OpenIfExists); await Task.Factory.StartNew(() => { var compare = new FontPathCompare(); Parallel.ForEach(fontsData, async(fontData) => { StorageFile fontFile = null; fontFile = await folder.CreateFileAsync(fontData.Key, Windows.Storage.CreationCollisionOption.OpenIfExists); var prop = await fontFile.GetBasicPropertiesAsync(); if (prop.Size == 0) { //시뉵 폰트 파일 저장 await Windows.Storage.FileIO.WriteBytesAsync(fontFile, fontData.Value); //System.Diagnostics.Debug.WriteLine($"폰트 저장 : {fontData.Key}"); } else { //이미 폰트가 존재하는 경우, 새롭게 설치 요청이 들어오면 기존 삭제 대상폰트 리스트에서 제거 한다. (초기화) FontDAO.DeleteTempFont(new string[] { fontFile.Path }); //System.Diagnostics.Debug.WriteLine($"폰트 이미 존재 : {fontData.Key}"); } List <KeyName> addedList = new List <KeyName>(); foreach (var font in await GetFontItems(fontFile)) { lock (lockobj) { if (!FontList.Contains(font, compare)) { if (!addedList.Contains(font)) { addedList.Add(font); } FontList.Add(font); } } } if (fireListChangedEvent) { //이벤트 처리 if (FontFamilyListChanged != null && addedList.Count > 0) { FontFamilyListChanged(FontList, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, addedList)); //System.Diagnostics.Debug.WriteLine($"추가 이벤트 발생 : {fontData.Key}"); } } }); }); }
private void LoadProgramState() { try { var isoStore = IsolatedStorageFile.GetUserStoreForAssembly(); if (isoStore.FileExists(SavedStateFileName)) { XmlSerializer serializer = new XmlSerializer(typeof(ProgramState)); using var isoStream = new IsolatedStorageFileStream(SavedStateFileName, FileMode.Open, isoStore); using var reader = new StreamReader(isoStream); var state = (ProgramState)serializer.Deserialize(reader); var savedFontFamily = new FontFamily(state.FontFamilySource); // Check if the saved font exists in the collection // in case the user has deleted the font that was saved if (FontList.Contains(savedFontFamily)) { SelectedFont = savedFontFamily; } else { SelectedFont = DefaultFontFamily; } SelectedFontWeight = LocalizedFontWeight.FromEnglishName(state.FontWeight); SelectedFontSize = state.FontSize; SelectedKanjiFontSize = state.KanjiFontSize; SpacingAdjustment = state.SpacingAdjustment; GlyphHorizontalMargin = state.HorizontalMargin; DropShadowSettings.BlurRadius = state.BlurRadius; DropShadowSettings.Direction = state.Direction; DropShadowSettings.Depth = state.ShadowDepth; DropShadowSettings.Opacity = state.Opacity; AdvancedExpanded = state.AdvancedExpanded; DisplayBoundingRectanglesChecked = state.DisplayBoundingRectangles; UseDarkTheme = state.UseDarkTheme; if (!string.IsNullOrEmpty(state.SelectedLanguage)) { CultureResources.ChangeCulture(new CultureInfo(state.SelectedLanguage)); var lang = Languages.Find(l => l.Culture.Name == state.SelectedLanguage); if (lang != null) { SelectedLanguage = lang; } } } else { SelectedFont = DefaultFontFamily; } } catch (IsolatedStorageException ex) { Console.WriteLine("Loading state failed: " + ex.Message); } catch (FileNotFoundException) { // Default settings will be used } }