Пример #1
0
 private LfxConfig(GitConfig gitConfig)
 {
     m_gitConfig  = gitConfig;
     m_configFile = new LfxConfigFile(m_gitConfig.ConfigFile);
     if (m_gitConfig.Parent != null)
     {
         m_parent = new LfxConfig(m_gitConfig.Parent);
     }
 }
Пример #2
0
        public static LfxPointer Create(string path, LfxHash?hash = null)
        {
            LfxPointer pointer;

            var length = new FileInfo(path).Length;

            if (hash == null)
            {
                hash = LfxHash.Compute(path);
            }
            pointer = Create(hash.Value, length);

            var config = LfxConfig.Load(path);

            // simple
            if (config.Type == LfxPointerType.Simple)
            {
                return(pointer);
            }

            var url     = config.Url;
            var relPath = config.ConfigFile.Path.MakeRelativePath(path);

            if (config.HasPattern)
            {
                // change base of relPath to config file containing pattern
                relPath = config.Pattern.ConfigFile.Path.MakeRelativePath(path);
                url     = Regex.Replace(
                    input: relPath,
                    pattern: config.Pattern,
                    replacement: config.Url
                    );
            }

            // curl
            if (config.Type == LfxPointerType.Curl)
            {
                return(pointer.AddUrl(url.ToUrl()));
            }

            // default hint is relPath
            var hint = relPath;

            if (config.HasHint)
            {
                // hardcoded hint (very rare)
                hint = config.Hint.Value;
                if (config.HasPattern)
                {
                    // substituted hint (nuget case)
                    hint = Regex.Replace(
                        input: relPath,
                        pattern: config.Pattern,
                        replacement: config.Hint
                        );
                }
            }

            // archive
            if (config.Type == LfxPointerType.Archive)
            {
                return(pointer.AddArchive(url.ToUrl(), hint));
            }

            // self extracting archive
            return(pointer.AddSelfExtractingArchive(url.ToUrl(), hint, config.Args));
        }