Exemplo n.º 1
0
        //Set the feed icon
        private async void btn_SetIcon_Clicked(object sender, EventArgs e)
        {
            try
            {
                Feeds SelectedItem = (Feeds)listview_Items.SelectedItem;
                if (SelectedItem != null)
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Set custom icon");
                    messageAnswers.Add("Reset the icon");
                    messageAnswers.Add("Cancel");

                    string messageResult = await MessagePopup.Popup("Change the feed icon", "Would you like to set a custom feed icon for " + SelectedItem.feed_title + "?", messageAnswers);

                    if (messageResult == "Set custom icon")
                    {
                        Debug.WriteLine("Changing icon for feed: " + SelectedItem.feed_id + " / " + SelectedItem.feed_title);

                        PickOptions pickOptions = new PickOptions();
                        pickOptions.FileTypes = FilePickerFileType.Png;

                        FileResult pickResult = await FilePicker.PickAsync(pickOptions);

                        if (pickResult != null)
                        {
                            //Load feed icon
                            Stream imageStream = await pickResult.OpenReadAsync();

                            //Update feed icon
                            if (imageStream.CanSeek)
                            {
                                imageStream.Position = 0;
                            }
                            SelectedItem.feed_icon = ImageSource.FromStream(() => imageStream);

                            //Save feed icon
                            AVFiles.File_SaveStream(SelectedItem.feed_id + ".png", imageStream, true, true);
                        }
                    }
                    else if (messageResult == "Reset the icon")
                    {
                        //Delete the feed icon
                        AVFiles.File_Delete(SelectedItem.feed_id + ".png", true);

                        //Load default feed icon
                        SelectedItem.feed_icon = ImageSource.FromResource("NewsScroll.Assets.iconRSS-Dark.png");

                        //Reset the online status
                        OnlineUpdateFeeds = true;
                        ApiMessageError   = string.Empty;

                        List <string> messageAnswersReset = new List <string>();
                        messageAnswersReset.Add("Ok");

                        await MessagePopup.Popup("Feed icon reset", "The feed icon has been reset and will be refreshed on the next online feed update, you can refresh the feeds by clicking on the refresh icon above.", messageAnswersReset);
                    }
                }
            }
            catch { }
        }
Exemplo n.º 2
0
        //Database Reset
        public static async Task DatabaseReset()
        {
            try
            {
                if (EventProgressDisableUI != null)
                {
                    EventProgressDisableUI("Resetting the database.", true);
                }
                Debug.WriteLine("Resetting the database.");

                //Delete all files from local storage
                string[] localFiles = AVFiles.Directory_ListFiles(string.Empty, true);
                foreach (string localFile in localFiles)
                {
                    AVFiles.File_Delete(localFile, false);
                }

                //Reset the online status
                OnlineUpdateFeeds   = true;
                OnlineUpdateNews    = true;
                OnlineUpdateStarred = true;
                ApiMessageError     = string.Empty;

                //Reset the last update setting
                await AppSettingSave("LastItemsUpdate", "Never");

                Debug.WriteLine("Resetted the database.");
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed resetting the database: " + ex.Message);
            }
        }
Exemplo n.º 3
0
        //Save the image
        private async void button_iconSave_Tap(object sender, EventArgs e)
        {
            try
            {
                string fileName    = Path.GetFileName(vImageLink);
                string localFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                string filePath    = Path.Combine(localFolder, fileName);

                //Download image
                Uri    imageUri    = new Uri(vImageLink);
                Stream imageStream = await dependencyAVImages.DownloadResizeImage(imageUri, 999999, 999999);

                //Save image
                AVFiles.File_SaveStream(filePath, imageStream, true, false);
            }
            catch
            {
                List <string> messageAnswers = new List <string>();
                messageAnswers.Add("Ok");

                await MessagePopup.Popup("Failed to save", "Failed to save the image, please check your internet connection and try again.", messageAnswers);

                Debug.WriteLine("Failed to save the image.");
            }
        }
Exemplo n.º 4
0
 void RemoveStartupShortcut(string shortcutName)
 {
     try
     {
         string        shortcutPath      = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
         DirectoryInfo shortcutDirectory = new DirectoryInfo(shortcutPath);
         FileInfo[]    shortcutFiles     = shortcutDirectory.GetFiles("*.url", SearchOption.AllDirectories);
         foreach (FileInfo shortcutFile in shortcutFiles)
         {
             try
             {
                 if (shortcutFile.Name.ToLower() == shortcutName.ToLower())
                 {
                     AVFiles.File_Delete(shortcutFile.FullName);
                     Debug.WriteLine("Removed startup shortcut: " + shortcutFile.FullName);
                 }
             }
             catch { }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Failed to remove startup shortcut: " + ex.Message);
     }
 }
Exemplo n.º 5
0
        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 { }
        }
Exemplo n.º 6
0
        //Load the News Scroll database size
        public static string GetDatabaseSize()
        {
            string DatabaseSize = "empty";

            try
            {
                long fileSize = AVFiles.File_Size("Database.sqlite", true);
                DatabaseSize = string.Format("{0:0.00}", +decimal.Divide(fileSize, 1048576)) + "MB";
            }
            catch { }
            return(DatabaseSize);
        }
Exemplo n.º 7
0
        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 { }
        }
Exemplo n.º 8
0
 //Cleanup image download cache
 public static void CleanImageDownloadCache()
 {
     try
     {
         Debug.WriteLine("Cleaning image download cache...");
         string[] fileNames = AVFiles.Directory_ListFiles("Cache", true);
         foreach (string fileName in fileNames)
         {
             DateTime fileDate   = AVFiles.File_CreationTime(fileName, false);
             int      removeDays = Convert.ToInt32(AppSettingLoad("RemoveItemsRange"));
             if (DateTime.Now.Subtract(fileDate).TotalDays > removeDays)
             {
                 AVFiles.File_Delete(fileName, false);
                 Debug.WriteLine("Removing image cache: " + fileName + fileDate);
             }
         }
     }
     catch { }
 }
Exemplo n.º 9
0
        static public async Task <bool> DeleteFeed(string FeedId)
        {
            try
            {
                string[][] RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppSettingLoad("ConnectApiAuth").ToString() } };

                string        PostString  = "ac=unsubscribe&s=feed/" + FeedId;
                StringContent PostContent = new StringContent(PostString, Encoding.UTF8, "application/x-www-form-urlencoded");
                Uri           PostUri     = new Uri(ApiConnectionUrl + "subscription/edit");

                string PostHttp = await AVDownloader.SendPostRequestAsync(7500, "News Scroll", RequestHeader, PostUri, PostContent);

                if (PostHttp != null && (PostHttp == "OK" || PostHttp.Contains("<error>Not found</error>")))
                {
                    //Clear feed from database
                    await vSQLConnection.ExecuteAsync("DELETE FROM TableFeeds WHERE feed_id = ('" + FeedId + "')");

                    //Clear items from database
                    await vSQLConnection.ExecuteAsync("DELETE FROM TableItems WHERE item_feed_id = ('" + FeedId + "') AND item_star_status = ('0')");

                    //Delete the feed icon
                    AVFiles.File_Delete(FeedId + ".png", true);

                    Debug.WriteLine("Deleted the feed and items off: " + FeedId);
                    return(true);
                }
                else
                {
                    Debug.WriteLine("Failed to delete feed: " + FeedId + " / server error.");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to delete feed: " + FeedId + " / " + ex.Message);
                return(false);
            }
        }
Exemplo n.º 10
0
        //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);
            }
        }
Exemplo n.º 11
0
        //Load feeds in selection
        async Task LoadSelectionFeeds(List <TableFeeds> LoadTableFeeds, List <TableItems> LoadTableItems, bool Silent, bool EnableUI)
        {
            try
            {
                if (!Silent)
                {
                    ProgressDisableUI("Loading selection feeds...", true);
                }
                Debug.WriteLine("Loading selection feeds, silent: " + Silent);

                combobox_FeedSelection.IsEnabled = false;
                combobox_FeedSelection.Opacity   = 0.30;
                await ClearObservableCollection(List_FeedSelect);

                //Check if received lists are empty
                if (LoadTableFeeds == null)
                {
                    LoadTableFeeds = await vSQLConnection.Table <TableFeeds>().OrderBy(x => x.feed_folder).ToListAsync();
                }
                if (LoadTableItems == null)
                {
                    LoadTableItems = await vSQLConnection.Table <TableItems>().ToListAsync();
                }

                //Filter un/ignored feeds
                List <string>     IgnoredFeedList   = LoadTableFeeds.Where(x => x.feed_ignore_status == true).Select(x => x.feed_id).ToList();
                List <TableFeeds> UnignoredFeedList = LoadTableFeeds.Where(x => x.feed_ignore_status == false).ToList();
                Feeds             TempFeed          = new Feeds();

                //Add all feeds selection
                TempFeed.feed_id = "0";
                int   TotalItemsAll = ProcessItemLoad.FilterNewsItems(IgnoredFeedList, LoadTableItems, TempFeed, 0, AppVariables.ItemsToLoadMax).Count();
                Feeds FeedItemAll   = new Feeds();
                FeedItemAll.feed_icon              = ImageSource.FromResource("NewsScroll.Assets.iconRSS-Dark.png");
                FeedItemAll.feed_title             = "All news items";
                FeedItemAll.feed_item_count        = TotalItemsAll;
                FeedItemAll.feed_collection_status = true;
                FeedItemAll.feed_id = "0";
                List_FeedSelect.Add(FeedItemAll);

                //Add unread feeds selection
                TempFeed.feed_id = "2";
                int   TotalItemsUnread = ProcessItemLoad.FilterNewsItems(IgnoredFeedList, LoadTableItems, TempFeed, 0, AppVariables.ItemsToLoadMax).Count();
                Feeds FeedItemUnread   = new Feeds();
                FeedItemUnread.feed_icon              = ImageSource.FromResource("NewsScroll.Assets.iconRSS-Dark.png");
                FeedItemUnread.feed_title             = "Unread news items";
                FeedItemUnread.feed_item_count        = TotalItemsUnread;
                FeedItemUnread.feed_collection_status = true;
                FeedItemUnread.feed_id = "2";
                List_FeedSelect.Add(FeedItemUnread);

                //Add read feeds selection
                TempFeed.feed_id = "1";
                int   TotalItemsRead = ProcessItemLoad.FilterNewsItems(IgnoredFeedList, LoadTableItems, TempFeed, 0, AppVariables.ItemsToLoadMax).Count();
                Feeds FeedItemRead   = new Feeds();
                FeedItemRead.feed_icon              = ImageSource.FromResource("NewsScroll.Assets.iconRSS-Dark.png");
                FeedItemRead.feed_title             = "Read news items";
                FeedItemRead.feed_item_count        = TotalItemsRead;
                FeedItemRead.feed_collection_status = true;
                FeedItemRead.feed_id = "1";
                List_FeedSelect.Add(FeedItemRead);

                //Feeds that are not ignored and contain items
                foreach (TableFeeds Feed in UnignoredFeedList)
                {
                    TempFeed.feed_id = Feed.feed_id;
                    int TotalItems = ProcessItemLoad.FilterNewsItems(IgnoredFeedList, LoadTableItems, TempFeed, 0, AppVariables.ItemsToLoadMax).Count();
                    if (TotalItems > 0)
                    {
                        //Add folder
                        string FeedFolder = Feed.feed_folder;
                        if (string.IsNullOrWhiteSpace(FeedFolder))
                        {
                            FeedFolder = "No folder";
                        }
                        Feeds FolderUpdate = List_FeedSelect.Where(x => x.feed_folder_title == FeedFolder && x.feed_folder_status).FirstOrDefault();
                        if (FolderUpdate == null)
                        {
                            //Load folder icon
                            ImageSource FolderIcon = ImageSource.FromResource("NewsScroll.Assets.iconFolder-Dark.png");

                            //Add folder
                            Feeds FolderItem = new Feeds();
                            FolderItem.feed_icon          = FolderIcon;
                            FolderItem.feed_title         = "(Folder) " + FeedFolder;
                            FolderItem.feed_folder_title  = FeedFolder;
                            FolderItem.feed_folder_status = true;
                            List_FeedSelect.Add(FolderItem);
                            //Debug.WriteLine("Added folder...");
                        }

                        //Add feed
                        //Load feed icon
                        ImageSource FeedIcon = null;
                        if (Feed.feed_id.StartsWith("user/"))
                        {
                            FeedIcon = ImageSource.FromResource("NewsScroll.Assets.iconUser-Dark.png");
                        }
                        else
                        {
                            FeedIcon = AVFiles.File_LoadImage(Feed.feed_id + ".png", true);
                        }
                        if (FeedIcon == null)
                        {
                            FeedIcon = ImageSource.FromResource("NewsScroll.Assets.iconRSS-Dark.png");
                        }

                        //Get the current feed item count
                        Feeds FeedItem = new Feeds();
                        FeedItem.feed_icon       = FeedIcon;
                        FeedItem.feed_title      = Feed.feed_title;
                        FeedItem.feed_item_count = TotalItems;
                        FeedItem.feed_id         = Feed.feed_id;
                        List_FeedSelect.Add(FeedItem);

                        //Update folder
                        FolderUpdate = List_FeedSelect.Where(x => x.feed_folder_title == FeedFolder && x.feed_folder_status).FirstOrDefault();
                        if (FolderUpdate != null)
                        {
                            FolderUpdate.feed_folder_ids.Add(Feed.feed_id);
                            FolderUpdate.feed_item_count = FolderUpdate.feed_item_count + FeedItem.feed_item_count;
                            //Debug.WriteLine("Updated folder...");
                        }
                    }
                }

                combobox_FeedSelection.IsEnabled = true;
                combobox_FeedSelection.Opacity   = 1;
            }
            catch { }
            if (EnableUI)
            {
                ProgressEnableUI();
            }
        }
Exemplo n.º 12
0
        //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);
            }
        }
Exemplo n.º 13
0
        //Update the item image content
        public static void ItemUpdateImages(object itemObject, bool resetContent)
        {
            try
            {
                Items updateItem = (Items)itemObject;
                if (resetContent)
                {
                    //Debug.WriteLine("Disappearing item: " + updateItem.item_title);
                    //Unload feed icon
                    if (updateItem.feed_icon != null)
                    {
                        updateItem.feed_icon = null;
                    }

                    //Unload status image
                    if (updateItem.item_read_icon != null)
                    {
                        updateItem.item_read_icon = null;
                    }
                    if (updateItem.item_star_icon != null)
                    {
                        updateItem.item_star_icon = null;
                    }

                    //Unload item image
                    if (updateItem.item_image != null)
                    {
                        updateItem.item_image = null;
                    }
                }
                else
                {
                    //Debug.WriteLine("Appearing item: " + updateItem.item_title);
                    //Load feed icon
                    if (updateItem.feed_icon == null)
                    {
                        if (updateItem.feed_id.StartsWith("user/"))
                        {
                            updateItem.feed_icon = ImageSource.FromResource("NewsScroll.Assets.iconUser-Dark.png");
                        }
                        else
                        {
                            updateItem.feed_icon = AVFiles.File_LoadImage(updateItem.feed_id + ".png", true);
                        }
                        if (updateItem.feed_icon == null)
                        {
                            updateItem.feed_icon = ImageSource.FromResource("NewsScroll.Assets.iconRSS-Dark.png");
                        }
                    }

                    //Load status image
                    if (updateItem.item_read_icon == null && updateItem.item_read_status)
                    {
                        updateItem.item_read_icon = ImageSource.FromResource("NewsScroll.Assets.iconRead-Dark.png");
                    }
                    if (updateItem.item_star_icon == null && updateItem.item_star_status)
                    {
                        updateItem.item_star_icon = ImageSource.FromResource("NewsScroll.Assets.iconStar-Dark.png");
                    }

                    //Load item image
                    string itemImageLink = updateItem.item_image_link;
                    if (updateItem.item_image == null && !string.IsNullOrWhiteSpace(itemImageLink) && updateItem.item_image_visibility == true && AppVariables.LoadMedia)
                    {
                        updateItem.item_image = itemImageLink;
                    }
                }
            }
            catch { }
        }
Exemplo n.º 14
0
        static public async Task <bool> Feeds(bool Silent, bool EnableUI)
        {
            try
            {
                if (!Silent)
                {
                    EventProgressDisableUI("Downloading latest feeds...", true);
                }
                Debug.WriteLine("Downloading latest feeds...");

                string[][] RequestHeader  = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppSettingLoad("ConnectApiAuth").ToString() } };
                string     DownloadString = await AVDownloader.DownloadStringAsync(10000, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "subscription/list?output=json"));

                JObject WebJObject = JObject.Parse(DownloadString);
                if (WebJObject["subscriptions"] != null && WebJObject["subscriptions"].HasValues)
                {
                    if (!Silent)
                    {
                        EventProgressDisableUI("Processing " + WebJObject["subscriptions"].Count() + " feeds...", true);
                    }
                    Debug.WriteLine("Processing " + WebJObject["subscriptions"].Count() + " feeds...");

                    List <string> ApiFeedIdList = new List <string>();
                    string[]      LocalFileList = AVFiles.Directory_ListFiles(string.Empty, true);

                    List <TableFeeds> TableUpdatedFeeds = new List <TableFeeds>();
                    List <TableFeeds> TableCurrentFeeds = await vSQLConnection.Table <TableFeeds>().ToListAsync();

                    foreach (JToken JTokenRoot in WebJObject["subscriptions"])
                    {
                        string FeedId    = JTokenRoot["sortid"].ToString();
                        string FeedTitle = JTokenRoot["title"].ToString();

                        string HtmlUrl = WebUtility.HtmlDecode(JTokenRoot["htmlUrl"].ToString());
                        HtmlUrl = WebUtility.UrlDecode(HtmlUrl);

                        Uri FullUrl = new Uri(HtmlUrl);
                        ApiFeedIdList.Add(FeedId);

                        TableFeeds TableResult = TableCurrentFeeds.Where(x => x.feed_id == FeedId).FirstOrDefault();
                        if (TableResult == null)
                        {
                            //Debug.WriteLine("Adding feed: " + FeedTitle);

                            TableFeeds AddFeed = new TableFeeds();
                            AddFeed.feed_id    = FeedId;
                            AddFeed.feed_title = FeedTitle;
                            AddFeed.feed_link  = FullUrl.Scheme + "://" + FullUrl.Host;

                            AddFeed.feed_ignore_status = false;
                            if (JTokenRoot["categories"] != null && JTokenRoot["categories"].HasValues)
                            {
                                AddFeed.feed_folder = JTokenRoot["categories"][0]["label"].ToString();
                            }

                            TableUpdatedFeeds.Add(AddFeed);
                        }
                        else
                        {
                            //Debug.WriteLine("Updating feed: " + FeedTitle);

                            TableResult.feed_title = FeedTitle;
                            TableResult.feed_link  = FullUrl.Scheme + "://" + FullUrl.Host;

                            if (JTokenRoot["categories"] != null && JTokenRoot["categories"].HasValues)
                            {
                                TableResult.feed_folder = JTokenRoot["categories"][0]["label"].ToString();
                            }

                            TableUpdatedFeeds.Add(TableResult);
                        }

                        //Check and download feed logo
                        if (!LocalFileList.Any(x => x.EndsWith(FeedId + ".png")))
                        {
                            try
                            {
                                if (!Silent)
                                {
                                    EventProgressDisableUI("Downloading " + FeedTitle + " icon...", true);
                                }

                                Uri    IconUrl      = new Uri("https://s2.googleusercontent.com/s2/favicons?domain=" + FullUrl.Host);
                                byte[] HttpFeedIcon = await AVDownloader.DownloadByteAsync(3000, "News Scroll", null, IconUrl);

                                if (HttpFeedIcon != null && HttpFeedIcon.Length > 75)
                                {
                                    AVFiles.File_SaveBytes(FeedId + ".png", HttpFeedIcon, true, true);
                                    Debug.WriteLine("Downloaded transparent logo: " + HttpFeedIcon.Length + "bytes/" + IconUrl);
                                }
                                else
                                {
                                    Debug.WriteLine("No logo found for: " + IconUrl);
                                }
                            }
                            catch { }
                        }
                    }

                    //Update the feeds in database
                    if (TableUpdatedFeeds.Any())
                    {
                        await vSQLConnection.InsertAllAsync(TableUpdatedFeeds, "OR REPLACE");
                    }

                    //Delete removed feeds from the database
                    List <string> DeletedFeeds = TableCurrentFeeds.Select(x => x.feed_id).Except(ApiFeedIdList).ToList();
                    Debug.WriteLine("Found deleted feeds: " + DeletedFeeds.Count());
                    foreach (string DeleteFeedId in DeletedFeeds)
                    {
                        await DeleteFeed(DeleteFeedId);
                    }
                }

                if (EnableUI)
                {
                    EventProgressEnableUI();
                }
                return(true);
            }
            catch
            {
                EventProgressEnableUI();
                return(false);
            }
        }
Exemplo n.º 15
0
        //Open the popup
        public async void OpenPopup(Items Source)
        {
            try
            {
                //Adjust the swiping direction
                SwipeBarAdjust();

                //Check if the header is hidden
                if (AppVariables.HeaderHidden)
                {
                    HideShowHeader(true);
                }

                //Update the status message
                ProgressDisableUI("Loading the item...");

                //Set item source
                vItemViewerItem  = Source;
                txt_AppInfo.Text = ApiMessageError + Source.feed_title;

                //Load feed icon
                if (vItemViewerItem.feed_id.StartsWith("user/"))
                {
                    image_feed_icon.Source = ImageSource.FromResource("NewsScroll.Assets.iconUser-Dark.png");
                }
                else
                {
                    image_feed_icon.Source = AVFiles.File_LoadImage(vItemViewerItem.feed_id + ".png", true);
                }
                if (image_feed_icon.Source == null)
                {
                    image_feed_icon.Source = ImageSource.FromResource("NewsScroll.Assets.iconRSS-Dark.png");
                }

                //Check if internet is available
                if (Connectivity.NetworkAccess == NetworkAccess.Internet)
                {
                    iconItem.IsVisible             = true;
                    iconBrowser.IsVisible          = true;
                    button_LoadFullItem.IsVisible  = true;
                    button_OpenInBrowser.IsVisible = true;
                }
                else
                {
                    iconItem.IsVisible             = false;
                    iconBrowser.IsVisible          = false;
                    button_LoadFullItem.IsVisible  = false;
                    button_OpenInBrowser.IsVisible = false;
                }

                //Update the star status
                if (Source.item_star_status == false)
                {
                    iconStar.Source = ImageSource.FromResource("NewsScroll.Assets.iconStarAdd.png");
                }
                else
                {
                    iconStar.Source = ImageSource.FromResource("NewsScroll.Assets.iconStarRemove.png");
                }
                iconStar.IsVisible = true;

                //Load item into the viewer
                await LoadItem(string.Empty);

                //Register page events
                RegisterPageEvents();

                //Update the status message
                ProgressEnableUI();
            }
            catch
            {
                Debug.WriteLine("Failed loading item.");
                await ClosePopup();
            }
        }
Exemplo n.º 16
0
        public static bool ProcessTableFeedsToList(ObservableCollection <Feeds> AddList, List <TableFeeds> LoadTableFeeds)
        {
            try
            {
                foreach (TableFeeds Feed in LoadTableFeeds)
                {
                    //Load and check feed id
                    string FeedId = Feed.feed_id;
                    if (!AddList.Any(x => x.feed_id == FeedId))
                    {
                        bool IgnoreStatus = Feed.feed_ignore_status ? true : false;

                        //Load feed folder
                        string FeedFolder = Feed.feed_folder;
                        if (string.IsNullOrWhiteSpace(FeedFolder))
                        {
                            FeedFolder = "No folder";
                        }

                        //Load feed icon
                        ImageSource FeedIcon = null;
                        if (FeedId.StartsWith("user/"))
                        {
                            FeedIcon = ImageSource.FromResource("NewsScroll.Assets.iconUser-Dark.png");
                        }
                        else
                        {
                            FeedIcon = AVFiles.File_LoadImage(FeedId + ".png", true);
                        }
                        if (FeedIcon == null)
                        {
                            FeedIcon = ImageSource.FromResource("NewsScroll.Assets.iconRSS-Dark.png");
                        }

                        //Add feed to list
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            try
                            {
                                AddList.Add(new Feeds()
                                {
                                    feed_id = FeedId, feed_title = Feed.feed_title, feed_icon = FeedIcon, feed_link = Feed.feed_link, feed_folder_title = FeedFolder, feed_ignore_status = IgnoreStatus
                                });
                            }
                            catch { }
                        });
                    }

                    //Update the added item count
                    AppVariables.CurrentFeedsLoaded++;

                    //Request information update
                    if (AppVariables.CurrentFeedsLoaded == 1)
                    {
                        EventHideProgressionStatus();
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed processing multiple feeds from database: " + ex.Message);
                return(false);
            }
        }
Exemplo n.º 17
0
        //Clear Database Thread
        async Task ClearDatabase()
        {
            ProgressDisableUI("Clearing stored items...");
            try
            {
                //Reset the online status
                OnlineUpdateFeeds   = true;
                OnlineUpdateNews    = true;
                OnlineUpdateStarred = true;
                ApiMessageError     = string.Empty;

                //Reset the last update setting
                await AppSettingSave("LastItemsUpdate", "Never");

                await ClearObservableCollection(List_Feeds);
                await ClearObservableCollection(List_FeedSelect);
                await ClearObservableCollection(List_NewsItems);
                await ClearObservableCollection(List_SearchItems);
                await ClearObservableCollection(List_StarredItems);

                await vSQLConnection.DeleteAllAsync <TableFeeds>();

                await vSQLConnection.DropTableAsync <TableFeeds>();

                await vSQLConnection.CreateTableAsync <TableFeeds>();

                await vSQLConnection.DeleteAllAsync <TableOffline>();

                await vSQLConnection.DropTableAsync <TableOffline>();

                await vSQLConnection.CreateTableAsync <TableOffline>();

                await vSQLConnection.DeleteAllAsync <TableItems>();

                await vSQLConnection.DropTableAsync <TableItems>();

                await vSQLConnection.CreateTableAsync <TableItems>();

                await vSQLConnection.DeleteAllAsync <TableSearchHistory>();

                await vSQLConnection.DropTableAsync <TableSearchHistory>();

                await vSQLConnection.CreateTableAsync <TableSearchHistory>();

                //Delete all feed icons from local storage
                foreach (string localFile in AVFiles.Directory_ListFiles(string.Empty, true))
                {
                    try
                    {
                        if (localFile.EndsWith(".png"))
                        {
                            AVFiles.File_Delete(localFile, false);
                        }
                    }
                    catch { }
                }

                //Load and set database size
                await UpdateSizeInformation();
            }
            catch { }
            ProgressEnableUI();
        }
Exemplo n.º 18
0
        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 { }
        }