Example #1
0
        private InstanceManager()
        {
            // Find the exe path
            ExeFilePath = Assembly.GetExecutingAssembly().Location;
            ExeDir      = ExeFilePath.SubstringRange(0, ExeFilePath.LastIndexOf('\\') + 1);
            // Check if this is an installed copy of Sky Jukebox
            var key = Registry.LocalMachine.OpenSubKey(@"Software\OronDF343\SkyJukebox");

            if (key != null)
            {
                Console.WriteLine("Installation detected");
                var loc = key.GetValue("InstallLocation");
                if (((string)loc).Trim('\"').Equals(ExeDir))
                {
                    Console.WriteLine("Loading from AppData");
                    UserDataDir = PathEx.Combine(new DirectoryInfoEx(KnownFolderIds.LocalAppData).FullName, "SkyJukebox");
                    if (!DirectoryEx.Exists(UserDataDir))
                    {
                        DirectoryEx.CreateDirectory(UserDataDir);
                    }
                    return;
                }
            }
            UserDataDir = ExeDir;
        }
Example #2
0
        protected override Task <object> RemoteExecuteAsync(IRemoteOperationExecutionContext context)
        {
            var sourcePath = context.ResolvePath(this.SourceDirectory);

            this.LogInformation($"Finding matching files in {sourcePath}...");
            if (!DirectoryEx.Exists(sourcePath))
            {
                this.LogError($"Directory {sourcePath} does not exist.");
                return(Complete);
            }

            var mask    = new MaskingContext(this.Includes, this.Excludes);
            var matches = DirectoryEx.GetFileSystemInfos(sourcePath, mask)
                          .OfType <SlimFileInfo>()
                          .Where(f => f.FullName.EndsWith(".sql", StringComparison.OrdinalIgnoreCase))
                          .ToList();

            if (matches.Count == 0)
            {
                this.LogError($"No matching .sql files were found in {sourcePath}.");
                return(Complete);
            }

            var outputFileName = context.ResolvePath(this.OutputFile);

            DirectoryEx.Create(PathEx.GetDirectoryName(outputFileName));

            using (var buffer = new TemporaryStream())
            {
                using (var zip = new ZipArchive(buffer, ZipArchiveMode.Create, true))
                {
                    foreach (var f in matches)
                    {
                        var entryName = getEntryName(f.FullName);
                        this.LogDebug($"Adding {entryName}...");
                        zip.CreateEntryFromFile(f.FullName, entryName, CompressionLevel.Optimal);
                    }
                }

                buffer.Position = 0;

                using (var outputStream = FileEx.Open(outputFileName, FileMode.Create, FileAccess.Write, FileShare.None, FileOptions.SequentialScan))
                {
                    using (var inedoSqlStream = typeof(BundleSqlScriptsOperation).Assembly.GetManifestResourceStream("Inedo.Extensions.SqlServer.Operations.inedosql.exe"))
                    {
                        inedoSqlStream.CopyTo(outputStream);
                    }

                    buffer.CopyTo(outputStream);
                }
            }

            this.LogInformation($"{outputFileName} created.");
            return(Complete);

            string getEntryName(string fullName) => fullName.Substring(0, sourcePath.Length).TrimStart('\\', '/').Replace('\\', '/');
        }
Example #3
0
 public override object ProvideValue(IServiceProvider serviceProvider)
 {
     if (!String.IsNullOrEmpty(FullPath))
         if (DirectoryEx.Exists(FullPath))
             return new DirectoryInfoEx(FullPath);
         else return new FileInfoEx(FullPath);
         
     return DirectoryInfoEx.DesktopDirectory;
 }
        public override Task <IEnumerable <string> > EnumerateRemoteBranchesAsync()
        {
            try
            {
                this.BeginOperation();

                this.log.LogDebug("Enumerating remote branches...");

                if (!Repository.IsValid(this.repository.LocalRepositoryPath))
                {
                    this.log.LogDebug($"Repository not found at '{this.repository.LocalRepositoryPath}'...");
                    if (DirectoryEx.Exists(this.repository.LocalRepositoryPath))
                    {
                        var contents = DirectoryEx.GetFileSystemInfos(this.repository.LocalRepositoryPath, MaskingContext.Default);
                        if (contents.Count > 0)
                        {
                            throw new InvalidOperationException("Specified local repository path is invalid.");
                        }
                    }

                    var refs = Repository.ListRemoteReferences(this.repository.RemoteRepositoryUrl, this.CredentialsHandler);

                    var trimmedRefs = (from r in refs
                                       where r.CanonicalName.StartsWith("refs/heads/")
                                       let trimmed = r.CanonicalName.Substring("refs/heads/".Length)
                                                     select trimmed).ToList();

                    return(Task.FromResult(trimmedRefs.AsEnumerable()));
                }
                else
                {
                    this.log.LogDebug($"Repository found at '{this.repository.LocalRepositoryPath}'...");
                    using (var repository = new Repository(this.repository.LocalRepositoryPath))
                    {
                        var origin = repository.Network.Remotes["origin"];
                        this.log.LogDebug($"Using remote: origin, '{origin.Name}'.");
                        var refs = repository.Network.ListReferences(origin);

                        var trimmedRefs = (from r in refs
                                           where r.CanonicalName.StartsWith("refs/heads/")
                                           let trimmed = r.CanonicalName.Substring("refs/heads/".Length)
                                                         select trimmed).ToList();

                        return(Task.FromResult(trimmedRefs.AsEnumerable()));
                    }
                }
            }
            catch (Exception ex)
            {
                // gitsharp exceptions are not always serializable
                throw new ExecutionFailureException(ex.Message);
            }
            finally
            {
                this.EndOperation();
            }
        }
        protected override Repository OpenRepository()
        {
            if (DirectoryEx.Exists(this.LocalRepositoryPath))
            {
                if (Repository.IsValid(this.LocalRepositoryPath))
                {
                    var repository = new Repository(this.LocalRepositoryPath);

                    if (!string.IsNullOrEmpty(this.RemoteRepositoryUrl))
                    {
                        Commands.Fetch(repository, "origin", Enumerable.Empty <string>(),
                                       new FetchOptions {
                            CredentialsProvider = CredentialsHandler
                        }, null);
                        if (repository.Refs["refs/heads/" + this.BranchName] == null)
                        {
                            //Must use an ObjectId to create a DirectReference (SymbolicReferences will cause an error when committing)
                            var objId = new ObjectId(repository.Refs["refs/remotes/origin/" + this.BranchName].TargetIdentifier);
                            repository.Refs.Add("refs/heads/" + this.BranchName, objId);
                        }
                        repository.Refs.UpdateTarget("refs/heads/" + this.BranchName, "refs/remotes/origin/" + this.BranchName);
                    }

                    return(repository);
                }

                if (DirectoryEx.GetFileSystemInfos(this.LocalRepositoryPath, MaskingContext.Default).Any())
                {
                    throw new InvalidOperationException("The specified local repository path does not appear to be a Git repository but already contains files or directories.");
                }
            }
            else
            {
                DirectoryEx.Create(this.LocalRepositoryPath);
            }

            if (!string.IsNullOrEmpty(this.RemoteRepositoryUrl))
            {
                Repository.Clone(
                    this.RemoteRepositoryUrl,
                    this.LocalRepositoryPath,
                    new CloneOptions
                {
                    CredentialsProvider = this.CredentialsHandler,
                    IsBare = true
                }
                    );
            }
            else
            {
                Repository.Init(this.LocalRepositoryPath, true);
            }

            return(new Repository(this.LocalRepositoryPath));
        }
Example #6
0
        public static bool TryCreate(string archiveRootDirectoryPath, out ArchiveRoot archivar)
        {
            archivar = null;

            if (!DirectoryEx.Exists(archiveRootDirectoryPath))
            {
                return(false);
            }

            archivar = new ArchiveRoot(archiveRootDirectoryPath);
            return(true);
        }
Example #7
0
        protected override async Task <object> RemoteExecuteAsync(IRemoteOperationExecutionContext context)
        {
            var projectFullPath = context.ResolvePath(this.ProjectPath);

            this.LogInformation($"Building {projectFullPath}...");

            var buildProperties = string.Join(";", this.MSBuildProperties ?? Enumerable.Empty <string>());

            var config = "Configuration=" + this.BuildConfiguration;

            if (!string.IsNullOrEmpty(this.TargetPlatform))
            {
                config += ";Platform=" + this.TargetPlatform;
            }

            if (!string.IsNullOrEmpty(buildProperties))
            {
                config += ";" + buildProperties;
            }

            var args = $"\"{projectFullPath}\" \"/p:{config}\"";

            if (!string.IsNullOrWhiteSpace(this.TargetDirectory))
            {
                args += $" \"/p:OutDir={context.ResolvePath(this.TargetDirectory).TrimEnd('\\')}\\\\\"";
            }

            if (!string.IsNullOrWhiteSpace(this.AdditionalArguments))
            {
                args += " " + this.AdditionalArguments;
            }

            var workingDir = PathEx.GetDirectoryName(projectFullPath);

            if (!DirectoryEx.Exists(workingDir))
            {
                throw new DirectoryNotFoundException($"Directory {workingDir} does not exist.");
            }

            int result = await this.InvokeMSBuildAsync(context, args, workingDir).ConfigureAwait(false);

            if (result != 0)
            {
                this.LogError($"Build failed (msbuild returned {result}).");
            }

            return(null);
        }
Example #8
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (!String.IsNullOrEmpty(FullPath))
            {
                if (DirectoryEx.Exists(FullPath))
                {
                    return(new DirectoryInfoEx(FullPath));
                }
                else
                {
                    return(new FileInfoEx(FullPath));
                }
            }

            return(DirectoryInfoEx.DesktopDirectory);
        }
        public void Expand(FileListViewModel _rootModel, ExModel dirModel)
        {
            if (_rootModel != null)
            {
                EmbeddedModel = dirModel;
                if (EmbeddedModel is DirectoryModel)
                {
                    _rootModel.CurrentDirectory = (EmbeddedModel as DirectoryModel).EmbeddedDirectoryEntry;
                }
                else
                {
                    try
                    {
#if true
                        FileSystemInfoEx entry = EmbeddedModel.EmbeddedEntry;
#else
                        FileSystemInfoEx entry = EmbeddedModel.EmbeddedEntry;
#endif

                        if (PathEx.GetExtension(entry.Name).ToLower() == ".lnk")
                        {
                            using (ShellLink sl = new ShellLink(entry.FullName))
                            {
                                string linkPath = sl.Target;
                                if (DirectoryEx.Exists(linkPath) && sl.Arguments == "")
                                {
                                    _rootModel.CurrentDirectory = FileSystemInfoEx.FromString(linkPath) as DirectoryInfoEx;
                                }
                                else
                                {
                                    Run(linkPath, sl.Arguments);
                                }
                            }
                        }
                        else
                        {
                            Run(entry.FullName, "");
                        }
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show(ex.Message, "Expand Failed");
                    }
                }
            }
        }
Example #10
0
        public static bool TryCreate(IDirectoryInfo assetDirectory, IFileSystemItem parent, out IFileSystemItem directory)
        {
            directory = null;

            if (!DirectoryEx.Exists(assetDirectory.FullName))
            {
                return(false);
            }

            var name = assetDirectory.Name;

            if (_allowedNames.All(item => item != name))
            {
                return(false);
            }

            directory = new ClubDirectory(assetDirectory, parent);
            return(true);
        }
 private async void PlaylistView_OnDrop(object sender, DragEventArgs e)
 {
     SpinningGear.Visibility = Visibility.Visible;
     foreach (var s in (string[])e.Data.GetData(DataFormats.FileDrop, false))
     {
         if (DirectoryEx.Exists(s))
         {
             await FileUtils.AddFolder(FileSystemInfoEx.FromString(s) as DirectoryInfoEx, true, FileSystemUtils.DefaultLoadErrorCallback);
         }
         else if (PlaylistDataManager.Instance.HasReader(s.GetExt()))
         {
             Playlist.AddRange(s, FileSystemUtils.DefaultLoadErrorCallback);
         }
         else if (PlaybackManagerInstance.HasSupportingPlayer(s.GetExt()))
         {
             Playlist.Add(MusicInfo.Create(FileSystemInfoEx.FromString(s) as FileInfoEx, FileSystemUtils.DefaultLoadErrorCallback));
         }
     }
     SpinningGear.Visibility = Visibility.Hidden;
 }
Example #12
0
        private static void CopyNonTfsFiles(string sourceDir, string targetDir)
        {
            if (!DirectoryEx.Exists(sourceDir))
            {
                return;
            }

            DirectoryEx.Create(targetDir);

            var sourceDirInfo = new DirectoryInfo(sourceDir);

            foreach (var file in sourceDirInfo.GetFiles())
            {
                file.CopyTo(PathEx.Combine(targetDir, file.Name), true);
            }

            foreach (var subDir in sourceDirInfo.GetDirectories().Where(d => d.Name != "$tf"))
            {
                CopyNonTfsFiles(subDir.FullName, PathEx.Combine(targetDir, subDir.Name));
            }
        }
Example #13
0
        private void App_Startup(object sender, StartupEventArgs e)
        {
            // Load skins:
            if (!DirectoryEx.Exists(InstanceManager.Instance.SkinsFolderPath))
            {
                DirectoryEx.CreateDirectory(InstanceManager.Instance.SkinsFolderPath);
            }
            SkinManager.Instance.LoadAllSkins(InstanceManager.Instance.SkinsFolderPath);

            // Load settings:
            SettingsManager.Init(InstanceManager.Instance.SettingsFilePath);

            // Set skin:
            if (!IconManager.Instance.LoadFromSkin((string)SettingsManager.Instance["SelectedSkin"].Value))
            {
                MessageBox.Show("Failed to load skin: " + SettingsManager.Instance["SelectedSkin"].Value, "Error", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                SettingsManager.Instance["SelectedSkin"].ResetValue();
                if (!IconManager.Instance.LoadFromSkin((string)SettingsManager.Instance["SelectedSkin"].Value))
                {
                    MessageBox.Show("Failed to load fallback default skin!", "This is a bug!", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }
            }

            // Load key bindings:
            KeyBindingManager.Init(InstanceManager.Instance.KeyConfigFilePath);
            //
            KeyBindingManager.Instance.Disable = !(bool)SettingsManager.Instance["EnableGlobalKeyBindings"].Value;
            SettingsManager.Instance["EnableGlobalKeyBindings"].PropertyChanged +=
                (s, args) => KeyBindingManager.Instance.Disable = !(bool)SettingsManager.Instance["EnableGlobalKeyBindings"].Value;

            // Load plugins:
            // VERY IMPORTANT: Force evaluation of IEnumerable
            InstanceManager.Instance.LoadedExtensions = ExtensionLoader.GetCompatibleExtensions <IExtension>(Lib.PathStringUtils.GetExePath()).ToList();
            _extAccess = new ExtensionAccess();
            foreach (var ex in InstanceManager.Instance.LoadedExtensions)
            {
                ex.Instance.Init(_extAccess);
            }
        }
Example #14
0
 public override async Task <IEntryModel> ParseAsync(string path)
 {
     return(await Task <IEntryModel> .Factory.StartNew(() =>
     {
         IEntryModel retVal = null;
         if (String.IsNullOrEmpty(path))
         {
             retVal = new FileSystemInfoExModel(this, DirectoryInfoEx.DesktopDirectory);
         }
         else
         if (path.StartsWith("::"))
         {
             if (DirectoryEx.Exists(path))
             {
                 retVal = new FileSystemInfoExModel(this, createDirectoryInfo(path));
             }
             else
             if (FileEx.Exists(path))
             {
                 retVal = new FileSystemInfoExModel(this, createFileInfo(path));
             }
         }
         else
         {
             if (Directory.Exists(path))
             {
                 retVal = new FileSystemInfoExModel(this, createDirectoryInfo(path));
             }
             else
             if (File.Exists(path))
             {
                 retVal = new FileSystemInfoExModel(this, createFileInfo(path));
             }
         }
         return Converters.Convert(retVal);
     }));
 }
Example #15
0
        public override Task <IEnumerable <RemoteBranchInfo> > EnumerateRemoteBranchesAsync()
        {
            bool endOperation = false;

            try
            {
                this.log.LogDebug("Enumerating remote branches...");

                if (!this.repository.HasLocalRepository || !Repository.IsValid(this.repository.LocalRepositoryPath))
                {
                    if (this.repository.HasLocalRepository)
                    {
                        this.log.LogDebug($"Repository not found at '{this.repository.LocalRepositoryPath}'...");
                    }

                    if (this.repository.HasLocalRepository && DirectoryEx.Exists(this.repository.LocalRepositoryPath))
                    {
                        var contents = DirectoryEx.GetFileSystemInfos(this.repository.LocalRepositoryPath, MaskingContext.Default);
                        if (contents.Count > 0)
                        {
                            throw new InvalidOperationException("Specified local repository path is invalid.");
                        }
                    }

                    var refs = Repository.ListRemoteReferences(this.repository.RemoteRepositoryUrl, this.CredentialsHandler);
                    return(Task.FromResult(getBranches(refs)));
                }
                else
                {
                    this.BeginOperation();
                    endOperation = true;

                    this.log.LogDebug($"Repository found at '{this.repository.LocalRepositoryPath}'...");
                    using (var repository = new Repository(this.repository.LocalRepositoryPath))
                    {
                        var origin = repository.Network.Remotes["origin"];
                        this.log.LogDebug($"Using remote: origin, '{origin.Name}'.");
                        var refs = repository.Network.ListReferences(origin);
                        return(Task.FromResult(getBranches(refs)));
                    }
                }
            }
            catch (Exception ex)
            {
                // gitsharp exceptions are not always serializable
                throw new ExecutionFailureException(ex.Message);
            }
            finally
            {
                if (endOperation)
                {
                    this.EndOperation();
                }
            }

            IEnumerable <RemoteBranchInfo> getBranches(IEnumerable <Reference> refs)
            {
                var branches = new HashSet <RemoteBranchInfo>();

                foreach (var r in refs)
                {
                    var direct = r.ResolveToDirectReference();
                    if (direct.CanonicalName.StartsWith("refs/heads/"))
                    {
                        branches.Add(new RemoteBranchInfo(direct.CanonicalName.Substring("refs/heads/".Length), direct.TargetIdentifier));
                    }
                }

                return(branches.ToArray());
            }
        }