/// <summary> /// Saves current profile to file /// </summary> public void SaveProfile(bool log = true) { try { IsNameValid(Name); IsUnpackDirectoryValid(UnpackDirectory); IsWorkingDirectoryValid(WorkingDirectory); IsKeyValid(BitConverter.ToString(IndexKey), "IndexKey"); IsKeyValid(BitConverter.ToString(PackKey), "PackKey"); if (HasErrors) { UserInput.ShowMessage("INVALID_PROFILE_SETTINGS"); return; } _profile.Save(); if (log) { WindowLog.Information("PROFILE_SAVED", null, Name); } } catch (ProfileNameAlreadyExistsException e) { Name = _profile.OriginalName; UserInput.ShowMessage("PROFILE_NAME_ALREADY_EXISTS"); } catch (IOException e) { WindowLog.Error("COULD_NOT_ACCESS_FILE", String.Format("{0}{1}.xml", ConstantsBase.ProfilesPath, Name), e.Message); } }
public static bool QueryLID(ref ulong id, string query) { MySqlCommand cmd = new MySqlCommand(query, connection); MySqlDataReader reader = null; try { reader = cmd.ExecuteReader(); id = (ulong)reader.FieldCount; // Maybe not the best to use, but should do the trick } catch (MySqlException ex) { WindowLog.Error("Database", "MySQL Error: " + ex.Message); return(false); } finally { if (reader != null) { reader.Close(); } } return(true); }
private async void InitializeVersionService() { // Handle New version found AppUpdater.CheckVersionsCompleted += (sender, args) => { if (args.AskToDownloadHandled || args.TargetSubscriberType != null) { return; } if (args.HasNewVersionAvailable) { ViewManager.ShowWindow <UpdateMenuView>(); UpdateMenuString = "There's an update available!"; } args.AskToDownloadHandled = true; }; // Check for new versions try { await AppUpdater.CheckVersions(); } catch (WebException ex) { WindowLog.Error("SERVER_DOWN", "App"); } }
/// <summary> /// Starts monitoring the working directory /// </summary> public void StartMonitoringDirectory() { try { _fsw.Path = MainWindowVm.Instance.SelectedWorkingProfile.WorkingDirectory; _fsw.EnableRaisingEvents = true; } catch (ArgumentException ex) { WindowLog.Error("COULD_NOT_MONITOR_DIR", null, MainWindowVm.Instance.SelectedWorkingProfile.WorkingDirectory); } }
/// <summary> /// Processes profile's Working directory /// </summary> public void ProcessWorkingDirectory() { // Return if null or no profile is selected if (MainWindowVm.Instance == null || MainWindowVm.Instance.SelectedWorkingProfile == null) { return; } WorkingItemsList.Clear(); try { // Loop through all files foreach (var item in IOHelper.GetAllFilesFromDir(MainWindowVm.Instance.SelectedWorkingProfile.WorkingDirectory) .Where(t => String.Equals(t.Extension, MainWindowVm.Instance.SelectedWorkingProfile.IndexExtension, StringComparison.CurrentCultureIgnoreCase)) .Select(file => new WorkingItemVm(Path.GetFileNameWithoutExtension(file.Name), file.Name, file.FullName, file.DirectoryName))) { // Add it to the list AddItemToWorkingList(item); } } catch (DirectoryNotFoundException ex) { WindowLog.Error("DIR_NOT_FOUND", null, MainWindowVm.Instance.SelectedWorkingProfile.WorkingDirectory); } try { // Loop through all the directories (since there may be files which are unpacked but not existing in the pack dir) foreach (var item in IOHelper.GetAllFirstDirectories(MainWindowVm.Instance.SelectedWorkingProfile.UnpackDirectory)) { if (WorkingItemsList.FirstOrDefault(x => String.Equals(x.DisplayName, item.Name, StringComparison.CurrentCultureIgnoreCase)) == null) { AddItemToWorkingList(new WorkingItemVm( item.Name, item.Name + MainWindowVm.Instance.SelectedWorkingProfile.IndexExtension, item.FullName + MainWindowVm.Instance.SelectedWorkingProfile.IndexExtension, item.FullName)); } } } catch (DirectoryNotFoundException ex) { WindowLog.Error("DIR_NOT_FOUND", null, MainWindowVm.Instance.SelectedWorkingProfile.UnpackDirectory); } WorkingItemsList = new ObservableImmutableList <WorkingItemVm>(WorkingItemsList.OrderBy(x => x.DisplayName)); }
public static bool Query(ref MySqlDataReader res, string query) { MySqlCommand cmd = new MySqlCommand(query, connection); try { res = cmd.ExecuteReader(); } catch (MySqlException ex) { WindowLog.Error("Database", "MySQL Error: " + ex.Message); return(false); } return(true); }
public static bool Init() { string connStr = String.Format("server={0};user id={1}; password={2}; database=eve-node; pooling=false", "localhost", "Almamu", "966772320"); try { connection = new MySqlConnection(connStr); connection.Open(); } catch (MySqlException) { WindowLog.Error("Database", "Cannot connect to server database"); return(false); } return(true); }
public static bool Query(string query) { MySqlCommand cmd = new MySqlCommand(query, connection); MySqlDataReader reader = null; try { reader = cmd.ExecuteReader(); } catch (MySqlException ex) { WindowLog.Error("Database", "MySQL Error: " + ex.Message); return(false); } finally { if (reader != null) { reader.Close(); } } return(true); }
/// <summary> /// Action performed when Pack file is hit /// </summary> /// <param name="param"></param> private async void PackFileAction(object param) { if (SelectedFilter < 0) { UserInput.ShowMessage("USER_SELECT_PACK_TYPE"); return; } QueueActionType = ActionType.Pack; if (!IsItemReady()) { return; } FilesActionVm.Instance.CcFiles++; SetItemState(State.Packing | State.LongAction); //await Task.Delay(1000); //this.SetItemState(State.Ready); //WorkingListVM.Instance.ProcessQueueUponActionFinalization(this); //return; HashMismatchFiles.Clear(); ErrorList.Clear(); _successCounter = 0; var filesInDir = IOHelper.GetAllFilesFromDir(String.Format("{0}{1}", MainWindowVm.Instance.SelectedWorkingProfile.UnpackDirectory, DisplayName)); var indexItems = new List <IndexItem>(); string indexFilePath = String.Format("{0}{1}", MainWindowVm.Instance.SelectedWorkingProfile.WorkingDirectory, String.Format("{0}{1}", DisplayName, MainWindowVm.Instance.SelectedWorkingProfile.IndexExtension)); string packFilePath = String.Format("{0}{1}", MainWindowVm.Instance.SelectedWorkingProfile.WorkingDirectory, String.Format("{0}{1}", DisplayName, MainWindowVm.Instance.SelectedWorkingProfile.PackExtension)); if (File.Exists(packFilePath)) { // File already packed, but will be overwritten WindowLog.Warning("FILE_ALREADY_PACKED_BUT_OVER", Filename); File.Delete(packFilePath); } if (File.Exists(indexFilePath)) { File.Delete(EterHelper.ReplaceWithEpkExt(indexFilePath)); } await Task.Run(() => { int counter = 0; foreach (var file in filesInDir) { //int type = -1; //string fileExtension = Path.GetExtension(file.FullName); //if (SelectedFilter.RawExtensions != null) //{ // foreach (var rawExt in SelectedFilter.RawExtensions) // if (rawExt.ToLower() == fileExtension.ToLower()) // type = 0; // foreach (var lzoExt in SelectedFilter.LzoExtensions) // if (lzoExt.ToLower() == fileExtension.ToLower()) // type = 1; // foreach (var xteaExt in SelectedFilter.XteaExtensions) // if (xteaExt.ToLower() == fileExtension.ToLower()) // type = 2; //} //if (type == -1) // type = SelectedFilter.NotIncludedExtensionsType; string toReplaceStr = String.Format("{0}{1}", MainWindowVm.Instance.SelectedWorkingProfile.UnpackDirectory, DisplayName).Replace("/", "\\"); string fileName = file.FullName.Substring(file.FullName.IndexOf(toReplaceStr) + toReplaceStr.Length + 1); indexItems.Add(new IndexItem( counter, fileName, null, 0, 0, null, 0, SelectedFilter, DisplayName)); counter++; } double lastProgressValue = 0; try { EterFilesDal.BuildIndexAndPackFiles( indexItems, packFilePath, String.Format("{0}{1}\\", MainWindowVm.Instance.SelectedWorkingProfile.UnpackDirectory, DisplayName), MainWindowVm.Instance.SelectedWorkingProfile.IndexKey, MainWindowVm.Instance.SelectedWorkingProfile.PackKey, (error) => { if (error != null) { ErrorList.Add(error); } }, (result, progress) => { if (result == 0) { _successCounter++; } if (((progress - lastProgressValue) >= 5)) { ActionProgress = progress; lastProgressValue = progress; } }, () => SetItemState(State.CriticalError)); } catch (OutOfMemoryException ex) { WindowLog.Warning("FILE_TOO_BIG", DisplayName); SetItemState(State.CriticalError); } catch (EterPackFileNotFoundException ex) { WindowLog.Error("ETER_EPK_FILE_NOT_FOUND", DisplayName); SetItemState(State.CriticalError); } catch (FileNotFoundException ex) { WindowLog.Error("FILE_NOT_FOUND", DisplayName, new object[] { ex.FileName }); SetItemState(State.CriticalError); } catch (UnauthorizedAccessException ex) { WindowLog.Error("COULD_NOT_ACCESS_FILE", DisplayName, DisplayName); SetItemState(State.CriticalError); } catch (System.IO.IOException ex) { WindowLog.Error("ERROR_WITH_CUSTOM_MSG", DisplayName, ex.Message); SetItemState(State.CriticalError); } }); SetItemState(ErrorList.Count > 0 ? State.ReadyWithErrors : State.Ready); ActionProgress = 100; WindowLog.Information("ETER_PACK_RESULT", DisplayName, new object[] { _successCounter, HashMismatchFiles.Count, ErrorList.Count }); AfterLongAction(param); }
/// <summary> /// Action performed when Unpack file is hit /// </summary> /// <param name="param"></param> private async void UnpackFileAction(object param) { QueueActionType = ActionType.Unpack; if (!IsItemReady()) { return; } FilesActionVm.Instance.CcFiles++; SetItemState(State.Unpacking | State.LongAction); await Task.Run(() => { // Set state to unpacking SetItemState(State.Unpacking); // Clear lists HashMismatchFiles.Clear(); ErrorList.Clear(); // Reset counters _successCounter = 0; double lastProgressValue = 0; try { // Unpack file EterFilesDal.UnpackFile( new FileInfo(EterHelper.ReplaceWithEpkExt(Path.Combine(MainWindowVm.Instance.SelectedWorkingProfile.WorkingDirectory, Filename))), MainWindowVm.Instance.SelectedWorkingProfile.UnpackDirectory, MainWindowVm.Instance.SelectedWorkingProfile.IndexKey, MainWindowVm.Instance.SelectedWorkingProfile.PackKey, (operationResult, globalProgress) => { if ((globalProgress - lastProgressValue) >= 5) { ActionProgress = globalProgress; lastProgressValue = globalProgress; } if (operationResult == 0) { _successCounter++; } }, (error, hash) => { if (error != null) { ErrorList.Add(error); } if (!String.IsNullOrWhiteSpace(hash)) { HashMismatchFiles.Add(hash); } }); } catch (ErrorReadingIndexException ex) { WindowLog.Error("ETER_WRONG_INDEX_KEY", DisplayName); SetItemState(State.CriticalError); } catch (OutOfMemoryException ex) { WindowLog.Warning("FILE_TOO_BIG", DisplayName); SetItemState(State.CriticalError); } catch (EterPackFileNotFoundException ex) { WindowLog.Error("ETER_EPK_FILE_NOT_FOUND", DisplayName); SetItemState(State.CriticalError); } catch (FileNotFoundException ex) { WindowLog.Error("FILE_NOT_FOUND", DisplayName, new object[] { ex.FileName }); SetItemState(State.CriticalError); } catch (UnauthorizedAccessException ex) { WindowLog.Error("COULD_NOT_ACCESS_FILE", DisplayName, DisplayName); SetItemState(State.CriticalError); } catch (System.IO.IOException ex) { WindowLog.Error("ERROR_WITH_CUSTOM_MSG", DisplayName, ex.Message); SetItemState(State.CriticalError); } }); // If any file produced an error, set state accordingly if (ErrorList.Count > 0 && ItemState != State.CriticalError) { SetItemState(State.ReadyWithErrors); } else if (ErrorList.Count == 0 && ItemState != State.CriticalError) { SetItemState(State.Ready); } // Make sure progress bar is at 100% ActionProgress = 100; // Logging stuff if (ItemState != State.CriticalError) { // Get all failed items int failedCount = ErrorList.Count; // Were any unnamed files present? var item = ErrorList.FirstOrDefault(x => x.ErrorMotive.Contains("(no name)")); // If so, add it if (item != null) { failedCount += Convert.ToInt32(item.Arg) - 1; } WindowLog.Information("ETER_UNPACK_RESULT", DisplayName, _successCounter, HashMismatchFiles.Count, failedCount); } AfterLongAction(param); }