Пример #1
0
        private void RemoveFromTreeview(ItemLink item)
        {
            var parent = item.GetParent(PackageFiles);

            if (MainExePath != null && item.SourceFilepath != null && MainExePath.ToLower() == item.SourceFilepath.ToLower())
            {
                MainExePath = string.Empty;
                RefreshPackageVersion();
            }

            //
            // Element is in the treeview root.
            if (parent == null)
            {
                if (_packageFiles.Contains(item))
                {
                    _packageFiles.Remove(item);
                }
            }
            else
            {
                //Remove it from children list
                parent.Children.Remove(item);
            }
        }
Пример #2
0
        private static void AddFileToPackage(string directoryBase, ItemLink node, List <ManifestFile> files)
        {
            // Don't add manifest if is directory

            if (node.IsDirectory)
            {
                directoryBase += "/" + node.Filename;

                foreach (var subNode in node.Children)
                {
                    AddFileToPackage(directoryBase, subNode, files);
                }
            }
            else
            {
                //if (File.Exists(node.SourceFilepath))
                {
                    var manifest = new ManifestFile();

                    manifest.Source = node.SourceFilepath;
                    {
                        var extension = Path.GetExtension(node.SourceFilepath);
                        //var filename = Path.GetFileNameWithoutExtension(node.Filename);
                        //manifest.Target = directoryBase + "/" + filename + "_ll_" + extension;
                        manifest.Target = directoryBase + "/" + node.Filename;
                    }


                    files.Add(manifest);
                }
            }
        }
Пример #3
0
        private static ItemLink FindParent(ItemLink link, ItemLink node)
        {
            if (node.Children != null)
            {
                if (node.Children.Contains(link))
                {
                    return(node);
                }

                foreach (var child in node.Children)
                {
                    var p = FindParent(link, child);
                    if (p != null)
                    {
                        return(p);
                    }
                }
            }


            return(null);
        }
Пример #4
0
        private void MoveItem(ItemLink draggedItem, ItemLink targetItem)
        {
            //
            // Remove from current location
            RemoveFromTreeview(draggedItem);


            //
            // Add to target position
            ItemLink parent = targetItem;

            if (targetItem == null)
            {
                //Porto su root
                _packageFiles.Add(draggedItem);
            }
            else
            {
                if (!targetItem.IsDirectory)
                {
                    parent = targetItem.GetParent(PackageFiles);
                }

                if (parent != null)
                {
                    //Insert into treeview root
                    parent.Children.Add(draggedItem);
                }
                else
                {
                    //Insert into treeview root
                    _packageFiles.Add(draggedItem);
                }
            }

            NotifyOfPropertyChange(() => PackageFiles);
        }
Пример #5
0
        private void AddFile(string filePath, ItemLink targetItem)
        {
            var            isDir = false;
            FileAttributes fa    = File.GetAttributes(filePath);

            if (fa != null && fa.HasFlag(FileAttributes.Directory))
            {
                isDir = true;
            }

            RemoveItemBySourceFilepath(filePath);

            var node = new ItemLink()
            {
                SourceFilepath = filePath, IsDirectory = isDir
            };

            ItemLink parent = targetItem;

            if (targetItem == null)
            {
                //Porto su root
                _packageFiles.Add(node);
            }
            else
            {
                if (!targetItem.IsDirectory)
                {
                    parent = targetItem.GetParent(PackageFiles);
                }

                if (parent != null)
                {
                    //Insert into treeview root
                    parent.Children.Add(node);
                }
                else
                {
                    //Insert into treeview root
                    _packageFiles.Add(node);
                }
            }

            if (isDir)
            {
                var dir = new DirectoryInfo(filePath);

                var files        = dir.GetFiles("*.*", SearchOption.TopDirectoryOnly);
                var subDirectory = dir.GetDirectories("*.*", SearchOption.TopDirectoryOnly);

                foreach (var f in files)
                {
                    AddFile(f.FullName, node);
                }

                foreach (var f in subDirectory)
                {
                    AddFile(f.FullName, node);
                }
            }
            else
            {
                // I keep the exe filepath, i'll read the version from this file.
                //
                var ext = Path.GetExtension(filePath).ToLower();

                if (ext == ".exe")
                {
                    MainExePath = filePath;

                    RefreshPackageVersion();
                }
            }
        }
Пример #6
0
 public void SetSelectedItem(ItemLink item)
 {
     SelectedLink = item;
 }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShellViewModel"/> class.
        /// </summary>
        public ShellViewModel()
        {
            var lastproject       = string.Empty;
            var errorMessageShown = false;

            AutoSquirrelPackage.DesignTimeEnviroment.Events.BuildEvents.OnBuildDone += (Scope, Action) => {
                try {
                    if (VSHelper.Options != null &&
                        VSHelper.SelectedProject.Value != null &&
                        VSHelper.Options.ShowUI &&
                        (VSHelper.Options.UseDebug || VSHelper.Options.UseRelease))
                    {
                        errorMessageShown = false;
                        lastproject       = string.Empty;
                        Model             = new AutoSquirrelModel();
                        VSHelper.SetProjectFiles(VSHelper.SelectedProject.Value);
                    }
                } catch {
                }
            };

            VSHelper.ProjectFiles.Where(x => x.Value != null && x.Key != null)
            .Throttle(TimeSpan.FromMilliseconds(500))
            .Select(x => new { Files = x.Value, Project = x.Key })
            .ObserveOn(DispatcherScheduler.Current)
            .Subscribe(x => {
                try {
                    var IsSquirrelProject = x.Files.Any(s => s.Contains("Squirrel"));
                    if (!IsSquirrelProject)
                    {
                        // Project is not using Squirrel
                        VSHelper.ProjectIsValid.Value = false;
                        return;
                    }

                    if (x.Project.FileName == lastproject && Model.IsValid)
                    {
                        // Nothing has changed just show the data
                        VSHelper.ProjectIsValid.Value = true;
                        return;
                    }

                    Model = new AutoSquirrelModel();

                    ItemLink targetItem = null;
                    foreach (var filePath in x.Files)
                    {
                        // exclude unwanted files
                        if (!filePath.Contains(".pdb") && !filePath.Contains(".nupkg") && !filePath.Contains(".vshost."))
                        {
                            Model.AddFile(filePath, targetItem);
                        }
                    }

                    if (string.IsNullOrWhiteSpace(Model.MainExePath))
                    {
                        // Project does not contain an exe at the root level
                        Model = new AutoSquirrelModel();
                        VSHelper.ProjectIsValid.Value = false;
                        return;
                    }
                    lastproject = x.Project.FileName;

                    Model.PackageFiles = AutoSquirrelModel.OrderFileList(Model.PackageFiles);
                    ProjectFilePath    = Path.GetDirectoryName(x.Project.FileName);

                    var xmldoc = new XmlDocument();
                    xmldoc.Load(x.Project.FileName);
                    var mgr = new XmlNamespaceManager(xmldoc.NameTable);
                    mgr.AddNamespace("x", "http://schemas.microsoft.com/developer/msbuild/2003");
                    const string msbuild = "//x:";
                    ////// ApplicationIcon
                    foreach (XmlNode item in xmldoc.SelectNodes(msbuild + "ApplicationIcon", mgr))
                    {
                        Model.IconFilepath = Path.Combine(ProjectFilePath, item.InnerText);
                    }

                    // try to retrieve existing settings
                    var file = Path.Combine(ProjectFilePath, $"{Model.AppId}.asproj");
                    if (File.Exists(file))
                    {
                        var m = FileUtility.Deserialize <AutoSquirrelModel>(file);
                        if (m != null)
                        {
                            Model.IconFilepath = m.IconFilepath;
                            if (!string.IsNullOrWhiteSpace(m?.SelectedConnectionString))
                            {
                                Model.SelectedConnectionString = m.SelectedConnectionString;
                                Model.SelectedConnection       = m.SelectedConnection;
                                FilePath = m.CurrentFilePath;
                                if (Model.SelectedConnection is FileSystemConnection fscon)
                                {
                                    if (string.IsNullOrWhiteSpace(fscon.FileSystemPath))
                                    {
                                        fscon.FileSystemPath = Path.Combine(FilePath, $"{Model.AppId}_files\\Releases");
                                    }
                                }
                                else if (Model.SelectedConnection is AmazonS3Connection s3con)
                                {
                                    if (string.IsNullOrWhiteSpace(s3con.FileSystemPath))
                                    {
                                        s3con.FileSystemPath = Path.Combine(FilePath, $"{Model.AppId}_files\\Releases");
                                    }
                                }
                            }
                        }
                    }

                    // If not able to read settings default to FileSystem settings
                    if (string.IsNullOrWhiteSpace(Model.SelectedConnectionString))
                    {
                        FilePath = ProjectFilePath;
                        Model.SelectedConnectionString = "File System";
                        if (!string.IsNullOrWhiteSpace(ProjectFilePath) && !string.IsNullOrWhiteSpace(Model.AppId) && Model.SelectedConnection is FileSystemConnection con)
                        {
                            con.FileSystemPath = Path.Combine(FilePath, $"{Model.AppId}_files\\Releases");
                        }
                    }
                    if (string.IsNullOrWhiteSpace(FilePath) && Model.SelectedConnection is FileSystemConnection fscon2)
                    {
                        FilePath = ProjectFilePath;
                        fscon2.FileSystemPath = Path.Combine(FilePath, $"{Model.AppId}_files\\Releases");
                    }

                    if (string.IsNullOrWhiteSpace(FilePath) && Model.SelectedConnection is AmazonS3Connection s3con2)
                    {
                        FilePath = ProjectFilePath;
                        s3con2.FileSystemPath = Path.Combine(FilePath, $"{Model.AppId}_files\\Releases");
                    }
                    Save();
                    if (Model.IsValid)
                    {
                        VSHelper.ProjectIsValid.Value = true;
                    }
                    else
                    {
                        if (!errorMessageShown)
                        {
                            MessageBox.Show(Model.Error, "Please correct the following issues with your project", MessageBoxButton.OK, MessageBoxImage.Error);
                            errorMessageShown = true;
                        }
                    }
                } catch (Exception) {
                    VSHelper.ProjectIsValid.Value = false;
                }
            });
        }