Example #1
0
 private static bool CanBeChildOf(IBuildFolderViewModel build, string parentPath, int parentDepth)
 {
     // Check depth and name
     if (parentDepth >= MaxBuildDepth)
         return false;
     var name = build.Build.Name;
     if (!IsNameValid(name, Path.Combine(parentPath, FileNameForFolder(name))))
         return false;
     // Check all subbuilds
     var nextPath = Path.Combine(parentPath, SerializationUtils.EncodeFileName(name));
     var nextDepth = parentDepth + 1;
     foreach (var child in build.Children)
     {
         var folder = child as IBuildFolderViewModel;
         if (folder == null)
         {
             if (!CanBeChildOf(child, nextPath))
             {
                 return false;
             }
         }
         else
         {
             if (!CanBeChildOf(folder, nextPath, nextDepth))
             {
                 return false;
             }
         }
     }
     return true;
 }
Example #2
0
        private async void BuildOnCollectionChanged(IBuildFolderViewModel build)
        {
            await SaveBuildToFile(build);

            // It's ok that this method doesn't return Task as it is used like an event handler and the
            // async action in SaveBuildToFile does not require to be waited upon.
        }
Example #3
0
        private static string?ValidateName(string name, string fullPath, IBuildViewModel?build,
                                           IBuildFolderViewModel parent)
        {
            if (!IsNameUnique(name, build, parent))
            {
                return(L10n.Message("A build or folder with this name already exists."));
            }

            IsNameValid(name, fullPath, out var message);
            return(message);
        }
        public void NewBuild(IBuildFolderViewModel folder)
        {
            var name = Util.FindDistinctName(SerializationConstants.DefaultBuildName,
                                             folder.Children.Select(b => b.Build.Name));
            var build = new BuildViewModel(new PoEBuild {
                Name = name
            }, Filter);

            folder.Children.Add(build);
            CurrentBuild = build;
        }
        private async Task <PoEBuild> PasteFromClipboard(IBuildFolderViewModel targetFolder)
        {
            var str      = Clipboard.GetText();
            var newBuild = await PersistentData.ImportBuildAsync(str);

            if (newBuild == null)
            {
                return(null);
            }
            newBuild.Name = Util.FindDistinctName(newBuild.Name, targetFolder.Children.Select(b => b.Build.Name));
            return(newBuild);
        }
Example #6
0
        /// <summary>
        /// Returns true iff <paramref name="build"/> can be moved to <paramref name="parent"/>.
        /// </summary>
        public bool CanMoveTo(IBuildViewModel build, IBuildFolderViewModel parent)
        {
            if (!IsNameUnique(build.Build.Name, build, parent))
                return false;

            var parentPath = BasePathFor(parent);
            var folder = build as IBuildFolderViewModel;
            if (folder == null)
            {
                return CanBeChildOf(build, parentPath);
            }
            else
            {
                var parentDepth = GetDepthOfFolder(parent);
                return CanBeChildOf(folder, parentPath, parentDepth);
            }
        }
Example #7
0
        private async Task NewFolder(IBuildFolderViewModel folder)
        {
            var name = await _dialogCoordinator.ShowValidatingInputDialogAsync(this,
                                                                               L10n.Message("New Folder"),
                                                                               L10n.Message("Enter the name of the new folder."),
                                                                               "",
                                                                               s => _buildValidator.ValidateNewFolderName(s, folder));

            if (string.IsNullOrWhiteSpace(name))
            {
                return;
            }
            var newFolder = new BuildFolderViewModel(new BuildFolder {
                Name = name
            }, Filter, BuildOnCollectionChanged);

            folder.Children.Add(newFolder);
            await SaveBuildToFile(newFolder);
        }
Example #8
0
        private async Task NewBuild(IBuildFolderViewModel folder)
        {
            var name = await _dialogCoordinator.ShowValidatingInputDialogAsync(this,
                                                                               L10n.Message("New Build"),
                                                                               L10n.Message("Enter the name of the new build."),
                                                                               "",
                                                                               s => _buildValidator.ValidateNewBuildName(s, folder));

            if (string.IsNullOrWhiteSpace(name))
            {
                return;
            }
            var build = new BuildViewModel(new PoEBuild {
                Name = name
            }, Filter);

            folder.Children.Add(build);
            CurrentBuild = build;
        }
        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);
            }
        }
Example #10
0
        /// <summary>
        /// Returns true iff <paramref name="build"/> can be moved to <paramref name="parent"/>.
        /// </summary>
        public bool CanMoveTo(IBuildViewModel build, IBuildFolderViewModel parent)
        {
            if (!IsNameUnique(build.Build.Name, build, parent))
            {
                return(false);
            }

            var parentPath = BasePathFor(parent);
            var folder     = build as IBuildFolderViewModel;

            if (folder == null)
            {
                return(CanBeChildOf(build, parentPath));
            }
            else
            {
                var parentDepth = GetDepthOfFolder(parent);
                return(CanBeChildOf(folder, parentPath, parentDepth));
            }
        }
Example #11
0
        private static bool CanBeChildOf(IBuildFolderViewModel build, string parentPath, int parentDepth)
        {
            // Check depth and name
            if (parentDepth >= MaxBuildDepth)
            {
                return(false);
            }
            var name = build.Build.Name;

            if (!IsNameValid(name, Path.Combine(parentPath, FileNameForFolder(name))))
            {
                return(false);
            }
            // Check all subbuilds
            var nextPath  = Path.Combine(parentPath, SerializationUtils.EncodeFileName(name));
            var nextDepth = parentDepth + 1;

            foreach (var child in build.Children)
            {
                var folder = child as IBuildFolderViewModel;
                if (folder == null)
                {
                    if (!CanBeChildOf(child, nextPath))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (!CanBeChildOf(folder, nextPath, nextDepth))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #12
0
 /// <summary>
 /// Returns true iff the <paramref name="folder"/> can have subfolders. There can only be a constant number
 /// of folders nested into each other.
 /// </summary>
 public bool CanHaveSubfolder(IBuildFolderViewModel folder)
 {
     return(GetDepthOfFolder(folder) < MaxBuildDepth);
 }
Example #13
0
 private static bool IsNameUnique(string name, IBuildViewModel build, IBuildFolderViewModel parent)
 {
     return(parent.Children.All(b => b == build || b.Build.Name != name));
 }
Example #14
0
 /// <summary>
 /// Returns an string that contains an error message if it is not null or empty that describes
 /// why <paramref name="name"/> is not allowed as a name for a new build located in <paramref name="parent"/>.
 /// </summary>
 public string ValidateNewBuildName(string name, IBuildFolderViewModel parent)
 {
     return(ValidateName(name, PathForBuild(name, parent), null, parent));
 }
Example #15
0
 /// <summary>
 /// Returns true iff the <paramref name="folder"/> can have subfolders. There can only be a constant number
 /// of folders nested into each other.
 /// </summary>
 public bool CanHaveSubfolder(IBuildFolderViewModel folder)
 {
     return GetDepthOfFolder(folder) < MaxBuildDepth;
 }
Example #16
0
 /// <summary>
 /// Returns an string that contains an error message if it is not null or empty that describes
 /// why <paramref name="name"/> is not allowed as a name for a new build located in <paramref name="parent"/>.
 /// </summary>
 public string ValidateNewBuildName(string name, IBuildFolderViewModel parent)
 {
     return ValidateName(name, PathForBuild(name, parent), null, parent);
 }
Example #17
0
 private static int GetDepthOfFolder(IBuildFolderViewModel folder)
 {
     return folder.Parent == null ? 1 : 1 + GetDepthOfFolder(folder.Parent);
 }
Example #18
0
 private static string ValidateName(string name, string fullPath, IBuildViewModel build,
     IBuildFolderViewModel parent)
 {
     if (!IsNameUnique(name, build, parent))
     {
         return L10n.Message("A build or folder with this name already exists.");
     }
     string message;
     IsNameValid(name, fullPath, out message);
     return message;
 }
Example #19
0
 private static int GetDepthOfFolder(IBuildFolderViewModel folder)
 {
     return(folder.Parent == null ? 1 : 1 + GetDepthOfFolder(folder.Parent));
 }
Example #20
0
 private static bool IsNameUnique(string name, IBuildViewModel build, IBuildFolderViewModel parent)
 {
     return parent.Children.All(b => b == build || b.Build.Name != name);
 }