public void OpenProject(string filepath) { try { if (string.IsNullOrEmpty(filepath) || !File.Exists(filepath)) { MessageBox.Show("This file doesn't exist : " + filepath, "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.None); return; } FilePath = filepath; var m = FileUtility.Deserialize <AutoSquirrelModel>(filepath); if (m == null) { return; } Model = m; Model.PackageFiles = AutoSquirrelModel.OrderFileList(Model.PackageFiles); Model.RefreshPackageVersion(); AddLastProject(filepath); } catch (Exception exception) { MessageBox.Show("Loading File Error, file no more supported", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.None); } }
/// <summary> /// Ctor /// </summary> public ShellViewModel() { Model = new AutoSquirrelModel(); UserPreference = PathFolderHelper.LoadUserPreference(); var last = UserPreference.LastOpenedProject.LastOrDefault(); if (!string.IsNullOrEmpty(last) && File.Exists(last)) { OpenProject(last); } }
/// /// M E T H O D S /// public void CreateNewProject() { var rslt = MessageBox.Show("Save current project ?", "New Project", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); if (rslt == MessageBoxResult.Cancel) { return; } if (rslt == MessageBoxResult.Yes) { Save(); } Model = new AutoSquirrelModel(); }
internal string CreateNugetPackage(AutoSquirrelModel model) { var metadata = new ManifestMetadata() { Id = model.AppId, Authors = model.Authors, Version = model.Version, Description = model.Description, Title = model.Title, }; PackageBuilder builder = new PackageBuilder(); builder.Populate(metadata); //As Squirrel convention i put everything in lib/net45 folder var directoryBase = "/lib/net45"; var files = new List <ManifestFile>(); foreach (var node in model.PackageFiles) { AddFileToPackage(directoryBase, node, files); } builder.PopulateFiles("", files.ToArray()); var nugetPath = model.NupkgOutputPath + Path.DirectorySeparatorChar + model.AppId + "." + model.Version + ".nupkg"; using (FileStream stream = File.Open(nugetPath, FileMode.OpenOrCreate)) { builder.Save(stream); } return(nugetPath); }
/// <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; } }); }