Ejemplo n.º 1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            string brandingPath = Path.Combine(Locations.InstallBase, "_branding");

            if (File.Exists(brandingPath + ".txt"))
            {
                Text = File.ReadAllText(brandingPath + ".txt");
            }
            if (File.Exists(brandingPath + ".png"))
            {
                pictureBoxLogo.Image = Image.FromFile(brandingPath + ".png");
            }

            if (Locations.IsPortable)
            {
                Text += @" - " + Resources.PortableMode;
            }
            if (_machineWide)
            {
                Text += @" - " + Resources.MachineWideMode;
            }
            labelVersion.Text = @"v" + AppInfo.Current.Version;

            tileListMyApps.IconCache = tileListCatalog.IconCache = IconCacheProvider.GetInstance();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the main GUI.
        /// </summary>
        /// <param name="machineWide">Apply operations machine-wide instead of just for the current user.</param>
        /// <exception cref="IOException">Failed to read a config file.</exception>
        /// <exception cref="UnauthorizedAccessException">Access to a configuration file was not permitted.</exception>
        /// <exception cref="InvalidDataException">The config data is damaged.</exception>
        public MainForm(bool machineWide)
        {
            InitializeComponent();
            HandleCreated += MainForm_HandleCreated;
            MouseWheel    += MainForm_MouseWheel;

            _machineWide = machineWide;

            var services = new ServiceLocator(new MinimalTaskHandler(this))
            {
                Config = { NetworkUse = NetworkLevel.Minimal }
            };

            _tileManagement = new AppTileManagement(
                services.FeedManager, services.CatalogManager, IconCacheProvider.GetInstance(),
                tileListMyApps, tileListCatalog, _machineWide);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Builds a stub EXE that executes the "0install run" command.
        /// </summary>
        /// <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="handler">A callback object used when the the user is to be informed about the progress of long-running operations such as downloads.</param>
        /// <param name="needsTerminal"><c>true</c> to build a CLI stub, <c>false</c> to build a GUI stub.</param>
        /// <param name="command">The command argument to be passed to the the "0install run" command; can be <c>null</c>.</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>
        internal static void BuildRunStub(FeedTarget target, [NotNull] string path, [NotNull] ITaskHandler handler, bool needsTerminal, [CanBeNull] string command = null)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }
            #endregion

            var compilerParameters = new CompilerParameters
            {
                GenerateExecutable      = true,
                OutputAssembly          = path,
                IncludeDebugInformation = false,
                GenerateInMemory        = false,
                TreatWarningsAsErrors   = true,
                ReferencedAssemblies    = { "System.dll" }
            };

            if (!needsTerminal)
            {
                compilerParameters.CompilerOptions += " /target:winexe";
            }

            var icon = target.Feed.GetIcon(Icon.MimeTypeIco, command);
            if (icon != null)
            {
                string iconPath = IconCacheProvider.GetInstance().GetIcon(icon.Href, handler);
                compilerParameters.CompilerOptions += " /win32icon:" + iconPath.EscapeArgument();
            }

            compilerParameters.CompileCSharp(
                GetRunStubCode(target, needsTerminal, command),
                typeof(StubBuilder).GetEmbeddedString("Stub.manifest"));
        }
Ejemplo n.º 4
0
        public static string GetIconPath([NotNull] Icon icon, [NotNull] ITaskHandler handler, bool machineWide)
        {
            #region Sanity checks
            if (icon == null)
            {
                throw new ArgumentNullException(nameof(icon));
            }
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }
            #endregion

            string iconDirPath  = Locations.GetIntegrationDirPath("0install.net", machineWide, "desktop-integration", "icons");
            string iconFilePath = Path.Combine(iconDirPath, icon.Href.AbsoluteUri.Hash(SHA256.Create()) + ".ico");

            // Return an existing icon or get a new one from the cache
            if (!File.Exists(iconFilePath) || (DateTime.UtcNow - File.GetLastWriteTimeUtc(iconFilePath) > _freshness))
            {
                File.Copy(IconCacheProvider.GetInstance().GetIcon(icon.Href, handler), iconFilePath, overwrite: true);
            }
            return(iconFilePath);
        }