Ejemplo n.º 1
0
        /// <summary>
        /// Looks up 'fileIndexPath' on the server 'urlForServer' copying the file to 'symbolCacheDir' and returning the
        /// path name there (thus it is always a local file).  Unlike  GetPhysicalFileFromServer, GetFileFromServer understands
        /// how to deal with compressed files and file.ptr (redirection).  
        /// </summary>
        /// <returns>The path to a local file or null if the file cannot be found.</returns>
        private string GetFileFromServer(string urlForServer, string fileIndexPath, string symbolCacheDir, ISymbolNotification notification)
        {
            if (String.IsNullOrEmpty(urlForServer))
                return null;

            // Just try to fetch the file directly
            var ret = GetPhysicalFileFromServer(urlForServer, fileIndexPath, symbolCacheDir, notification);
            if (ret != null)
                return ret;

            var targetPath = Path.Combine(symbolCacheDir, fileIndexPath);

            // See if it is a compressed file by replacing the last character of the name with an _
            var compressedSigPath = fileIndexPath.Substring(0, fileIndexPath.Length - 1) + "_";
            var compressedFilePath = GetPhysicalFileFromServer(urlForServer, compressedSigPath, symbolCacheDir, notification);
            if (compressedFilePath != null)
            {
                // Decompress it
                _log.WriteLine("Expanding {0} to {1}", compressedFilePath, targetPath);
                Command.Run("Expand " + Command.Quote(compressedFilePath) + " " + Command.Quote(targetPath));
                File.Delete(compressedFilePath);
                notification.DecompressionComplete(targetPath);
                return targetPath;
            }

            // See if we have a file that tells us to redirect elsewhere. 
            var filePtrSigPath = Path.Combine(Path.GetDirectoryName(fileIndexPath), "file.ptr");
            var filePtrFilePath = GetPhysicalFileFromServer(urlForServer, filePtrSigPath, symbolCacheDir, notification);
            if (filePtrFilePath != null)
            {
                var filePtrData = File.ReadAllText(filePtrFilePath).Trim();
                if (filePtrData.StartsWith("PATH:"))
                    filePtrData = filePtrData.Substring(5);

                File.Delete(filePtrFilePath);
                // TODO FIX NOW can you use file.ptr to redirect to HTTP?

                if (!filePtrData.StartsWith("MSG:") && File.Exists(filePtrData))
                {
                    _log.WriteLine("Copying {0} to {1}", filePtrData, targetPath);
                    // TODO FIX NOW don't use copyFile as it is not very interruptable, and this can take a while over a network.  
                    File.Copy(filePtrData, targetPath, true);
                    return targetPath;
                }
                else
                    _log.WriteLine("Error resolving file.Ptr: content '{0}'", filePtrData);
            }
            return null;
        }