public static async Task StartupCheck(string appName, ProcessPriorityClass priorityLevel) { try { Debug.WriteLine("Checking application status."); //Get current process information Process currentProcess = Process.GetCurrentProcess(); string processName = currentProcess.ProcessName; Process[] activeProcesses = Process.GetProcessesByName(processName); //Check if application is already running if (activeProcesses.Length > 1) { Debug.WriteLine("Application " + appName + " is already running, closing the process"); Environment.Exit(0); return; } //Set the working directory to executable directory try { Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); } catch { } //Set the application priority level try { currentProcess.PriorityClass = priorityLevel; } catch { } //Check - Windows version if (AVFunctions.DevOsVersion() < 10) { List <string> messageAnswers = new List <string>(); messageAnswers.Add("Ok"); await new AVMessageBox().Popup(null, "Windows 10 required", appName + " only supports Windows 10 or newer.", messageAnswers); //Close the application Environment.Exit(0); return; } //Check for missing user folders AVFiles.Directory_Create(@"Assets\User\Apps", false); AVFiles.Directory_Create(@"Assets\User\Clocks", false); AVFiles.Directory_Create(@"Assets\User\Fonts", false); AVFiles.Directory_Create(@"Assets\User\Games", false); AVFiles.Directory_Create(@"Assets\User\Sounds", false); } catch { } }
public static async Task ApplicationStart() { try { Debug.WriteLine("NewsScroll startup checks."); //Check application settings await SettingsPage.SettingsCheck(); //Create image cache folder AVFiles.Directory_Create(@"Cache", false, true); //Cleanup image download cache CleanImageDownloadCache(); //Adjust the color theme AppAdjust.AdjustColorTheme(); //Adjust the font sizes AppAdjust.AdjustFontSizes(); //Connect to the database if (!DatabaseConnect()) { List <string> messageAnswers = new List <string>(); messageAnswers.Add("Ok"); string messageResult = await MessagePopup.Popup("Failed to connect to the database", "Your database will be cleared, please restart the application to continue.", messageAnswers); await DatabaseReset(); System.Diagnostics.Process.GetCurrentProcess().Kill(); return; } //Create the database tables await DatabaseCreate(); //Register application timers TimersRegister(); //Register Application Events EventsRegister(); //Prevent application lock screen DeviceDisplay.KeepScreenOn = true; } catch { } }
//Download console information public async Task <DownloadInfoConsole> DownloadInfoConsole(string nameConsole, int imageWidth) { try { //Filter the name string nameConsoleSave = FilterNameRom(nameConsole, true, false, false, 0); //Show the text input popup string nameConsoleDownload = await Popup_ShowHide_TextInput("Console search", nameConsoleSave, "Search information for the console", true); if (string.IsNullOrWhiteSpace(nameConsoleDownload)) { Debug.WriteLine("No search term entered."); return(null); } nameConsoleDownload = FilterNameRom(nameConsoleDownload, false, true, false, 0); //Search for consoles IEnumerable <ApiIGDBPlatforms> iGDBPlatforms = vApiIGDBPlatforms.Where(x => FilterNameRom(x.name, false, true, false, 0).Contains(nameConsoleDownload) || (x.alternative_name != null && FilterNameRom(x.alternative_name, false, true, false, 0).Contains(nameConsoleDownload))); if (iGDBPlatforms == null || !iGDBPlatforms.Any()) { Debug.WriteLine("No consoles found"); await Notification_Send_Status("Close", "No consoles found"); return(null); } //Ask user which console to download List <DataBindString> Answers = new List <DataBindString>(); BitmapImage imageAnswer = FileToBitmapImage(new string[] { "Assets/Default/Icons/Emulator.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); foreach (ApiIGDBPlatforms infoPlatforms in iGDBPlatforms) { DataBindString answerDownload = new DataBindString(); answerDownload.ImageBitmap = imageAnswer; answerDownload.Name = infoPlatforms.name; answerDownload.NameSub = infoPlatforms.alternative_name; answerDownload.Data1 = infoPlatforms; Answers.Add(answerDownload); } //Get selected result DataBindString messageResult = await Popup_Show_MessageBox("Select a found console (" + Answers.Count() + ")", "* Information will be saved in the \"Assets\\User\\Games\\Downloaded\" folder as:\n" + nameConsoleSave, "Download image and description for the console:", Answers); if (messageResult == null) { Debug.WriteLine("No console selected"); return(null); } //Create downloaded directory AVFiles.Directory_Create("Assets/User/Games/Downloaded", false); //Convert result back to json ApiIGDBPlatforms selectedConsole = (ApiIGDBPlatforms)messageResult.Data1; await Notification_Send_Status("Download", "Downloading information"); Debug.WriteLine("Downloading information for: " + nameConsole); //Get the platform versions id string firstPlatformId = selectedConsole.versions.FirstOrDefault().ToString(); ApiIGDBPlatformVersions[] iGDBPlatformVersions = await ApiIGDBDownloadPlatformVersions(firstPlatformId); if (iGDBPlatformVersions == null || !iGDBPlatformVersions.Any()) { Debug.WriteLine("No information found"); await Notification_Send_Status("Close", "No information found"); return(null); } ApiIGDBPlatformVersions targetPlatformVersions = iGDBPlatformVersions.FirstOrDefault(); await Notification_Send_Status("Download", "Downloading image"); Debug.WriteLine("Downloading image for: " + nameConsole); //Get the image url BitmapImage downloadedBitmapImage = null; string downloadImageId = targetPlatformVersions.platform_logo.ToString(); if (downloadImageId != "0") { ApiIGDBImage[] iGDBImages = await ApiIGDB_DownloadImage(downloadImageId, "platform_logos"); if (iGDBImages == null || !iGDBImages.Any()) { Debug.WriteLine("No images found"); await Notification_Send_Status("Close", "No images found"); return(null); } //Download and save image ApiIGDBImage infoImages = iGDBImages.FirstOrDefault(); Uri imageUri = new Uri("https://images.igdb.com/igdb/image/upload/t_720p/" + infoImages.image_id + ".png"); byte[] imageBytes = await AVDownloader.DownloadByteAsync(5000, "CtrlUI", null, imageUri); if (imageBytes != null && imageBytes.Length > 256) { try { //Convert bytes to a BitmapImage downloadedBitmapImage = BytesToBitmapImage(imageBytes, imageWidth); //Save bytes to image file File.WriteAllBytes("Assets/User/Games/Downloaded/" + nameConsoleSave + ".png", imageBytes); Debug.WriteLine("Saved image: " + imageBytes.Length + "bytes/" + imageUri); } catch { } } } //Json settings JsonSerializerSettings jsonSettings = new JsonSerializerSettings(); jsonSettings.NullValueHandling = NullValueHandling.Ignore; //Json serialize string serializedObject = JsonConvert.SerializeObject(targetPlatformVersions, jsonSettings); //Save json information File.WriteAllText("Assets/User/Games/Downloaded/" + nameConsoleSave + ".json", serializedObject); await Notification_Send_Status("Download", "Downloaded information"); Debug.WriteLine("Downloaded and saved information for: " + nameConsole); //Return the information DownloadInfoConsole downloadInfo = new DownloadInfoConsole(); downloadInfo.ImageBitmap = downloadedBitmapImage; downloadInfo.Details = targetPlatformVersions; return(downloadInfo); } catch (Exception ex) { Debug.WriteLine("Failed downloading console information: " + ex.Message); await Notification_Send_Status("Close", "Failed downloading"); return(null); } }
//Download game information public async Task <DownloadInfoGame> DownloadInfoGame(string nameRom, int imageWidth, bool saveOriginalName) { try { //Filter the game name string nameRomSaveOriginal = FilterNameFile(nameRom); string nameRomSaveFilter = FilterNameRom(nameRom, true, false, true, 0); //Show the text input popup string nameRomDownload = await Popup_ShowHide_TextInput("Game search", nameRomSaveFilter, "Search information for the game", true); if (string.IsNullOrWhiteSpace(nameRomDownload)) { Debug.WriteLine("No search term entered."); return(null); } nameRomDownload = nameRomDownload.ToLower(); await Notification_Send_Status("Download", "Downloading information"); Debug.WriteLine("Downloading information for: " + nameRom); //Download available games IEnumerable <ApiIGDBGames> iGDBGames = await ApiIGDB_DownloadGames(nameRomDownload); if (iGDBGames == null || !iGDBGames.Any()) { Debug.WriteLine("No games found"); await Notification_Send_Status("Close", "No games found"); return(null); } //Ask user which game to download List <DataBindString> Answers = new List <DataBindString>(); BitmapImage imageAnswer = FileToBitmapImage(new string[] { "Assets/Default/Icons/Game.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); foreach (ApiIGDBGames infoGames in iGDBGames) { //Check if information is available if (infoGames.cover == 0 && string.IsNullOrWhiteSpace(infoGames.summary)) { continue; } //Release date string gameReleaseDate = string.Empty; string gameReleaseYear = string.Empty; ApiIGDB_ReleaseDateToString(infoGames, out gameReleaseDate, out gameReleaseYear); //Game platforms string gamePlatforms = string.Empty; if (infoGames.platforms != null) { foreach (int platformId in infoGames.platforms) { ApiIGDBPlatforms apiIGDBPlatforms = vApiIGDBPlatforms.Where(x => x.id == platformId).FirstOrDefault(); gamePlatforms = AVFunctions.StringAdd(gamePlatforms, apiIGDBPlatforms.name, ","); } } DataBindString answerDownload = new DataBindString(); answerDownload.ImageBitmap = imageAnswer; answerDownload.Name = infoGames.name; answerDownload.NameSub = gamePlatforms; answerDownload.NameDetail = gameReleaseYear; answerDownload.Data1 = infoGames; Answers.Add(answerDownload); } //Get selected result DataBindString messageResult = await Popup_Show_MessageBox("Select a found game (" + Answers.Count() + ")", "* Information will be saved in the \"Assets\\User\\Games\\Downloaded\" folder as:\n" + nameRomSaveFilter, "Download image and description for the game:", Answers); if (messageResult == null) { Debug.WriteLine("No game selected"); return(null); } //Create downloaded directory AVFiles.Directory_Create("Assets/User/Games/Downloaded", false); //Convert result back to json ApiIGDBGames selectedGame = (ApiIGDBGames)messageResult.Data1; await Notification_Send_Status("Download", "Downloading image"); Debug.WriteLine("Downloading image for: " + nameRom); //Get the image url BitmapImage downloadedBitmapImage = null; string downloadImageId = selectedGame.cover.ToString(); if (downloadImageId != "0") { ApiIGDBImage[] iGDBImages = await ApiIGDB_DownloadImage(downloadImageId, "covers"); if (iGDBImages == null || !iGDBImages.Any()) { Debug.WriteLine("No images found"); await Notification_Send_Status("Close", "No images found"); return(null); } //Download and save image ApiIGDBImage infoImages = iGDBImages.FirstOrDefault(); Uri imageUri = new Uri("https://images.igdb.com/igdb/image/upload/t_720p/" + infoImages.image_id + ".png"); byte[] imageBytes = await AVDownloader.DownloadByteAsync(5000, "CtrlUI", null, imageUri); if (imageBytes != null && imageBytes.Length > 256) { try { //Convert bytes to a BitmapImage downloadedBitmapImage = BytesToBitmapImage(imageBytes, imageWidth); //Save bytes to image file if (saveOriginalName) { File.WriteAllBytes("Assets/User/Games/Downloaded/" + nameRomSaveOriginal + ".png", imageBytes); } else { File.WriteAllBytes("Assets/User/Games/Downloaded/" + nameRomSaveFilter + ".png", imageBytes); } Debug.WriteLine("Saved image: " + imageBytes.Length + "bytes/" + imageUri); } catch { } } } //Json settings JsonSerializerSettings jsonSettings = new JsonSerializerSettings(); jsonSettings.NullValueHandling = NullValueHandling.Ignore; //Json serialize string serializedObject = JsonConvert.SerializeObject(selectedGame, jsonSettings); //Save json information if (saveOriginalName) { File.WriteAllText("Assets/User/Games/Downloaded/" + nameRomSaveOriginal + ".json", serializedObject); } else { File.WriteAllText("Assets/User/Games/Downloaded/" + nameRomSaveFilter + ".json", serializedObject); } await Notification_Send_Status("Download", "Downloaded information"); Debug.WriteLine("Downloaded and saved information for: " + nameRom); //Return the information DownloadInfoGame downloadInfo = new DownloadInfoGame(); downloadInfo.ImageBitmap = downloadedBitmapImage; downloadInfo.Details = selectedGame; return(downloadInfo); } catch (Exception ex) { Debug.WriteLine("Failed downloading game information: " + ex.Message); await Notification_Send_Status("Close", "Failed downloading"); return(null); } }
public static async Task Application_LaunchCheck(string applicationName, ProcessPriorityClass priorityLevel, bool skipFileCheck, bool focusActiveProcess) { try { Debug.WriteLine("Checking application status."); Process currentProcess = Process.GetCurrentProcess(); string processName = currentProcess.ProcessName; Process[] activeProcesses = Process.GetProcessesByName(processName); //Check - If application is already running if (activeProcesses.Length > 1) { Debug.WriteLine("Application is already running."); //Show the active process if (focusActiveProcess) { foreach (Process activeProcess in activeProcesses) { try { if (currentProcess.Id != activeProcess.Id) { Debug.WriteLine("Showing active process: " + activeProcess.Id); await FocusProcessWindow(applicationName, activeProcess.Id, activeProcess.MainWindowHandle, 0, false, false); } } catch { } } } //Close the current process Debug.WriteLine("Closing the process."); Environment.Exit(0); return; } //Set the working directory to executable directory try { Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); } catch { } //Set the application priority level try { currentProcess.PriorityClass = priorityLevel; } catch { } //Check - Windows version check if (AVFunctions.DevOsVersion() < 10) { MessageBox.Show(applicationName + " only supports Windows 10 or newer.", applicationName); Environment.Exit(0); return; } //Check for missing application files if (!skipFileCheck) { ApplicationFiles = ApplicationFiles.Concat(ProfileFiles).Concat(ResourcesFiles).Concat(AssetsDefaultFiles).ToArray(); foreach (string checkFile in ApplicationFiles) { try { if (!File.Exists(checkFile)) { MessageBox.Show("File: " + checkFile + " could not be found, please check your installation.", applicationName); Environment.Exit(0); return; } } catch { } } } //Check for missing user folders AVFiles.Directory_Create(@"Assets\User\Apps", false); AVFiles.Directory_Create(@"Assets\User\Clocks", false); AVFiles.Directory_Create(@"Assets\User\Fonts", false); AVFiles.Directory_Create(@"Assets\User\Games", false); AVFiles.Directory_Create(@"Assets\User\Sounds", false); } catch { } }