Example #1
0
 private static void OpenUrlIfPresent(string?url)
 {
     if (url != null)
     {
         HolzShotsPaths.OpenLink(url);
     }
 }
Example #2
0
        /// <summary> Can also be safely called for reloads. </summary>
        public async Task Load()
        {
            try
            {
                HolzShotsPaths.EnsureDirectory(_customUploadersDirectory);
                // var res = new Dictionary<UploaderMeta, CustomUploader>();

                var res   = ImmutableDictionary.CreateBuilder <UploaderMeta, CustomUploader>();
                var files = ImmutableDictionary.CreateBuilder <string, CustomUploaderSpec>();

                foreach (var jsonFile in Directory.EnumerateFiles(_customUploadersDirectory, HolzShotsPaths.CustomUploadersFilePattern))
                {
                    using var reader = File.OpenText(jsonFile);
                    var jsonStr = await reader.ReadToEndAsync().ConfigureAwait(false);

                    // TODO: Catch parsing errors
                    var uploader = JsonConvert.DeserializeObject <CustomUploaderSpec>(jsonStr, JsonConfig.JsonSettings);

                    // TODO: Aggregate errors of invalid files (and display them to the user)
                    Debug.Assert(uploader != null);

                    if (CustomUploader.TryLoad(uploader, out var loadedUploader))
                    {
                        Debug.Assert(loadedUploader != null);
                        res.Add(uploader.Meta, loadedUploader);
                        files.Add(jsonFile, uploader);
                    }
                }

                _uploadersFiles  = files.ToImmutable();
                _customUploaders = res.ToImmutable();
            }
            catch (FileNotFoundException)
            {
                _customUploaders = ImmutableDictionary <UploaderMeta, CustomUploader> .Empty;
            }
            finally
            {
                Loaded = true;
            }
        }
Example #3
0
        /// <returns>true if the default stuff was created.</returns>
        public static async Task CreateUserSettingsIfNotPresent()
        {
            if (File.Exists(HolzShotsPaths.UserSettingsFilePath))
            {
                return;
            }

            var createdAppData = HolzShotsPaths.EnsureAppDataDirectories();

            if (!createdAppData)
            {
                // Since the appdata (and the plugins dir) was just created, there is no demo uploader. So we need to place it there.
                // It's also referenced in the default settings, so it should better be there
                var contents = await HolzShotsResources.ReadResourceAsString("HolzShots.Resources.DirectUpload.net.hs.json");

                await File.WriteAllTextAsync(HolzShotsPaths.DemoCustomUploaderPath, contents);
            }

            using var fs = File.OpenWrite(HolzShotsPaths.UserSettingsFilePath);
            var defaultSettingsStr = await CreateDefaultSettingsJson().ConfigureAwait(false);

            var defaultSettings = Encoding.UTF8.GetBytes(defaultSettingsStr);
            await fs.WriteAsync(defaultSettings).ConfigureAwait(false);
        }
Example #4
0
 public static void OpenSettingsInDefaultEditor() => HolzShotsPaths.OpenFileInDefaultApplication(HolzShotsPaths.UserSettingsFilePath);
Example #5
0
 private void OpenPluginsDirectoryLabel_LinkClicked(object sender, EventArgs e)
 {
     HolzShotsPaths.OpenFolderInExplorer(_model.PluginDirectory);
 }