Example #1
0
        static LauncherApp()
        {
            var assembly = typeof(Program).Assembly;

            var assemblyInformationalVersion = CustomAttributeProviderExtensions.GetCustomAttribute <AssemblyInformationalVersionAttribute>(assembly);

            Version = assemblyInformationalVersion.InformationalVersion;
        }
Example #2
0
 /// <inheritdoc />
 public void Register <TService>(Regex assemblyNamePattern = null)
 {
     EnsureStandardLibraries();
     foreach (var implementingType in CustomAttributeProviderExtensions.FindAllTypesImplementing <TService>(assemblyNamePattern))
     {
         Register <TService>(implementingType, implementingType.FullName);
     }
 }
Example #3
0
        private void SelfUpdate()
        {
            var version          = new SemanticVersion(Version);
            var productAttribute = CustomAttributeProviderExtensions.GetCustomAttribute <AssemblyProductAttribute>(typeof(LauncherApp).Assembly);
            var packageId        = productAttribute.Product;

            var package = store.Manager.SourceRepository.GetUpdates(new[] { new PackageName(packageId, version) }, true, false).FirstOrDefault();

            // Check to see if an update is needed
            if (package != null && version < package.Version)
            {
                var movedFiles = new List <string>();

                // Copy files from tools\ to the current directory
                var          inputFiles    = package.GetFiles();
                const string directoryRoot = "tools\\"; // Important!: this is matching where files are store in the nuspec
                foreach (var file in inputFiles.Where(file => file.Path.StartsWith(directoryRoot)))
                {
                    var fileName = Path.Combine(store.RootDirectory, file.Path.Substring(directoryRoot.Length));

                    // Move previous files to .old
                    string renamedPath = fileName + ".old";

                    try
                    {
                        if (File.Exists(fileName))
                        {
                            Move(fileName, renamedPath);
                            movedFiles.Add(fileName);
                        }

                        // Update the file
                        UpdateFile(fileName, file);
                    }
                    catch (Exception)
                    {
                        // Revert all olds files if a file didn't work well
                        foreach (var oldFile in movedFiles)
                        {
                            renamedPath = oldFile + ".old";
                            Move(renamedPath, oldFile);
                        }
                        return;
                    }
                }


                // Remove .old files
                foreach (var oldFile in movedFiles)
                {
                    try
                    {
                        var renamedPath = oldFile + ".old";

                        if (File.Exists(renamedPath))
                        {
                            File.Delete(renamedPath);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }


                IsSelfUpdated = true;
            }
        }