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); } }
//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); } }
//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 { } }
//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 { } }
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); } }
//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(); }