private void GetData() { NTSTATUS status = FileMethods.Imports.NtQueryDirectoryFile( FileHandle: _directory, Event: IntPtr.Zero, ApcRoutine: null, ApcContext: IntPtr.Zero, IoStatusBlock: out IO_STATUS_BLOCK statusBlock, FileInformation: _buffer.VoidPointer, Length: (uint)_buffer.ByteCapacity, FileInformationClass: FileInformationClass.FileFullDirectoryInformation, ReturnSingleEntry: false, FileName: null, RestartScan: false); switch (status) { case NTSTATUS.STATUS_NO_MORE_FILES: NoMoreFiles(); return; case NTSTATUS.STATUS_SUCCESS: Debug.Assert(statusBlock.Information.ToInt64() != 0); break; default: throw ErrorMethods.GetIoExceptionForNTStatus(status); } }
private async void CM_Delete_Click(object sender, RoutedEventArgs e) { try { string text = "Are you sure you would like to delete " + view_DataGridView.SelectedItems.Count + " show" + (view_DataGridView.SelectedItems.Count == 1 ? "" : "s") + "?"; if (MessageBox.Show(text, "Confirm deletion", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { List <Show> toDelete = view_DataGridView.SelectedItems.Cast <Show>().ToList(); foreach (Show show in toDelete) { SeriesResult <Show> result = await AppGlobal.Db.UserShowDeleteAsync(show.UserShowID); if (result.Result == SQLResult.Success) { AppGlobal.User.Shows.Remove(show); AppGlobal.Settings.RemoveSeriesPath(show.Id); AppGlobal.Settings.Save(); } else { MessageBox.Show("Something went wrong!\n\n" + result.Message); } } MyViewModel.RefreshView(); } } catch (Exception ex) { ErrorMethods.LogError(ex.Message); } }
/// <summary> /// Get the ids for all processes that have a handle to this file system object. /// Does not include the current process. /// </summary> public unsafe static IEnumerable <UIntPtr> GetProcessIds(SafeFileHandle fileHandle) { return(BufferHelper.BufferInvoke((HeapBuffer buffer) => { NTSTATUS status = NTSTATUS.STATUS_INFO_LENGTH_MISMATCH; while (status == NTSTATUS.STATUS_INFO_LENGTH_MISMATCH) { status = Imports.NtQueryInformationFile(fileHandle, out IO_STATUS_BLOCK statusBlock, buffer.VoidPointer, (uint)buffer.ByteCapacity, FileInformationClass.FileProcessIdsUsingFileInformation); switch (status) { case NTSTATUS.STATUS_SUCCESS: break; case NTSTATUS.STATUS_INFO_LENGTH_MISMATCH: // Not a big enough buffer buffer.EnsureByteCapacity((ulong)statusBlock.Information); break; default: throw ErrorMethods.GetIoExceptionForNTStatus(status); } } return ((FILE_PROCESS_IDS_USING_FILE_INFORMATION *)buffer.VoidPointer)->ProcessIdList.ToArray(); })); }
private void Btn_WatchEpisode_Click(object sender, RoutedEventArgs e) { bool found = false; try { if (string.IsNullOrEmpty(MyViewModel.MyShow.LocalSeriesPath)) { return; } if (!Directory.Exists(MyViewModel.MyShow.LocalSeriesPath)) { return; } Button m = (Button)sender; Panel p = (m.Parent as Panel).Parent as Panel; int episodeNumber = int.Parse(p.Tag.ToString()); string seasonPath = Path.Combine(MyViewModel.MyShow.LocalSeriesPath, "Season " + MyViewModel.ViewingSeason); var dir = new DirectoryInfo(seasonPath); if (!dir.Exists) { return; } var files = dir.GetFiles(); Episode episode = MyViewModel.MyShow.GetEpisode(MyViewModel.ViewingSeason, episodeNumber); foreach (FileInfo file in files) { if (file.Name.Contains(episode.FullEpisodeString)) { found = true; var q = CommonMethods.StartProcess(file.FullName); // Testing //q.EnableRaisingEvents = true; //q.Exited += delegate //{ // TimeSpan watchTime = DateTime.Now - q.StartTime; // MessageBox.Show("You watched for " + watchTime.TotalSeconds + " seconds"); //}; break; } } } catch (Exception ex) { ErrorMethods.LogError(ex.Message); } if (!found) { MessageBox.Show("Failed to locate episode on local drive.", "Episode not found"); } }
private async void Btn_EpisodeEyeToggle_Click(object sender, RoutedEventArgs e) { try { if (busy) { return; } busy = true; ToggleButton m = (ToggleButton)sender; Grid p = m.Parent as Grid; m.IsHitTestVisible = false; int episode = int.Parse(p.Tag.ToString()); await EpisodeWatchedToggle(episode); m.IsHitTestVisible = true; busy = false; } catch (Exception ex) { ErrorMethods.LogError(ex.Message); } }
private async void CM_DownloadLastEpisode_Click(object sender, RoutedEventArgs e) { try { if (MyViewModel.IsBusy) { return; } Show show = view_DataGridView.SelectedItem as Show; MyViewModel.SetStatus($"Finding magnets for {show.SeriesName} {show.LatestEpisode.FullEpisodeString}"); var torrents = await MethodCollection.GetEpisodeTorrentList(show, show.LatestEpisode); if (torrents == null || torrents.Count == 0) { PopupNotification($"Failed to find last episode for {show.SeriesName}"); MyViewModel.ResetStatus(); return; } await DialogHost.Show(new EpisodeDownloadsDialog(torrents), "RootDialog"); MyViewModel.ResetStatus(); } catch (Exception ex) { ErrorMethods.LogError(ex.Message); } }
public JsonResult GetPost(int id) { var post = GetMethods.GetPost(id); if (post == null) { var err = ErrorMethods.Handle404(); JsonConvert.SerializeObject(err); return(new JsonResult { Data = err, JsonRequestBehavior = JsonRequestBehavior.AllowGet, ContentType = "application/json" }); } var jsonResult = new JsonResult { Data = post, JsonRequestBehavior = JsonRequestBehavior.AllowGet, ContentType = "application/json" }; return(jsonResult); }
public SeriesResult <Category> UserShowCategoryAdd(int UserShowID, Category record) { try { connection.Open(); cmd = CreateSqlCommandForSP("UserShowCategoryAdd"); cmd.Parameters.AddWithValue("UserShowID", UserShowID); cmd.Parameters.AddWithValue("CategoryID", record.CategoryID); cmd.Parameters.Add("ID", SqlDbType.Int).Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); record.UserShowCategoryID = int.Parse(cmd.Parameters["ID"].Value.ToString()); return(new SeriesResult <Category> { Result = SQLResult.Success, Data = record }); } catch (Exception e) { ErrorMethods.LogError(e.Message); return(new SeriesResult <Category> { Result = SQLResult.ErrorHasOccured, Message = e.Message }); } finally { connection.Close(); } }
public SeriesResult <User> UserUpdate(User UserData) { try { connection.Open(); cmd = CreateSqlCommandForSP("UserUpdate"); cmd.Parameters.AddWithValue("UserID", UserData.UserID); cmd.Parameters.AddWithValue("Name", UserData.FirstName); cmd.Parameters.AddWithValue("Surname", UserData.LastName); cmd.Parameters.AddWithValue("Password", sha256(UserData.Password)); cmd.Parameters.AddWithValue("DoB", UserData.DateOfBirth); int r = cmd.ExecuteNonQuery(); return(new SeriesResult <User> { Result = SQLResult.Success }); } catch (Exception e) { ErrorMethods.LogError(e.Message); return(new SeriesResult <User> { Result = SQLResult.ErrorHasOccured, Message = e.Message }); } finally { connection.Close(); } }
public SeriesResult <UserShowWatch> UserShowWatchDelete(UserShowWatch record) { try { connection.Open(); cmd = CreateSqlCommandForSP("UserShowWatchDelete"); cmd.Parameters.AddWithValue("UserShowWatchID", record.ID); cmd.ExecuteNonQuery(); return(new SeriesResult <UserShowWatch> { Result = SQLResult.Success, Data = record }); } catch (Exception e) { ErrorMethods.LogError(e.Message); return(new SeriesResult <UserShowWatch> { Result = SQLResult.ErrorHasOccured, Message = e.Message }); } finally { connection.Close(); } }
public SeriesResult <Category> UserCategoryDeleteMutliple(List <Category> records) { try { connection.Open(); cmd = CreateSqlCommandForSP("UserCategoryDelete"); foreach (Category record in records) { cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("UserID", AppGlobal.User.UserID); cmd.Parameters.AddWithValue("CategoryID", record.CategoryID); cmd.ExecuteNonQuery(); } return(new SeriesResult <Category> { Result = SQLResult.Success }); } catch (Exception ex) { ErrorMethods.LogError(ex.Message); return(new SeriesResult <Category> { Result = SQLResult.ErrorHasOccured, Message = ex.Message }); } finally { connection.Close(); } }
public SeriesResult <Show> UserShowUpdate(Show record) { try { connection.Open(); cmd = CreateSqlCommandForSP("UserShowUpdate"); cmd.Parameters.AddWithValue("UserID", AppGlobal.User.UserID); cmd.Parameters.AddWithValue("TvdbID", record.Id); int r = cmd.ExecuteNonQuery(); return(new SeriesResult <Show> { Result = SQLResult.Success }); } catch (Exception e) { ErrorMethods.LogError(e.Message); return(new SeriesResult <Show> { Result = SQLResult.ErrorHasOccured, Message = e.Message }); } finally { connection.Close(); } }
public SeriesResult <User> UserDelete() { try { connection.Open(); cmd = CreateSqlCommandForSP("UserDelete"); cmd.Parameters.AddWithValue("UserID", AppGlobal.User.UserID.ToString()); cmd.ExecuteNonQuery(); return(new SeriesResult <User> { Result = SQLResult.Success }); } catch (Exception ex) { ErrorMethods.LogError(ex.Message); return(new SeriesResult <User> { Result = SQLResult.ErrorHasOccured, Message = ex.Message }); } finally { connection.Close(); } }
public SeriesResult <Category> UserShowCategoryDelete(int UserShowCategoryID) { try { connection.Open(); cmd = CreateSqlCommandForSP("UserShowCategoryDelete"); cmd.Parameters.AddWithValue("UserShowCategoryID", UserShowCategoryID); cmd.ExecuteNonQuery(); return(new SeriesResult <Category> { Result = SQLResult.Success }); } catch (Exception e) { ErrorMethods.LogError(e.Message); return(new SeriesResult <Category> { Result = SQLResult.ErrorHasOccured, Message = e.Message }); } finally { connection.Close(); } }
/// <summary> /// Enumerates rights explicitly given to the specified SID. If the given SID /// doesn't have any directly applied rights, returns an empty collection. /// </summary> public static IEnumerable <string> LsaEnumerateAccountRights(LsaHandle policyHandle, ref SID sid) { NTSTATUS status = Imports.LsaEnumerateAccountRights(policyHandle, ref sid, out var rightsBuffer, out uint rightsCount); switch (status) { case NTSTATUS.STATUS_OBJECT_NAME_NOT_FOUND: return(Enumerable.Empty <string>()); case NTSTATUS.STATUS_SUCCESS: break; default: throw ErrorMethods.GetIoExceptionForNTStatus(status); } List <string> rights = new List <string>(); Reader reader = new Reader(rightsBuffer); for (int i = 0; i < rightsCount; i++) { rights.Add(reader.ReadUNICODE_STRING()); } return(rights); }
private async Task CheckForMissingLocalData() { MyViewModel.SetStatus("Verifying local data"); try { List <Show> missingShows = new List <Show>(); foreach (Show show in AppGlobal.User.Shows) { string tvdbPath = Path.Combine(AppGlobal.Paths.SeriesDirectory, show.Id.ToString()); if (!Directory.Exists(tvdbPath) || !File.Exists(show.LocalJsonPath)) { missingShows.Add(show); } } if (missingShows.Count > 0) { int counter = 1; foreach (Show show in missingShows) { MyViewModel.SetStatus($"Downloading data {counter++}/{missingShows.Count} - {show.SeriesName}"); await MethodCollection.RetrieveTvdbDataForSeriesAsync(show.Id); } } } catch (Exception ex) { ErrorMethods.LogError(ex.Message); } }
public JsonResult PostUserCreatePost(string title, string content) { var user = ActionContext.Request.Headers.Authorization.Parameter; var userInfo = GetMethods.GetUserInformationByBase64(user); var res = CreateNewPost(userInfo.UserId, title, content); if (res == 1) { return new JsonResult { Data = new{ status = "successful" } } } ; var err = ErrorMethods.Handle500(); JsonConvert.SerializeObject(err); return(new JsonResult { Data = err, JsonRequestBehavior = JsonRequestBehavior.AllowGet, ContentType = "application/json" }); }
private async Task SetupStructure() { MyViewModel.SetStatus("Setting up Structure"); try { // Check local series folder directory if (!string.IsNullOrEmpty(AppGlobal.Paths.LocalSeriesDirectory) && !Directory.Exists(AppGlobal.Paths.LocalSeriesDirectory)) { MessageBox.Show($"Series path '{AppGlobal.Paths.LocalSeriesDirectory}' does not exist or cannot be read. Please set a new path."); AppGlobal.Settings.LocalSeriesFolder = ""; AppGlobal.Settings.Save(); } // Check for files if (!File.Exists(AppGlobal.Paths.EztvIDFile) || DateTime.Now > Properties.Settings.Default.EztvLastUpdate.AddDays(7)) { MyViewModel.SetStatus("Updating Eztv data"); await MethodCollection.UpdateEztvShowFileAsync(); Properties.Settings.Default.EztvLastUpdate = DateTime.Now; Properties.Settings.Default.Save(); } } catch (Exception ex) { ErrorMethods.LogError(ex.Message); } }
private async Task Startup() { try { LoadWindowSettings(); SetupTrayIcon(); SetupShortcuts(); SetupNetChange(); //SetupShowTimer(); await Task.Delay(1000); await SetupTvdbAPI(); await SetupStructure(); await CheckForMissingLocalData(); LoadSeries(); MyViewModel.RefreshView(); SortDataGrid(AppGlobal.Settings.DefaultSortColumn, AppGlobal.Settings.DefaultSortDirection); //if (await CheckForShowUpdates()) // MyViewModel.RefreshView(); MyViewModel.ResetStatus(); } catch (Exception ex) { ErrorMethods.LogError(ex.Message); } }
public void DoWriteFirmannummer() { try { using (var db = new SteinbachEntities()) { var query = from f in db.firmen where f.istFirma == 1 select new { f.KdNr, f.name }; foreach (var item in query) { var project = from p in db.projekte where p.firmenname == item.name select p; foreach (var pro in project) { pro.FirmenNr = item.KdNr; } } db.SaveChanges(); } } catch (Exception ex) { System.Windows.MessageBox.Show(ErrorMethods.GetExceptionMessageInfo(ex)); } }
public SeriesResult <Category> UserCategoryAddMultiple(List <Category> records) { try { connection.Open(); cmd = CreateSqlCommandForSP("UserCategoryAdd"); foreach (Category record in records) { cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("UserID", AppGlobal.User.UserID); cmd.Parameters.AddWithValue("Category", record.Name); cmd.Parameters.Add("ID", SqlDbType.Int).Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); record.CategoryID = int.Parse(cmd.Parameters["ID"].Value.ToString()); } return(new SeriesResult <Category> { Result = SQLResult.Success, ListData = records }); } catch (Exception e) { ErrorMethods.LogError(e.Message); return(new SeriesResult <Category> { Result = SQLResult.ErrorHasOccured, Message = e.Message }); } finally { connection.Close(); } }
private async Task LoadBannerAsync() { try { Models.Image banner = MyViewModel.MyShow.Banners.First(); if (!File.Exists(MyViewModel.MyShow.LocalBannerPath) && !File.Exists(banner.LocalImagePath)) { using (WebClient client = new WebClient()) { await client.DownloadFileTaskAsync(new Uri(banner.OnlineImageUrl), banner.LocalImagePath); } if (File.Exists(MyViewModel.MyShow.LocalBannerPath)) { File.Delete(MyViewModel.MyShow.LocalBannerPath); } File.Copy(banner.LocalImagePath, MyViewModel.MyShow.LocalBannerPath); MyViewModel.RefreshBanner(); } } catch (Exception ex) { ErrorMethods.LogError(ex.Message); } }
static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam) { switch (message) { case WindowMessage.Size: cxBlock = lParam.LowWord / DIVISIONS; cyBlock = lParam.HighWord / DIVISIONS; return(0); case WindowMessage.LeftButtonDown: int x = lParam.LowWord / cxBlock; int y = lParam.HighWord / cyBlock; if (x < DIVISIONS && y < DIVISIONS) { fState[x, y] ^= true; RECT rect = new RECT { left = x * cxBlock, top = y * cyBlock, right = (x + 1) * cxBlock, bottom = (y + 1) * cyBlock }; window.InvalidateRectangle(rect, false); } else { ErrorMethods.MessageBeep(0); } return(0); case WindowMessage.Paint: using (DeviceContext dc = window.BeginPaint()) { for (x = 0; x < DIVISIONS; x++) { for (y = 0; y < DIVISIONS; y++) { dc.Rectangle(x * cxBlock, y * cyBlock, (x + 1) * cxBlock, (y + 1) * cyBlock); if (fState[x, y]) { dc.MoveTo(x * cxBlock, y * cyBlock); dc.LineTo((x + 1) * cxBlock, (y + 1) * cyBlock); dc.MoveTo(x * cxBlock, (y + 1) * cyBlock); dc.LineTo((x + 1) * cxBlock, y * cyBlock); } } } } return(0); case WindowMessage.Destroy: Windows.PostQuitMessage(0); return(0); } return(Windows.DefaultWindowProcedure(window, message, wParam, lParam)); }
public void Dispose() { if (_restoreOldMode) { _restoreOldMode = false; ErrorMethods.SetThreadErrorMode(_oldMode); } }
private async void Btn_Search_Click(object sender, RoutedEventArgs e) { if (busySearching) { return; } string searchString = txt_Search.Text; if (string.IsNullOrWhiteSpace(searchString)) { txt_Search.Focus(); SystemSounds.Beep.Play(); return; } try { busySearching = true; MyViewModel.SearchResults.Clear(); btn_Accept.IsEnabled = false; MyViewModel.SetStatus("Searching...", Brushes.Yellow); string url = $"https://api.thetvdb.com/search/series?name={Uri.EscapeUriString(searchString)}"; ReturnResult <TvdbAPI> jsonData = await Request.ExecuteAndDeserializeAsync <TvdbAPI>("GET", url); if (jsonData.Result.Error == null) { List <Show> results = JsonConvert.DeserializeObject <List <Show> >(jsonData.Result.Data.ToString()) .Where(x => !x.SeriesName.Contains("Series Not Permitted")) .ToList(); results.ForEach(s => s.SetupVariables()); // TODO FIX //MyViewModel.SearchResults.AddRange(results.OrderByDescending(x => x.YearDisplay == "Unknown" ? "1" : x.YearDisplay).ThenBy(x => x.SeriesName)); MyViewModel.SetStatus($"{MyViewModel.SearchResults.Count} results found", Brushes.LimeGreen); } else { txt_Search.Focus(); txt_Search.SelectAll(); MyViewModel.SetStatus("No results found", Brushes.Red); } SystemSounds.Beep.Play(); busySearching = false; } catch (Exception ex) { ErrorMethods.LogError(ex.Message); } }
public static void LsaFreeMemory(IntPtr handle) { NTSTATUS status = Imports.LsaFreeMemory(handle); if (status != NTSTATUS.STATUS_SUCCESS) { throw ErrorMethods.GetIoExceptionForNTStatus(status); } }
private TemporaryErrorMode(ErrorMode modesToEnable) { _oldMode = ErrorMethods.GetThreadErrorMode(); if ((_oldMode & modesToEnable) != modesToEnable) { _oldMode = ErrorMethods.SetThreadErrorMode(_oldMode | modesToEnable); _restoreOldMode = true; } }
public LoginResult UserLogin(string UsernameOrEmail, string Password) { try { connection.Open(); cmd = CreateSqlCommandForSP("UserLogin"); cmd.Parameters.AddWithValue("Email", UsernameOrEmail); cmd.Parameters.AddWithValue("Password", sha256(Password)); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Read(); DateTime?DoB = null; if (!string.IsNullOrEmpty(reader["DateOfBirth"].ToString())) { DoB = DateTime.Parse(reader["DateOfBirth"].ToString()); } User data = new User { UserID = int.Parse(reader["UserID"].ToString()), Username = reader["Username"].ToString(), FirstName = reader["Name"].ToString(), LastName = reader["Surname"].ToString(), Email = reader["Email"].ToString(), Password = Password, DateOfBirth = DoB }; reader.Close(); return(new LoginResult { Result = SQLResult.LoginSuccessful, UserData = data }); } else { return(new LoginResult { Result = SQLResult.BadLogin }); } } catch (Exception ex) { ErrorMethods.LogError(ex.Message); return(new LoginResult { Result = SQLResult.ErrorHasOccured, Message = ex.Message }); } finally { connection.Close(); } }
public static unsafe void ToUpperInvariant(ref UNICODE_STRING value) { NTSTATUS status = Imports.RtlUpcaseUnicodeString( (UNICODE_STRING *)Structs.AddressOf(ref value), (UNICODE_STRING *)Structs.AddressOf(ref value), false); if (!ErrorMacros.NT_SUCCESS(status)) { ErrorMethods.GetIoExceptionForNTStatus(status); } }
/// <summary> /// Get the access rights applied to the given file handle. /// </summary> public unsafe static FileAccessRights GetRights(SafeFileHandle fileHandle) { FILE_ACCESS_INFORMATION access = new FILE_ACCESS_INFORMATION(); NTSTATUS result = Imports.NtQueryInformationFile(fileHandle, out _, &access, (uint)sizeof(FILE_ACCESS_INFORMATION), FileInformationClass.FileAccessInformation); if (result != NTSTATUS.STATUS_SUCCESS) { throw ErrorMethods.GetIoExceptionForNTStatus(result); } return(access.AccessFlags); }