/// <summary> /// Creates a new or updates an existing stub EXE that executes the "0install run" command. /// </summary> /// <seealso cref="BuildRunStub"/> /// <param name="target">The application to be launched via the stub.</param> /// <param name="path">The target path to store the generated EXE file.</param> /// <param name="command">The command argument to be passed to the the "0install run" command; can be <see langword="null"/>.</param> /// <param name="needsTerminal"><see langword="true"/> to build a CLI stub, <see langword="false"/> to build a GUI stub.</param> /// <param name="handler">A callback object used when the the user is to be informed about the progress of long-running operations such as downloads.</param> /// <exception cref="OperationCanceledException">The user canceled the task.</exception> /// <exception cref="InvalidOperationException">There was a compilation error while generating the stub EXE.</exception> /// <exception cref="IOException">A problem occurs while writing to the filesystem.</exception> /// <exception cref="WebException">A problem occured while downloading additional data (such as icons).</exception> /// <exception cref="UnauthorizedAccessException">Write access to the filesystem is not permitted.</exception> private static void CreateOrUpdateRunStub(this FeedTarget target, [NotNull] string path, [CanBeNull] string command, bool needsTerminal, [NotNull] ITaskHandler handler) { if (File.Exists(path)) { // Existing stub // TODO: Find better rebuild discriminator if (File.GetLastWriteTime(path) < Process.GetCurrentProcess().StartTime) { // Outdated, try to rebuild try { File.Delete(path); } #region Error handling catch (IOException ex) { Log.Warn(string.Format(Resources.UnableToReplaceStub, path)); Log.Warn(ex); return; } catch (UnauthorizedAccessException ex) { Log.Warn(string.Format(Resources.UnableToReplaceStub, path)); Log.Warn(ex); return; } #endregion target.BuildRunStub(path, handler, needsTerminal, command); } } else { // No existing stub, build new one target.BuildRunStub(path, handler, needsTerminal, command); } }
/// <summary> /// Creates an application alias in the current system. /// </summary> /// <param name="target">The application being integrated.</param> /// <param name="command">The command within <paramref name="target"/> the alias shall point to; can be <see langword="null"/>.</param> /// <param name="aliasName">The name of the alias to be created.</param> /// <param name="machineWide">Create the alias machine-wide instead of just for the current user.</param> /// <param name="handler">A callback object used when the the user is to be informed about the progress of long-running operations such as downloads.</param> /// <exception cref="OperationCanceledException">The user canceled the task.</exception> /// <exception cref="IOException">A problem occurs while writing to the filesystem or registry.</exception> /// <exception cref="WebException">A problem occured while downloading additional data (such as icons).</exception> /// <exception cref="UnauthorizedAccessException">Write access to the filesystem or registry is not permitted.</exception> public static void Create(FeedTarget target, [CanBeNull] string command, [NotNull] string aliasName, bool machineWide, [NotNull] ITaskHandler handler) { #region Sanity checks if (string.IsNullOrEmpty(aliasName)) { throw new ArgumentNullException("aliasName"); } if (handler == null) { throw new ArgumentNullException("handler"); } #endregion if (string.IsNullOrEmpty(aliasName) || aliasName.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) { throw new IOException(string.Format(Resources.NameInvalidChars, aliasName)); } string stubDirPath = Locations.GetIntegrationDirPath("0install.net", machineWide, "desktop-integration", "aliases"); string stubFilePath = Path.Combine(stubDirPath, aliasName + ".exe"); target.BuildRunStub(stubFilePath, handler, needsTerminal: true, command: command); AddToPath(stubDirPath, machineWide); AddToAppPaths(aliasName + ".exe", stubFilePath, machineWide); }