static string BuildPackagesDirectory([NotNull] ISnapFilesystem filesystem, [NotNull] string workingDirectory, [NotNull] SnapAppsGeneric snapAppsGeneric, [NotNull] SnapApp snapApp) { if (filesystem == null) { throw new ArgumentNullException(nameof(filesystem)); } if (workingDirectory == null) { throw new ArgumentNullException(nameof(workingDirectory)); } if (snapAppsGeneric == null) { throw new ArgumentNullException(nameof(snapAppsGeneric)); } if (snapApp == null) { throw new ArgumentNullException(nameof(snapApp)); } var properties = new Dictionary <string, string> { { "id", snapApp.Id }, { "rid", snapApp.Target.Rid } }; return(snapAppsGeneric.Packages == null? filesystem.PathCombine(workingDirectory, ".snapx", "packages", "$id$/$rid$").ExpandProperties(properties) : filesystem.PathGetFullPath(snapAppsGeneric.Packages).ExpandProperties(properties)); }
static int CommandRcEdit([NotNull] RcEditOptions opts, [NotNull] ICoreRunLib coreRunLib, [NotNull] ISnapFilesystem snapFilesystem, [NotNull] ILog logger) { if (opts == null) { throw new ArgumentNullException(nameof(opts)); } if (coreRunLib == null) { throw new ArgumentNullException(nameof(coreRunLib)); } if (snapFilesystem == null) { throw new ArgumentNullException(nameof(snapFilesystem)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } var exitCode = 1; if (!snapFilesystem.FileExists(opts.Filename)) { logger.Error($"Filename does not exist: {opts.Filename}."); goto done; } if (opts.ConvertSubSystemToWindowsGui) { logger.Info($"Attempting to change subsystem to Windows GUI for executable: {snapFilesystem.PathGetFileName(opts.Filename)}."); using (var srcStream = snapFilesystem.FileReadWrite(opts.Filename, false)) { if (!srcStream.ChangeSubsystemToWindowsGui(SnapLogger)) { goto done; } logger.Info("Subsystem has been successfully changed to Windows GUI."); } exitCode = 0; } if (opts.IconFilename != null) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { logger.Error("Modifying executable icon is not supported on this OS platform."); goto done; } opts.IconFilename = snapFilesystem.PathGetFullPath(opts.IconFilename); if (!snapFilesystem.FileExists(opts.IconFilename)) { logger.Error($"Unable to find icon with filename: {opts.IconFilename}"); goto done; } if (!coreRunLib.SetIcon(opts.Filename, opts.IconFilename)) { logger.Error($"Unknown error setting icon for executable {opts.Filename}. Icon filename: {opts.Filename}."); goto done; } logger.Info("Icon has been successfully updated."); exitCode = 0; } done: return(exitCode); }
internal static SnapApp BuildSnapApp([NotNull] this SnapApps snapApps, string id, [NotNull] string rid, [NotNull] INuGetPackageSources nuGetPackageSources, [NotNull] ISnapFilesystem snapFilesystem) { if (snapApps == null) { throw new ArgumentNullException(nameof(snapApps)); } if (rid == null) { throw new ArgumentNullException(nameof(rid)); } if (nuGetPackageSources == null) { throw new ArgumentNullException(nameof(nuGetPackageSources)); } if (snapFilesystem == null) { throw new ArgumentNullException(nameof(snapFilesystem)); } var snapApp = snapApps.Apps.SingleOrDefault(x => string.Equals(x.Id, id, StringComparison.OrdinalIgnoreCase)); if (snapApp == null) { throw new Exception($"Unable to find snap with id: {id}"); } if (!Guid.TryParse(snapApp.SuperVisorId, out var superVisorId)) { throw new Exception("Unable to parse supervisor id. Please use a unique guid to identify your application."); } if (superVisorId == Guid.Empty) { throw new Exception("Supervisor id cannot be an empty guid."); } var snapAppUniqueRuntimeIdentifiers = snapApp.Targets.Select(x => x.Rid).ToList(); if (snapAppUniqueRuntimeIdentifiers.Distinct().Count() != snapApp.Targets.Count) { throw new Exception($"Target runtime identifiers (rids) must be unique: {string.Join(",", snapAppUniqueRuntimeIdentifiers)}. Snap id: {snapApp.Id}"); } var snapAppTarget = snapApp.Targets.SingleOrDefault(x => string.Equals(x.Rid, rid, StringComparison.OrdinalIgnoreCase)); if (snapAppTarget == null) { throw new Exception($"Unable to find target with rid: {rid}. Snap id: {snapApp.Id}"); } snapAppTarget.Installers = snapAppTarget.Installers.Distinct().ToList(); if (!snapAppTarget.Rid.IsRuntimeIdentifierValidSafe()) { throw new Exception($"Unsupported rid: {rid}. Snap id: {snapApp.Id}"); } if (!snapAppTarget.Framework.IsNetFrameworkValidSafe()) { throw new Exception($"Unknown .NET framework: {snapAppTarget.Framework}"); } var snapAppTargetUniqueShortcuts = snapAppTarget.Shortcuts.Select(x => x).ToList(); if (snapAppTargetUniqueShortcuts.Distinct().Count() != snapAppTarget.Shortcuts.Count) { throw new Exception($"Target shortcut locations must be unique: {string.Join(", ", snapAppTargetUniqueShortcuts)}. Snap id: {snapApp.Id}"); } var snapAppTargetUniqueInstallers = snapAppTarget.Installers.Select(x => x).ToList(); if (snapAppTargetUniqueInstallers.Distinct().Count() != snapAppTarget.Installers.Count) { throw new Exception($"Target installer types must be unique: {string.Join(", ", snapAppTargetUniqueInstallers)}. Snap id: {snapApp.Id}"); } if (snapAppTarget.Icon != null) { snapAppTarget.Icon = snapFilesystem.PathGetFullPath(snapAppTarget.Icon); if (!snapFilesystem.FileExists(snapAppTarget.Icon)) { throw new Exception($"Unable to find icon: {snapAppTarget.Icon}."); } } var snapAppUniqueChannels = snapApp.Channels.Distinct().ToList(); if (snapAppUniqueChannels.Count != snapApp.Channels.Count) { throw new Exception($"Channel list must be unique: {string.Join(",", snapApp.Channels)}. Snap id: {snapApp.Id}"); } var snapAppsDefaultChannel = snapApps.Channels.First(); var snapAppDefaultChannel = snapApp.Channels.First(); if (!string.Equals(snapAppsDefaultChannel.Name, snapAppDefaultChannel, StringComparison.Ordinal)) { throw new Exception($"Default channel must be {snapAppsDefaultChannel.Name}. Snap id: {snapApp.Id}"); } var snapAppAvailableChannels = snapApps.Channels.Where(rhs => snapApp.Channels.Any(lhs => lhs.Equals(rhs.Name, StringComparison.OrdinalIgnoreCase))).ToList(); if (!snapAppAvailableChannels.Any()) { throw new Exception($"Could not find any global channels. Channel list: {string.Join(",", snapAppUniqueChannels)}. Snap id: {snapApp.Id}"); } var snapFeeds = new List <SnapFeed>(); snapFeeds.AddRange(nuGetPackageSources.BuildSnapFeeds()); snapFeeds.AddRange(snapApps.Channels.Select(x => x.UpdateFeed).OfType <SnapsHttpFeed>().DistinctBy(x => x.Source).Select(x => new SnapHttpFeed(x))); var snapNugetFeeds = snapFeeds.Where(x => x is SnapNugetFeed).Cast <SnapNugetFeed>().ToList(); var snapHttpFeeds = snapFeeds.Where(x => x is SnapHttpFeed).Cast <SnapHttpFeed>().ToList(); var snapAppChannels = new List <SnapChannel>(); for (var i = 0; i < snapAppAvailableChannels.Count; i++) { var snapsChannel = snapAppAvailableChannels[i]; var pushFeed = snapNugetFeeds.SingleOrDefault(x => x.Name == snapsChannel.PushFeed.Name); if (pushFeed == null) { throw new Exception($"Unable to resolve push feed: {snapsChannel.PushFeed.Name}. Channel: {snapsChannel.Name}. Application id: {snapApp.Id}"); } SnapFeed updateFeed = null; switch (snapsChannel.UpdateFeed) { case SnapsNugetFeed snapsNugetFeed: updateFeed = snapNugetFeeds.SingleOrDefault(x => x.Name == snapsNugetFeed.Name); break; case SnapsHttpFeed snapsHttpFeed: updateFeed = snapHttpFeeds.SingleOrDefault(x => x.Source == snapsHttpFeed.Source); break; } if (updateFeed == null) { throw new Exception($"Unable to resolve update feed type: {snapsChannel.UpdateFeed?.GetType().Name}. Channel: {snapsChannel.Name}. Application id: {snapApp.Id}"); } var currentChannel = i == 0; // Default snap channel is always the first one defined. snapAppChannels.Add(new SnapChannel(snapsChannel.Name, currentChannel, pushFeed, updateFeed)); } var snapChannelNugetFeedNames = snapAppChannels.Select(x => x.PushFeed.Name).Distinct().ToList(); if (snapChannelNugetFeedNames.Count > 1) { throw new Exception($"Multiple nuget push feeds is not supported: {string.Join(",", snapChannelNugetFeedNames)}. Application id: {snapApp.Id}"); } if (snapAppTarget.PersistentAssets.Any(x => x.StartsWith("app-", StringComparison.OrdinalIgnoreCase))) { throw new Exception("Fatal error! A persistent asset starting with 'app-' was detected in manifest. This is a reserved keyword."); } return(new SnapApp { Id = snapApp.Id, SuperVisorId = superVisorId.ToString(), Channels = snapAppChannels, Target = new SnapTarget(snapAppTarget), Authors = snapApp.Nuspec.Authors, Description = snapApp.Nuspec.Description, ReleaseNotes = snapApp.Nuspec.ReleaseNotes, RepositoryUrl = snapApp.Nuspec.RepositoryUrl, RepositoryType = snapApp.Nuspec.RepositoryType }); }