Google.JarResolver.PlayServicesSupport.CopyDependencies C# (CSharp) Méthode

CopyDependencies() public méthode

Copies the dependencies from the repository to the specified directory. The destination directory is checked for an existing version of the dependency before copying. The OverwriteConfirmation delegate is called for the first existing file or directory. If the delegate returns true, the old dependency is deleted and the new one copied.
public CopyDependencies ( Dependency>.Dictionary dependencies, string destDirectory, OverwriteConfirmation confirmer ) : void
dependencies Dependency>.Dictionary The dependencies to copy.
destDirectory string Destination directory.
confirmer OverwriteConfirmation Confirmer - the delegate for confirming overwriting.
Résultat void
        public void CopyDependencies(
            Dictionary<string, Dependency> dependencies,
            string destDirectory,
            OverwriteConfirmation confirmer)
        {
            if (!Directory.Exists(destDirectory))
            {
                Directory.CreateDirectory(destDirectory);
            }

            foreach (Dependency dep in dependencies.Values)
            {
                // match artifact-*.  The - is important to distinguish art-1.0.0
                // from artifact-1.0.0 (or base and basement).
                string[] dups = Directory.GetFileSystemEntries(destDirectory,
                                                               dep.Artifact + "-*");
                bool doCopy = true;
                bool doCleanup = false;
                foreach (string s in dups)
                {
                    // skip the .meta files (a little Unity creeps in).
                    if (s.EndsWith(".meta"))
                    {
                        continue;
                    }

                    // Strip the package extension from filenames.  Directories generated from
                    // unpacked AARs do not have extensions.
                    string existing = Directory.Exists(s) ? s :
                        Path.GetFileNameWithoutExtension(s);

                    // Extract the version from the filename.
                    // dep.Artifact is the name of the package (prefix)
                    // The regular expression extracts the version number from the filename
                    // handling filenames like foo-1.2.3-alpha.
                    string artifactName = existing.Substring(dep.Artifact.Length + 1);
                    System.Text.RegularExpressions.Match match =
                        System.Text.RegularExpressions.Regex.Match(artifactName, "^([0-9.]+)");
                    if (!match.Success) continue;
                    string artifactVersion = match.Groups[1].Value;

                    Dependency oldDep = new Dependency(dep.Group, artifactName, artifactVersion,
                                                       packageIds: dep.PackageIds,
                                                       repositories: dep.Repositories);

                    // add the artifact version so BestVersion == version.
                    oldDep.AddVersion(oldDep.Version);
                    // If the existing artifact matches the new dependency, don't modify it.
                    if (dep.Key == oldDep.Key) continue;
                    doCleanup = doCleanup || confirmer == null || confirmer(oldDep, dep);

                    if (doCleanup)
                    {
                        DeleteExistingFileOrDirectory(s);
                    }
                    else
                    {
                        doCopy = false;
                    }
                }

                if (doCopy)
                {
                    string aarFile = null;

                    // TODO(wilkinsonclay): get the extension from the pom file.
                    string baseName = null;
                    string extension = null;
                    foreach (string ext in Packaging)
                    {
                        string fname = Path.Combine(dep.BestVersionPath,
                            dep.Artifact + "-" + dep.BestVersion + ext);
                        if (File.Exists(fname))
                        {
                            baseName = dep.Artifact + "-" + dep.BestVersion;
                            aarFile = fname;
                            extension = ext;
                        }
                    }

                    if (aarFile != null)
                    {
                        string destName = Path.Combine(destDirectory, baseName) +
                            (extension == ".srcaar" ? ".aar" : extension);
                        string destNameUnpacked = Path.Combine(
                            destDirectory, Path.GetFileNameWithoutExtension(destName));
                        string existingName =
                            File.Exists(destName) ? destName :
                            Directory.Exists(destNameUnpacked) ? destNameUnpacked : null;

                        if (existingName != null)
                        {
                            doCopy = File.GetLastWriteTime(existingName).CompareTo(
                                File.GetLastWriteTime(aarFile)) < 0;
                            if (doCopy) DeleteExistingFileOrDirectory(existingName);
                        }
                        if (doCopy)
                        {
                            File.Copy(aarFile, destName);
                        }
                    }
                    else
                    {
                        throw new ResolutionException("Cannot find artifact for " +
                            dep);
                    }
                }
            }
        }

Usage Example

        /// <summary>
        /// Perform the resolution and the exploding/cleanup as needed.
        /// </summary>
        public override void DoResolution(PlayServicesSupport svcSupport,
                                          string destinationDirectory,
                                          PlayServicesSupport.OverwriteConfirmation handleOverwriteConfirmation)
        {
            // Get the collection of dependencies that need to be copied.
            Dictionary<string, Dependency> deps =
                svcSupport.ResolveDependencies(true);

            // Copy the list
            svcSupport.CopyDependencies(deps,
                destinationDirectory,
                handleOverwriteConfirmation);

            // we want to look at all the .aars to decide to explode or not.
            // Some aars have variables in their AndroidManifest.xml file,
            // e.g. ${applicationId}.  Unity does not understand how to process
            // these, so we handle it here.
            ProcessAars(destinationDirectory);
        }
All Usage Examples Of Google.JarResolver.PlayServicesSupport::CopyDependencies