private async Task <string> GetBuildsSavePathAsync()
        {
            if (AppData.IsPortable)
            {
                return(AppData.ToRelativePath(AppData.GetFolder("Builds")));
            }

            // Ask user for path. Default: AppData.GetFolder("Builds")
            var dialogSettings = new FileSelectorDialogSettings
            {
                DefaultPath       = AppData.GetFolder("Builds"),
                IsFolderPicker    = true,
                ValidationSubPath = GetLongestRequiredSubpath(),
                IsCancelable      = false
            };

            if (!DeserializesBuildsSavePath)
            {
                dialogSettings.AdditionalValidationFunc =
                    path => Directory.Exists(path) && Directory.EnumerateFileSystemEntries(path).Any()
                        ? L10n.Message("Directory must be empty.")
                        : null;
            }
            return((await DialogCoordinator.ShowFileSelectorAsync(PersistentData,
                                                                  L10n.Message("Select build directory"),
                                                                  L10n.Message("Select the directory where builds will be stored.\n" +
                                                                               "It will be created if it does not yet exist. You can change it in the settings later."),
                                                                  dialogSettings)) !);
        }
Beispiel #2
0
        private async Task ChangeBuildsSavePath()
        {
            var dialogSettings = new FileSelectorDialogSettings
            {
                DefaultPath       = Options.BuildsSavePath,
                IsFolderPicker    = true,
                ValidationSubPath = SerializationConstants.EncodedDefaultBuildName
            };
            var path = await _dialogCoordinator.ShowFileSelectorAsync(this,
                                                                      L10n.Message("Select build directory"),
                                                                      L10n.Message("Select the directory where builds will be stored.\n" +
                                                                                   "It will be created if it does not yet exist."),
                                                                      dialogSettings);

            if (path == null)
            {
                return;
            }

            var message = L10n.Message("There are unsaved builds. Do you want to save them before changing build directory?\n\n"
                                       + "If you cancel, the build directory will not be changed.");

            if (!await _buildsControlViewModel.HandleUnsavedBuilds(message, true))
            {
                return;
            }
            _persistentData.SaveFolders();

            Options.BuildsSavePath = path;
            await _persistentData.ReloadBuildsAsync();
        }
Beispiel #3
0
 public FileSelectorViewModel(string title, string message, FileSelectorDialogSettings settings)
 {
     if (!settings.IsFolderPicker && !string.IsNullOrEmpty(settings.ValidationSubPath))
     {
         throw new ArgumentException("ValidationSubPath may only be given if IsFolderPicker is true",
                                     nameof(settings));
     }
     DisplayName               = title;
     Message                   = message;
     IsCancelable              = settings.IsCancelable;
     _isFolderPicker           = settings.IsFolderPicker;
     _validationSubPath        = settings.ValidationSubPath;
     _additionalValidationFunc = settings.AdditionalValidationFunc;
     FilePath                  = settings.DefaultPath;
     SelectFileCommand         = new RelayCommand(SelectFile);
 }
        private async void ExportGGGBuild(IBuildFolderViewModel target)
        {
            var build = new GGGBuild()
            {
                Name    = target.Build.Name,
                Version = PoESkillTree.Properties.Version.GGGPatchVersion,
                Parts   = new List <GGGBuildPart>()
            };

            foreach (var c in target.Children)
            {
                if (!c.GetType().Equals(typeof(BuildFolderViewModel)))
                {
                    build.Parts.Add(new GGGBuildPart()
                    {
                        Label = c.Build.Name, Link = ((PoEBuild)c.Build).TreeUrl
                    });
                }
            }

            var dialogSettings = new FileSelectorDialogSettings
            {
                DefaultPath    = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                IsFolderPicker = true,
            };
            var path = await _dialogCoordinator.ShowFileSelectorAsync(this,
                                                                      L10n.Message("Select save directory"),
                                                                      L10n.Message("Select the directory where you want to export this build structure."),
                                                                      dialogSettings);

            if (path == null)
            {
                return;
            }
            path = Path.Combine(path, $"{SerializationUtils.EncodeFileName(build.Name)}.build");

            byte[] jsonEncodedText = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(build));
            using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: jsonEncodedText.Length, useAsync: true))
            {
                await stream.WriteAsync(jsonEncodedText, 0, jsonEncodedText.Length);
            }
        }
        /// <summary>
        /// Changes the stat tracking path.
        /// </summary>
        /// <returns></returns>
        private async Task ChangeStatTrackingPath()
        {
            var dialogSettings = new FileSelectorDialogSettings
            {
                DefaultPath       = StatTrackingSavePath,
                IsFolderPicker    = true,
                ValidationSubPath = SerializationConstants.EncodedDefaultBuildName
            };
            var path = await _dialogCoordinator.ShowFileSelectorAsync(this,
                                                                      L10n.Message("Select TrackedStat directory"),
                                                                      L10n.Message("Select the directory where builds will be stored.\n" +
                                                                                   "It will be created if it does not yet exist."),
                                                                      dialogSettings);

            if (path == null)
            {
                return;
            }

            StatTrackingSavePath = path;
        }
Beispiel #6
0
        public async Task InitializeAsync(IDialogCoordinator dialogCoordinator)
        {
            DialogCoordinator = dialogCoordinator;
            if (PersistentData.Options.BuildsSavePath == null)
            {
                if (AppData.IsPortable)
                {
                    PersistentData.Options.BuildsSavePath = AppData.GetFolder("Builds");
                }
                else
                {
                    // Ask user for path. Default: AppData.GetFolder("Builds")
                    var dialogSettings = new FileSelectorDialogSettings
                    {
                        DefaultPath       = AppData.GetFolder("Builds"),
                        IsFolderPicker    = true,
                        ValidationSubPath = GetLongestRequiredSubpath(),
                        IsCancelable      = false
                    };
                    if (!DeserializesBuildsSavePath)
                    {
                        dialogSettings.AdditionalValidationFunc =
                            path => Directory.Exists(path) && Directory.EnumerateFileSystemEntries(path).Any()
                                ? L10n.Message("Directory must be empty.")
                                : null;
                    }
                    PersistentData.Options.BuildsSavePath = await dialogCoordinator.ShowFileSelectorAsync(PersistentData,
                                                                                                          L10n.Message("Select build directory"),
                                                                                                          L10n.Message("Select the directory where builds will be stored.\n" +
                                                                                                                       "It will be created if it does not yet exist. You can change it in the settings later."),
                                                                                                          dialogSettings);
                }
            }
            Directory.CreateDirectory(PersistentData.Options.BuildsSavePath);
            await DeserializeAdditionalFilesAsync();

            PersistentData.EquipmentData = await DeserializeEquipmentData();

            PersistentData.StashItems.AddRange(await DeserializeStashItemsAsync());
        }