private void DeployResourcesInternal()

in csharp/NativeUtils/ResourceLoader.cs [715:768]


        private void DeployResourcesInternal(string deploymentPath)
        {
            byte[] inputData = this.InputBuffer;
            byte[] decompressedData = _outputBuffer;

            var fileList = _resources.ToList();
            fileList.Sort(
                (x, y) =>
                /* non-null(existing files) before non-null */
                null != x.File && null == y.File ? -1 :
                null == x.File && null != y.File ? 1 :
                /* otherwise, descending order by size */
                y.Length.CompareTo(x.Length)
            );

            Assembly _assembly = ResourceAssembly;
            foreach (var resource in fileList)
            {
                // If partial reuse is allowed and we already locked some files for read, do not deploy them
                if (null != resource.File)
                    continue;

                string filePath = resource.FullPath(deploymentPath);
                byte[] outputData = inputData;

                Log($"Reading {filePath}");
                using (var resourceStream = _assembly.GetManifestResourceStream(resource.ResourcePath))
                    ReadResourceFile(resourceStream, inputData, resource.Length);

                long outputLength = resource.Length;
                if (resource.IsZstd)
                {
                    outputLength = (long)ZStdDecompress.GetDecompressedSize(inputData);
                    if (null == decompressedData || outputLength > decompressedData.Length)
                        decompressedData = _outputBuffer = new byte[outputLength];

                    outputData = decompressedData;
                    ZStdDecompress.Decompress(decompressedData, inputData);
                }

                LockFileWatchdogUpdate();

                Log($"Writing {filePath}");
                using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                {
                    WriteResourceFile(fs, outputData, Convert.ToInt32(outputLength));
                    Log($"Done writing {filePath}, closing");
                    Dbg("last.lastWrittenFile", filePath);
                }

                Log($"After writing {filePath}, taking read lock");
                resource.ReadLock(filePath);
            }
        }