Click here to Skip to main content
15,885,757 members
Articles / Programming Languages / C#

Create a Vista Gadget Using Visual Studio IDE (updated)

Rate me:
Please Sign up or sign in to vote.
4.84/5 (46 votes)
8 Feb 2011CPOL13 min read 263.4K   19.5K   254  
This article describes how to use Visual Studio for developing a Vista Gadget.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using EnvDTE;
using EnvDTE80;

namespace RunVistaGadget25.AdditionalApplicationsWrappers
{
    public class CabarcRunner : ApplicationRunner
    {
        public CabarcRunner(DTE2 applicationObject)
            : base(applicationObject, false)
        {

        }

        public CabarcRunner(DTE2 applicationObject, bool isRunAsWinApp)
            : base(applicationObject, isRunAsWinApp)
        {

        }

        public override string GetAppArguments()
        {
            String RootDirectory = Path.GetDirectoryName(project.FullName);
            String RootDirectoryWithoutDiskName = RootDirectory.Replace(Path.GetPathRoot(RootDirectory), "") + "\\";
            String AllowedFileExtensions = GadgetProp.AllowedExtensionsForGadget;
            String[] AllowesFileExtensionsArray = AllowedFileExtensions.Split(';');
            StringBuilder AllowedInGadgetFileExtensions = new StringBuilder();
            for (int i = 0; i < AllowesFileExtensionsArray.Length; i++)
            {
                if (!String.IsNullOrEmpty(AllowesFileExtensionsArray[i].Trim()))
                {
                    AllowedInGadgetFileExtensions.Append(String.Format(" {0}\\{1}", RootDirectory, AllowesFileExtensionsArray[i].Trim()));
                }

            }

            String CabarcArgs = @" -r -p -P " + RootDirectoryWithoutDiskName + " n " + GadgetPath + AllowedInGadgetFileExtensions.ToString();
            return CabarcArgs;
        }

        public override string GetOutputAndRunApplication()
        {
            GadgetProperties gp = new GadgetProperties();
            base.CalledApplicationPath = gp.ArchivatorPath;
            if (base.IsExistCalledApplication(base.CalledApplicationPath, "CABARC.EXE") == false)
                throw new Exception("Could not find required application CABARC.EXE. Please, define it with 'GadgetProperties' form.");
            return base.GetOutputAndRunApplication();
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions