Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        public LauncherDatabase()
        {
            AppDataPath = Path.Combine(LauncherHelper.GetAppDataPath(), APP_DATA_FILENAME);

            LauncherDataWrapper wrapper;

            if (File.Exists(AppDataPath))
            {
                var jsonData = File.ReadAllText(AppDataPath);
                wrapper = JsonConvert.DeserializeObject <LauncherDataWrapper>(jsonData);
            }
            else
            {
                wrapper = new LauncherDataWrapper();
            }

            _applicationsData = wrapper.ApplicationsData.ToList();
            _sessionsData     = wrapper.SessionsData.ToList();
        }