/// <summary> /// Based on executable application path it creates application data and saves icon for application /// Application is also automaticaly selected as current /// </summary> /// <param name="applicationPath">Path to application user wants to add</param> public void AddNewApplication(string applicationPath) { var appData = new ApplicationRuntimeData { AppGUID = Guid.NewGuid(), AppName = Path.GetFileNameWithoutExtension(applicationPath), AppExecutablePath = applicationPath, }; using (var icon = Icon.ExtractAssociatedIcon(applicationPath)) { using (var bitmap = icon.ToBitmap()) { var iconPath = Path.Combine(LauncherHelper.GetAppIconsPath(), appData.AppGUID + ".png"); appData.AppIconPath = iconPath; using (var stream = new StreamWriter(iconPath)) { bitmap.Save(stream.BaseStream, System.Drawing.Imaging.ImageFormat.Png); stream.Close(); } } } ApplicationsData.Add(appData); SelectApplication(appData.AppGUID); _launcherDatabase.UpdateApplicationData(appData); }
/// <summary> /// Updates application data if exists and add if is new, saves it on drive /// </summary> /// <param name="applicationData">Application data to be updated</param> public void UpdateApplicationData(ApplicationRuntimeData applicationData) { var appData = _applicationsData.Find(x => x.AppGUID == applicationData.AppGUID); if (appData != null) { var index = _applicationsData.IndexOf(appData); _applicationsData[index] = new ApplicationSerializableData(applicationData); } else { _applicationsData.Add(new ApplicationSerializableData(applicationData)); } SaveAppData(); }
public void Test_SuperLaucher_ApplicationTest() { var app = new ApplicationSerializableData() { AppGUID = Guid.NewGuid(), AppExecutablePath = "path_exe", AppIconPath = "icon_path_exe", AppName = "name" }; var runtimeApp = new ApplicationRuntimeData(app); Assert.AreEqual(runtimeApp.AppGUID, app.AppGUID); Assert.AreEqual(runtimeApp.AppExecutablePath, app.AppExecutablePath); Assert.AreEqual(runtimeApp.AppIconPath, app.AppIconPath); Assert.AreEqual(runtimeApp.AppName, app.AppName); }
/// <summary> /// Creates database which loads data from saved files, prepares session and achievements /// Tries to select current application if there is any loaded /// </summary> /// <param name="dispatcher">Allows to start WPF connected code from different Thread on UI Thread</param> public SuperLauncher(Dispatcher dispatcher) { _dispatcher = dispatcher; _launcherDatabase = new LauncherDatabase(); AchievementsCheckers = new Dictionary <int, IAchievementChecker> { { 1, new FirstAchievementChecker() }, { 2, new SecondAchievementChecker() }, { 3, new ThirdAchievementChecker() }, { 4, new FourAchievementChecker() }, }; CurrentApplicationAchievements = new Dictionary <int, bool> { { 1, false }, { 2, false }, { 3, false }, { 4, false }, }; SessionsData = new ObservableCollection <SessionRuntimeData>(); CurrentApplicationData = new ApplicationRuntimeData(); ApplicationsData = new ObservableCollection <ApplicationRuntimeData>(); foreach (var applicationData in _launcherDatabase.ApplicationsData) { var runtimeData = new ApplicationRuntimeData(applicationData); ApplicationsData.Add(runtimeData); SelectApplication(runtimeData.AppGUID); } if (ApplicationsData.Count > 0) { SelectApplication(ApplicationsData[0].AppGUID); } }
/// <summary> /// Validate if all sessions have duration longer then 30 minutes /// </summary> /// <param name="applicationData">Current application data</param> /// <param name="sessionsData">Current application sessions</param> /// <returns>True if achievement is unlocked and false if it isn't</returns> public bool ValidateAchievement(ApplicationRuntimeData applicationData, List <SessionRuntimeData> sessionsData) { return(sessionsData.Sum(x => x.TotalDurationMinutes) >= 30); }
/// <summary> /// Validate if there is at least 5 sessions for application /// </summary> /// <param name="applicationData">Current application data</param> /// <param name="sessionsData">Current application sessions</param> /// <returns>True if achievement is unlocked and false if it isn't</returns> public bool ValidateAchievement(ApplicationRuntimeData applicationData, List <SessionRuntimeData> sessionsData) { return(sessionsData.Count >= 5); }