public MainForm(IFormOpener formManager, IMainFormPresenter presenter, MainFormStyler mainFormStyler, IPubSub pubsub, IPropertiesRepository propertiesRepository)
        {
            InitializeComponent();

            _mainFormStyler = mainFormStyler;
            _pubsub         = pubsub;
            RenderTheme();
            if (propertiesRepository.GetValue <bool>(Constants.AppProperties.UpdateSettings))
            {
                propertiesRepository.Upgrade();
                propertiesRepository.SetValue(Constants.AppProperties.UpdateSettings, false);
                propertiesRepository.Save();
            }

            _formManager = formManager;
            presenter.InitializePresenter(new
            {
                MainForm = this,
                PubSub   = _pubsub
            });

            var selectedPath = propertiesRepository.GetValue <string>(Constants.AppProperties.SelectedPath);

            if (!string.IsNullOrEmpty(selectedPath))
            {
                Presenter.PopulateTreeView(selectedPath);
            }

            _propertiesRepository = propertiesRepository;
        }
        public void SavePreferences(AppPreferences preferences)
        {
            if (!_propertiesRepository.GetValue <string>(Constants.AppProperties.TransactionCachePath).Equals(preferences.TransactionCacheLocation, System.StringComparison.InvariantCultureIgnoreCase))
            {
                _propertiesRepository.SetValue(Constants.AppProperties.TransactionCachePath, preferences.TransactionCacheLocation);
                _propertiesRepository.Save();
                _mainFormPresenter.InitializeTransactionCache();
            }

            if (_propertiesRepository.GetValue <bool>(Constants.AppProperties.UseDarkTheme) != preferences.UseDarkTheme)
            {
                _propertiesRepository.SetValue(Constants.AppProperties.UseDarkTheme, preferences.UseDarkTheme);
                _propertiesRepository.Save();
                _pubsub.Publish(this, new PubSubEventArgs {
                    Data = preferences.UseDarkTheme
                }, Constants.SubscriptionTypes.THEME_CHANGE);
                _view.RenderTheme();
            }
        }
Beispiel #3
0
        public void InitializeTransactionCache()
        {
            // The folder for the roaming current user
            var folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            // Combine the base folder with your specific folder....
            AppReferences.AppDataFolder = Path.Combine(folder, "CosmosManager");
            Directory.CreateDirectory(AppReferences.AppDataFolder);

            var appPath = Path.Combine(folder, "CosmosManager/TransactionCache");

            if (!string.IsNullOrEmpty(_propertiesRepository.GetValue <string>(Constants.AppProperties.TransactionCachePath)))
            {
                appPath = _propertiesRepository.GetValue <string>(Constants.AppProperties.TransactionCachePath);
            }
            AppReferences.TransactionCacheDataFolder = appPath;
            Directory.CreateDirectory(AppReferences.TransactionCacheDataFolder);

            var size = CalculateFolderSize(AppReferences.TransactionCacheDataFolder);

            _view.SetTransactionCacheLabel($"Transaction Cache: {BytesToSting(size)}");
            _view.SetFileWatcherPath(AppReferences.TransactionCacheDataFolder);
        }