/// <summary> /// Load Collection of languages as BitmapSource /// </summary> /// <param name="vnInfoEntry"></param> /// <returns></returns> public static BindableCollection <BitmapSource> LoadLanguages(ref VnInfo vnInfoEntry) { try { if (vnInfoEntry != null) { var languageCollection = new BindableCollection <BitmapSource>(); foreach (var language in GetLanguages(vnInfoEntry.Languages)) { languageCollection.Add(new BitmapImage(new Uri(language))); } return(languageCollection); } else { return(new BindableCollection <BitmapSource>()); } } catch (Exception e) { App.Logger.Warning(e, "Failed to load relations"); SentrySdk.CaptureException(e); return(new BindableCollection <BitmapSource>()); } }
/// <summary> /// Load the languages, and add them to the view /// </summary> /// <param name="vnInfoEntry"></param> private void LoadLanguages(ref VnInfo vnInfoEntry) { var langCollection = VndbDataHelper.LoadLanguages(ref vnInfoEntry); LanguageCollection.Clear(); LanguageCollection.AddRange(langCollection); }
/// <summary> /// Download Vndb cover image /// </summary> /// <param name="vnId"></param> /// <returns></returns> internal static async Task DownloadCoverImageAsync(uint vnId) { try { RootViewModel.StatusBarPage.InfoText = App.ResMan.GetString("DownCoverImage"); var cred = CredentialManager.GetCredentials(App.CredDb); if (cred == null || cred.UserName.Length < 1) { return; } using var db = new LiteDatabase($"{App.GetDbStringWithoutPass}'{cred.Password}'"); VnInfo entry = db.GetCollection <VnInfo>(DbVnInfo.VnInfo.ToString()).Query().Where(x => x.VnId == vnId).FirstOrDefault(); if (entry == null) { return; } if (entry.ImageLink != null) { var uri = new Uri(entry.ImageLink); RootViewModel.StatusBarPage.IsFileDownloading = true; string path = $@"{App.AssetDirPath}\sources\vndb\images\cover\{entry.VnId}.jpg"; await ImageHelper.DownloadImageAsync(uri, NsfwHelper.RawRatingIsNsfw(entry.ImageRating), path); } } catch (Exception ex) { App.Logger.Warning(ex, "Failed to download cover image"); SentrySdk.CaptureException(ex); } finally { RootViewModel.StatusBarPage.IsFileDownloading = false; RootViewModel.StatusBarPage.InfoText = string.Empty; } }
private void StartVn() { try { if (Globals.VnId < 1) { return; } if (_isGameRunning) { Messenger.Default.Send(new NotificationMessage("Game Already Running")); } if (_isGameRunning == false) { _stopwatch.Reset(); Process process = null; using (var context = new DatabaseContext()) { VnInfo idList = context.VnInfo.FirstOrDefault(x => x.Title.Equals(_selectedVn)); VnUserData vnUserData = context.VnUserData.FirstOrDefault(x => x.VnId.Equals(idList.VnId)); if (vnUserData?.ExePath != null && Directory.Exists(vnUserData?.ExePath)) { string exepath = vnUserData.ExePath; string dirpath = Path.GetDirectoryName(exepath); if (dirpath != null) { Directory.SetCurrentDirectory(dirpath); } process = new Process { StartInfo = { FileName = exepath, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true }, EnableRaisingEvents = true }; _processList.Add(process); process.Start(); _isGameRunning = true; _stopwatch.Start(); IsPlayEnabled = false; } } Directory.SetCurrentDirectory(Directory.GetCurrentDirectory()); List <Process> children = process.GetChildProcesses(); _processList.AddRange(children); int initialChildrenCount = children.Count; if (process != null) { process.EnableRaisingEvents = true; process.Exited += delegate(object o, EventArgs args) { //Only allows the HasExited event to trigger when there are no child processes if (children.Count < 1 && initialChildrenCount == 0) { _stopwatch.Stop(); VnOrChildProcessExited(null, null); } }; } foreach (Process proc in children) { proc.EnableRaisingEvents = true; proc.Exited += VnOrChildProcessExited; } } } catch (Exception exception) { Globals.Logger.Error(exception); throw; } }
private async Task DownloadCoverImage() { if (ConnectionTest.VndbTcpSocketTest() == false) { //TODO: add a default cover image for when it can't connect online Globals.Logger.Warn("Could not connect to Vndb API over SSL"); Globals.StatusBar.SetOnlineStatusColor(false); Globals.StatusBar.IsShowOnlineStatusEnabled = true; await Task.Delay(3500); Globals.StatusBar.IsShowOnlineStatusEnabled = false; return; } using (var context = new DatabaseContext()) { Globals.StatusBar.IsWorkProcessing = true; Globals.StatusBar.ProgressText = "Loading cover image"; VnInfo vnData = context.VnInfo.FirstOrDefault(t => t.Title == (_selectedVn)); if (vnData == null) { return; } string url = vnData.ImageLink; bool nsfw = Convert.ToBoolean(vnData.ImageNsfw); string pathNoExt = $@"{Globals.DirectoryPath}\Data\images\cover\{Globals.VnId}"; string path = $@"{Globals.DirectoryPath}\Data\images\cover\{Globals.VnId}.jpg"; try { switch (nsfw) { case true: if (!File.Exists(pathNoExt)) { Globals.StatusBar.IsDownloading = true; Globals.StatusBar.ProgressText = "Loading cover image"; Thread.Sleep(150); //to be nice to the server WebClient client = new WebClient(); using (MemoryStream stream = new MemoryStream(await client.DownloadDataTaskAsync(new Uri(url)))) { string base64Img = Base64Converter.ImageToBase64(Image.FromStream(stream), ImageFormat.Jpeg); File.WriteAllText(pathNoExt, base64Img); } client.Dispose(); } break; case false: if (!File.Exists(path)) { Globals.StatusBar.IsDownloading = true; Globals.StatusBar.ProgressText = "Loading cover image"; Thread.Sleep(150); //to be nice to the server WebClient client = new WebClient(); await client.DownloadFileTaskAsync(new Uri(url), path); client.Dispose(); } break; } Globals.StatusBar.IsDownloading = false; Globals.StatusBar.ProgressText = String.Empty; } catch (WebException ex) { Globals.Logger.Error(ex); throw; } catch (Exception ex) { Globals.Logger.Error(ex); throw; } Globals.StatusBar.IsWorkProcessing = false; Globals.StatusBar.ProgressText = String.Empty; } }