コード例 #1
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            User user = WebsitesClient.GetPublishingCredentials(ResourceGroupName, Name, Slot);

            HttpResponseMessage r;
            string deployUrl;
            string deploymentStatusUrl = user.ScmUri + "/api/deployments/latest";

            if (ArchivePath.ToLower().EndsWith("war"))
            {
                deployUrl = user.ScmUri + "/api/wardeploy?isAsync=true";
            }
            else if (ArchivePath.ToLower().EndsWith("zip") || ArchivePath.ToLower().EndsWith("jar"))
            {
                deployUrl = user.ScmUri + "/api/zipdeploy?isAsync=true";
            }
            else
            {
                throw new Exception("Unknown archive type.");
            }

            Action zipDeployAction = () =>
            {
                using (var s = File.OpenRead(ArchivePath))
                {
                    HttpClient client    = new HttpClient();
                    var        byteArray = Encoding.ASCII.GetBytes(user.PublishingUserName + ":" + user.PublishingPassword);
                    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
                    HttpContent fileContent = new StreamContent(s);
                    fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("multipart/form-data");
                    r = client.PostAsync(deployUrl, fileContent).Result;

                    int numChecks = 0;
                    do
                    {
                        Thread.Sleep(TimeSpan.FromSeconds(2));
                        r = client.GetAsync(deploymentStatusUrl).Result;
                        numChecks++;
                    } while (r.StatusCode == HttpStatusCode.Accepted && numChecks < NumStatusChecks);

                    if (r.StatusCode == HttpStatusCode.Accepted && numChecks >= NumStatusChecks)
                    {
                        var rec = new ErrorRecord(new Exception("Maximum status polling time exceeded. Deployment is still in progress."), string.Empty, ErrorCategory.OperationTimeout, null);
                        WriteError(rec);
                    }
                    else if (r.StatusCode != HttpStatusCode.OK)
                    {
                        var rec = new ErrorRecord(new Exception("Deployment failed with status code " + r.StatusCode), string.Empty, ErrorCategory.InvalidResult, null);
                        WriteError(rec);
                    }
                }
            };

            ConfirmAction(this.Force.IsPresent, $"Contents of {ArchivePath} will be deployed to the web app {Name}.", "The web app has been deployed.", Name, zipDeployAction);

            PSSite app = new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, Name, Slot));

            WriteObject(app);
        }
コード例 #2
0
        private string GetUpdatedArchivePath(ArchiveTypeViewModel previous, ArchiveTypeViewModel current)
        {
            var currentExtensionLength      = previous?.Name?.Length ?? 0;
            var archivePathWithoutExtension = ArchivePath.Substring(0, ArchivePath.Length - currentExtensionLength);

            return($"{archivePathWithoutExtension}{current.Name}");
        }
コード例 #3
0
 public virtual void ArchiveFile(RFFileAvailableEvent availableFile)
 {
     if (ArchivePath.NotBlank())
     {
         var destinationPath = CombinePath(ArchivePath, availableFile.FileAttributes.FileName);
         MoveFile(availableFile.FileAttributes.FullPath, destinationPath);
     }
 }
コード例 #4
0
        public FluentFileDecompressor Decompress()
        {
            if (string.IsNullOrWhiteSpace(OutputDirectory) || string.IsNullOrWhiteSpace(ArchivePath))
            {
                throw new InvalidOperationException("Output and Archive paths should be defined.");
            }

            if (ArchivePath.EndsWith(".rar"))
            {
                DecompressRar();
            }

            return(this);
        }
コード例 #5
0
        /// <summary>
        /// Builds the installation queues for the mod. Item 1 is the unpacked job mappings (per modjob) along with the list of custom dlc folders being installed. Item 2 is the list of modjobs, their sfar paths, and the list of source files to install for SFAR jobs.
        /// </summary>
        /// <param name="gameTarget"></param>
        /// <returns></returns>
        public (Dictionary <ModJob, (Dictionary <string, InstallSourceFile> unpackedJobMapping, List <string> dlcFoldersBeingInstalled)>, List <(ModJob job, string sfarPath, Dictionary <string, InstallSourceFile>)>) GetInstallationQueues(GameTarget gameTarget)
        {
            if (IsInArchive)
            {
#if DEBUG
                if (Archive.IsDisposed())
                {
                    Debug.WriteLine(@">>> ARCHIVE IS DISPOSED");
                }
#endif
                if (File.Exists(ArchivePath) && (Archive == null || Archive.IsDisposed()))
                {
                    Archive = new SevenZipExtractor(ArchivePath); //load archive file for inspection
                }
                else if (Archive != null && Archive.GetBackingStream() is SevenZip.ArchiveEmulationStreamProxy aesp && aesp.Source is MemoryStream ms)
                {
                    var isExe = ArchivePath.EndsWith(@".exe", StringComparison.InvariantCultureIgnoreCase);
                    Archive = isExe ? new SevenZipExtractor(ms, InArchiveFormat.Nsis) : new SevenZipExtractor(ms);
                    MemoryAnalyzer.AddTrackedMemoryItem($@"Re-opened SVE archive for {ModName}", new WeakReference(Archive));
                }
            }
            var gameDLCPath      = M3Directories.GetDLCPath(gameTarget);
            var customDLCMapping = Enumerable.FirstOrDefault <ModJob>(InstallationJobs, x => x.Header == ModJob.JobHeader.CUSTOMDLC)?.CustomDLCFolderMapping;
            if (customDLCMapping != null)
            {
                //Make clone so original value is not modified
                customDLCMapping = new Dictionary <string, string>(customDLCMapping); //prevent altering the source object
            }

            var unpackedJobInstallationMapping = new Dictionary <ModJob, (Dictionary <string, InstallSourceFile> mapping, List <string> dlcFoldersBeingInstalled)>();
            var sfarInstallationJobs           = new List <(ModJob job, string sfarPath, Dictionary <string, InstallSourceFile> installationMapping)>();
            foreach (var job in InstallationJobs)
            {
                Log.Information($@"Preprocessing installation job: {job.Header}");
                var alternateFiles = Enumerable.Where <AlternateFile>(job.AlternateFiles, x => x.IsSelected && x.Operation != AlternateFile.AltFileOperation.OP_NOTHING &&
                                                                      x.Operation != AlternateFile.AltFileOperation.OP_NOINSTALL_MULTILISTFILES).ToList();
                var alternateDLC = Enumerable.Where <AlternateDLC>(job.AlternateDLCs, x => x.IsSelected).ToList();
                if (job.Header == ModJob.JobHeader.CUSTOMDLC)
                {
                    #region Installation: CustomDLC
                    //Key = destination file, value = source file to install
                    var installationMapping = new Dictionary <string, InstallSourceFile>();
                    unpackedJobInstallationMapping[job] = (installationMapping, new List <string>());
                    foreach (var altdlc in alternateDLC)
                    {
                        if (altdlc.Operation == AlternateDLC.AltDLCOperation.OP_ADD_CUSTOMDLC)
                        {
                            customDLCMapping[altdlc.AlternateDLCFolder] = altdlc.DestinationDLCFolder;
                        }
                    }

                    foreach (var mapping in customDLCMapping)
                    {
                        //Mapping is done as DESTINATIONFILE = SOURCEFILE so you can override keys
                        var source = FilesystemInterposer.PathCombine(IsInArchive, ModPath, mapping.Key);
                        var target = Path.Combine(gameDLCPath, mapping.Value);

                        //get list of all normal files we will install
                        var allSourceDirFiles = FilesystemInterposer.DirectoryGetFiles(source, "*", SearchOption.AllDirectories, Archive).Select(x => x.Substring(ModPath.Length).TrimStart('\\')).ToList();
                        unpackedJobInstallationMapping[job].dlcFoldersBeingInstalled.Add(target);
                        //loop over every file
                        foreach (var sourceFile in allSourceDirFiles)
                        {
                            //Check against alt files
                            bool altApplied = false;
                            foreach (var altFile in alternateFiles)
                            {
                                if (altFile.ModFile.Equals(sourceFile, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    //Alt applies to this file
                                    switch (altFile.Operation)
                                    {
                                    case AlternateFile.AltFileOperation.OP_NOINSTALL:
                                        CLog.Information($@"Not installing {sourceFile} for Alternate File {altFile.FriendlyName} due to operation OP_NOINSTALL", Settings.LogModInstallation);
                                        //we simply don't map as we just do a continue below.
                                        altApplied = true;
                                        break;

                                    case AlternateFile.AltFileOperation.OP_SUBSTITUTE:
                                        CLog.Information($@"Repointing {sourceFile} to {altFile.AltFile} for Alternate File {altFile.FriendlyName} due to operation OP_SUBSTITUTE", Settings.LogModInstallation);
                                        if (job.JobDirectory != null && altFile.AltFile.StartsWith((string)job.JobDirectory))
                                        {
                                            installationMapping[sourceFile] = new InstallSourceFile(altFile.AltFile.Substring(job.JobDirectory.Length).TrimStart('/', '\\'))
                                            {
                                                AltApplied             = true,
                                                IsFullRelativeFilePath = true
                                            };    //use alternate file as key instead
                                        }
                                        else
                                        {
                                            installationMapping[sourceFile] = new InstallSourceFile(altFile.AltFile)
                                            {
                                                AltApplied = true, IsFullRelativeFilePath = true
                                            };                                                                                                                                 //use alternate file as key instead
                                        }
                                        altApplied = true;
                                        break;

                                    case AlternateFile.AltFileOperation.OP_INSTALL:
                                        //same logic as substitute, just different logging.
                                        CLog.Information($@"Adding {sourceFile} to install (from {altFile.AltFile}) as part of Alternate File {altFile.FriendlyName} due to operation OP_INSTALL", Settings.LogModInstallation);
                                        if (job.JobDirectory != null && altFile.AltFile.StartsWith((string)job.JobDirectory))
                                        {
                                            installationMapping[sourceFile] = new InstallSourceFile(altFile.AltFile.Substring(job.JobDirectory.Length).TrimStart('/', '\\'))
                                            {
                                                AltApplied             = true,
                                                IsFullRelativeFilePath = true
                                            };     //use alternate file as key instead
                                        }
                                        else
                                        {
                                            installationMapping[sourceFile] = new InstallSourceFile(altFile.AltFile)
                                            {
                                                AltApplied = true, IsFullRelativeFilePath = true
                                            };                                                                                                                                 //use alternate file as key instead
                                        }
                                        altApplied = true;
                                        break;
                                    }
                                    break;
                                }
                            }

                            if (altApplied)
                            {
                                continue;             //no further processing for file
                            }
                            var    relativeDestStartIndex = sourceFile.IndexOf(mapping.Value);
                            string destPath = sourceFile.Substring(relativeDestStartIndex);
                            installationMapping[destPath] = new InstallSourceFile(sourceFile); //destination is mapped to source file that will replace it.
                        }

                        foreach (var altdlc in alternateDLC)
                        {
                            if (altdlc.Operation == AlternateDLC.AltDLCOperation.OP_ADD_FOLDERFILES_TO_CUSTOMDLC)
                            {
                                string alternatePathRoot = FilesystemInterposer.PathCombine(IsInArchive, ModPath, altdlc.AlternateDLCFolder);
                                var    filesToAdd        = FilesystemInterposer.DirectoryGetFiles(alternatePathRoot, "*", SearchOption.AllDirectories, Archive).Select(x => x.Substring(ModPath.Length).TrimStart('\\')).ToList();
                                foreach (var fileToAdd in filesToAdd)
                                {
                                    var destFile = Path.Combine(altdlc.DestinationDLCFolder, fileToAdd.Substring(altdlc.AlternateDLCFolder.Length).TrimStart('\\', '/'));
                                    CLog.Information($@"Adding extra CustomDLC file ({fileToAdd} => {destFile}) due to Alternate DLC {altdlc.FriendlyName}'s {altdlc.Operation}", Settings.LogModInstallation);

                                    installationMapping[destFile] = new InstallSourceFile(fileToAdd)
                                    {
                                        AltApplied = true
                                    };
                                }
                            }
                            else if (altdlc.Operation == AlternateDLC.AltDLCOperation.OP_ADD_MULTILISTFILES_TO_CUSTOMDLC)
                            {
                                string alternatePathRoot = FilesystemInterposer.PathCombine(IsInArchive, ModPath, altdlc.MultiListRootPath);
                                foreach (var fileToAdd in altdlc.MultiListSourceFiles)
                                {
                                    var sourceFile = FilesystemInterposer.PathCombine(IsInArchive, alternatePathRoot, fileToAdd).Substring(ModPath.Length).TrimStart('\\');
                                    var destFile   = Path.Combine(altdlc.DestinationDLCFolder, fileToAdd.TrimStart('\\', '/'));
                                    CLog.Information($@"Adding extra CustomDLC file (MultiList) ({sourceFile} => {destFile}) due to Alternate DLC {altdlc.FriendlyName}'s {altdlc.Operation}", Settings.LogModInstallation);

                                    installationMapping[destFile] = new InstallSourceFile(sourceFile)
                                    {
                                        AltApplied = true
                                    };
                                }
                            }
                        }

                        // Process altfile removal of multilist, since it should be done last
                        var fileRemoveAltFiles = Enumerable.Where <AlternateFile>(job.AlternateFiles, x => x.IsSelected && x.Operation == AlternateFile.AltFileOperation.OP_NOINSTALL_MULTILISTFILES);
                        foreach (var altFile in fileRemoveAltFiles)
                        {
                            foreach (var multifile in altFile.MultiListSourceFiles)
                            {
                                CLog.Information($@"Attempting to remove multilist file {multifile} from install (from {altFile.MultiListTargetPath}) as part of Alternate File {altFile.FriendlyName} due to operation OP_NOINSTALL_MULTILISTFILES", Settings.LogModInstallation);
                                string relativeSourcePath = altFile.MultiListRootPath + '\\' + multifile;

                                var targetPath = altFile.MultiListTargetPath + '\\' + multifile;
                                if (installationMapping.Remove(targetPath))
                                {
                                    CLog.Information($@" > Removed multilist file {targetPath} from installation",
                                                     Settings.LogModInstallation);
                                }
                            }
                        }
                    }
                    #endregion
                }
                else if (job.Header == ModJob.JobHeader.LOCALIZATION)
                {
                    #region Installation: LOCALIZATION
                    var installationMapping = new CaseInsensitiveDictionary <InstallSourceFile>();
                    unpackedJobInstallationMapping[job] = (installationMapping, new List <string>());
                    buildInstallationQueue(job, installationMapping, false);
                    #endregion
                }
                else if (job.Header == ModJob.JobHeader.BASEGAME || job.Header == ModJob.JobHeader.BALANCE_CHANGES || job.Header == ModJob.JobHeader.ME1_CONFIG)
                {
                    #region Installation: BASEGAME, BALANCE CHANGES, ME1 CONFIG
                    var installationMapping = new CaseInsensitiveDictionary <InstallSourceFile>();
                    unpackedJobInstallationMapping[job] = (installationMapping, new List <string>());
                    buildInstallationQueue(job, installationMapping, false);
                    #endregion
                }
                else if (Game == MEGame.ME3 && ModJob.ME3SupportedNonCustomDLCJobHeaders.Contains(job.Header)) //previous else if will catch BASEGAME
                {
                    #region Installation: DLC Unpacked and SFAR (ME3 ONLY)

                    if (M3Directories.IsOfficialDLCInstalled(job.Header, gameTarget))
                    {
                        string sfarPath = job.Header == ModJob.JobHeader.TESTPATCH ? M3Directories.GetTestPatchSFARPath(gameTarget) : Path.Combine(gameDLCPath, ModJob.GetHeadersToDLCNamesMap(MEGame.ME3)[job.Header], @"CookedPCConsole", @"Default.sfar");


                        if (File.Exists(sfarPath))
                        {
                            var installationMapping = new CaseInsensitiveDictionary <InstallSourceFile>();
                            if (new FileInfo(sfarPath).Length == 32)
                            {
                                //Unpacked
                                unpackedJobInstallationMapping[job] = (installationMapping, new List <string>());
                                buildInstallationQueue(job, installationMapping, false);
                            }
                            else
                            {
                                //Packed
                                //unpackedJobInstallationMapping[job] = installationMapping;
                                buildInstallationQueue(job, installationMapping, true);
                                sfarInstallationJobs.Add((job, sfarPath, installationMapping));
                            }
                        }
                    }
                    else
                    {
                        Log.Warning($@"DLC not installed, skipping: {job.Header}");
                    }
                    #endregion
                }
                else if (Game == MEGame.ME2 || Game == MEGame.ME1)
                {
                    #region Installation: DLC Unpacked (ME1/ME2 ONLY)
                    //Unpacked
                    if (M3Directories.IsOfficialDLCInstalled(job.Header, gameTarget))
                    {
                        var installationMapping = new CaseInsensitiveDictionary <InstallSourceFile>();
                        unpackedJobInstallationMapping[job] = (installationMapping, new List <string>());
                        buildInstallationQueue(job, installationMapping, false);
                    }
                    else
                    {
                        Log.Warning($@"DLC not installed, skipping: {job.Header}");
                    }

                    #endregion
                }
                else
                {
                    //?? Header
                    throw new Exception(@"Unsupported installation job header! " + job.Header);
                }
            }

            return(unpackedJobInstallationMapping, sfarInstallationJobs);
        }
コード例 #6
0
        /// <summary>
        /// This function searches through all the IFFs in the game to
        /// find chunks of the type specified by the user.
        /// </summary>
        private void ScanIFFs()
        {
            string ObjDataPath = "", HouseDataPath = "";
            bool   LookingForSprites = false;

            if (m_TSOPath != "" || TxtTSOPath.Text != "")
            {
                if (TxtChunkType.Text != "")
                {
                    if (TxtChunkType.Text.Contains("SPR#") || TxtChunkType.Text.Contains("SPR2") ||
                        TxtChunkType.Text.Contains("DGRP"))
                    {
                        LookingForSprites = true;
                    }

                    string[] Dirs = Directory.GetDirectories(m_TSOPath);

                    foreach (string Dir in Dirs)
                    {
                        if (Dir.Contains("objectdata"))
                        {
                            ObjDataPath = Dir;
                        }

                        if (Dir.Contains("housedata"))
                        {
                            HouseDataPath = Dir;
                        }
                    }

                    string[] ObjDataDirs   = Directory.GetDirectories(ObjDataPath);
                    string[] HouseDataDirs = Directory.GetDirectories(HouseDataPath);

                    foreach (string Dir in ObjDataDirs)
                    {
                        string[] Files = Directory.GetFiles(Dir);

                        foreach (string ArchivePath in Files)
                        {
                            if (ArchivePath.Contains(".far"))
                            {
                                FARArchive Archive = new FARArchive(ArchivePath);
                                List <KeyValuePair <string, byte[]> > ArchiveFiles = Archive.GetAllEntries();

                                foreach (KeyValuePair <string, byte[]> ArchiveFile in ArchiveFiles)
                                {
                                    if (!LookingForSprites)
                                    {
                                        //Skip the OTFs in 'objotf.far'...
                                        if (ArchiveFile.Key.Contains(".iff"))
                                        {
                                            Iff             IffFile;
                                            List <IffChunk> Chunks    = new List <IffChunk>();
                                            int             NumChunks = 0;

                                            LblScanning.Invoke(m_OnUpdateStatus, new object[] { ArchiveFile.Key });

                                            if (!m_Debug)
                                            {
                                                IffFile = new Iff(ArchiveFile.Value, ArchiveFile.Key);
                                            }
                                            else
                                            {
                                                IffFile = new Iff(ArchiveFile.Value);
                                            }

                                            //Figure out how many chunks of the type being searched for
                                            //is in the current IFF archive. Is there a faster way to do this?
                                            foreach (IffChunk Chunk in IffFile.Chunks)
                                            {
                                                if (Chunk.Resource == TxtChunkType.Text)
                                                {
                                                    NumChunks++;
                                                }
                                            }

                                            List <IffInfo> InfoList = new List <IffInfo>();

                                            foreach (IffChunk Chunk in IffFile.Chunks)
                                            {
                                                if (Chunk.Resource == TxtChunkType.Text)
                                                {
                                                    LstChunkTypes.Invoke(m_OnFoundChunk, new object[] { ArchiveFile.Key });

                                                    IffInfo Info = new IffInfo();
                                                    Info.ArchivePath = ArchivePath;
                                                    Info.IffName     = ArchiveFile.Key;
                                                    Info.NumChunks   = NumChunks;

                                                    InfoList.Add(Info);
                                                }
                                            }

                                            m_IffInfoList.Add(Path.GetFileName(ArchivePath) + "\\" + ArchiveFile.Key, InfoList);
                                        }
                                    }
                                    else
                                    {
                                        Iff IffFile;
                                        int NumChunks = 0;

                                        if (ArchiveFile.Key.Contains(".spf") || ArchiveFile.Key.Contains(".wll") || ArchiveFile.Key.Contains(".flr"))
                                        {
                                            LblScanning.Invoke(m_OnUpdateStatus, new object[] { ArchiveFile.Key });

                                            if (!m_Debug)
                                            {
                                                IffFile = new Iff(ArchiveFile.Value, ArchiveFile.Key);
                                            }
                                            else
                                            {
                                                IffFile = new Iff(ArchiveFile.Value);
                                            }

                                            //Figure out how many chunks of the type is being searched for
                                            //is in the current IFF archive. Is there a faster way to do this?
                                            foreach (IffChunk Chunk in IffFile.Chunks)
                                            {
                                                if (Chunk.Resource == TxtChunkType.Text)
                                                {
                                                    NumChunks++;
                                                }
                                            }

                                            List <IffInfo> InfoList = new List <IffInfo>();

                                            foreach (IffChunk Chunk in IffFile.Chunks)
                                            {
                                                if (Chunk.Resource == TxtChunkType.Text)
                                                {
                                                    LstChunkTypes.Invoke(m_OnFoundChunk, new object[] { ArchiveFile.Key });

                                                    IffInfo Info = new IffInfo();
                                                    Info.ArchivePath = ArchivePath;
                                                    Info.IffName     = ArchiveFile.Key;
                                                    Info.NumChunks   = NumChunks;

                                                    InfoList.Add(Info);
                                                }
                                            }

                                            m_IffInfoList.Add(Path.GetFileName(ArchivePath) + "\\" + ArchiveFile.Key, InfoList);
                                        }
                                    }
                                }
                            }
                            else //The files in "objectdata\globals\" are not in a FAR archive...
                            {
                                //Some of the files in "objectdata\globals\" are *.otf files...
                                if (ArchivePath.Contains(".iff"))
                                {
                                    if (!LookingForSprites)
                                    {
                                        Iff IffFile   = new Iff(ArchivePath);
                                        int NumChunks = 0;

                                        LblScanning.Invoke(m_OnUpdateStatus, new object[] { ArchivePath });

                                        //Figure out how many chunks of the type is being searched for
                                        //is in the current IFF archive. Is there a faster way to do this?
                                        foreach (IffChunk Chunk in IffFile.Chunks)
                                        {
                                            if (Chunk.Resource == TxtChunkType.Text)
                                            {
                                                NumChunks++;
                                            }
                                        }

                                        List <IffInfo> InfoList = new List <IffInfo>();

                                        foreach (IffChunk Chunk in IffFile.Chunks)
                                        {
                                            if (Chunk.Resource == TxtChunkType.Text)
                                            {
                                                LstChunkTypes.Invoke(m_OnFoundChunk, new object[] { Path.GetFileName(ArchivePath) });

                                                IffInfo Info = new IffInfo();
                                                Info.ArchivePath = "";
                                                Info.IffName     = IffFile.Path;
                                                Info.NumChunks   = NumChunks;

                                                InfoList.Add(Info);
                                            }
                                        }

                                        m_IffInfoList.Add(Path.GetFileName(ArchivePath), InfoList);
                                    }
                                }
                            }
                        }
                    }

                    foreach (string Dir in HouseDataDirs)
                    {
                        string[] Files = Directory.GetFiles(Dir);

                        if (Dir.Contains("walls") || Dir.Contains("floors"))
                        {
                            foreach (string ArchivePath in Files)
                            {
                                FARArchive Archive = new FARArchive(ArchivePath);
                                List <KeyValuePair <string, byte[]> > ArchiveFiles = Archive.GetAllEntries();

                                foreach (KeyValuePair <string, byte[]> ArchiveFile in ArchiveFiles)
                                {
                                    if (!LookingForSprites)
                                    {
                                        //Don't waste time scanning *.spf files if not looking for sprites...
                                        if (!ArchiveFile.Key.Contains(".spf"))
                                        {
                                            Iff IffFile;
                                            int NumChunks = 0;

                                            LblScanning.Invoke(m_OnUpdateStatus, new object[] { ArchiveFile.Key });

                                            if (!m_Debug)
                                            {
                                                IffFile = new Iff(ArchiveFile.Value, ArchiveFile.Key);
                                            }
                                            else
                                            {
                                                IffFile = new Iff(ArchiveFile.Value);
                                            }

                                            //Figure out how many chunks of the type is being searched for
                                            //is in the current IFF archive. Is there a faster way to do this?
                                            foreach (IffChunk Chunk in IffFile.Chunks)
                                            {
                                                if (Chunk.Resource == TxtChunkType.Text)
                                                {
                                                    NumChunks++;
                                                }
                                            }

                                            List <IffInfo> InfoList = new List <IffInfo>();

                                            foreach (IffChunk Chunk in IffFile.Chunks)
                                            {
                                                if (Chunk.Resource == TxtChunkType.Text)
                                                {
                                                    LstChunkTypes.Invoke(m_OnFoundChunk, new object[] { ArchiveFile.Key });

                                                    IffInfo Info = new IffInfo();
                                                    Info.ArchivePath = ArchivePath;
                                                    Info.IffName     = ArchiveFile.Key;
                                                    Info.NumChunks   = NumChunks;

                                                    InfoList.Add(Info);
                                                }
                                            }

                                            m_IffInfoList.Add(Path.GetFileName(ArchivePath) + "\\" + ArchiveFile.Key, InfoList);
                                        }
                                    }
                                    else
                                    {
                                        if (ArchiveFile.Key.Contains(".spf") || ArchiveFile.Key.Contains(".wll") || ArchiveFile.Key.Contains(".flr"))
                                        {
                                            Iff IffFile;
                                            int NumChunks = 0;

                                            LblScanning.Invoke(m_OnUpdateStatus, new object[] { ArchiveFile.Key });

                                            if (!m_Debug)
                                            {
                                                IffFile = new Iff(ArchiveFile.Value, ArchiveFile.Key);
                                            }
                                            else
                                            {
                                                IffFile = new Iff(ArchiveFile.Value);
                                            }

                                            //Figure out how many chunks of the type is being searched for
                                            //is in the current IFF archive. Is there a faster way to do this?
                                            foreach (IffChunk Chunk in IffFile.Chunks)
                                            {
                                                if (Chunk.Resource == TxtChunkType.Text)
                                                {
                                                    NumChunks++;
                                                }
                                            }

                                            List <IffInfo> InfoList = new List <IffInfo>();

                                            foreach (IffChunk Chunk in IffFile.Chunks)
                                            {
                                                if (Chunk.Resource == TxtChunkType.Text)
                                                {
                                                    LstChunkTypes.Invoke(m_OnFoundChunk, new object[] { ArchiveFile.Key });

                                                    IffInfo Info = new IffInfo();
                                                    Info.ArchivePath = ArchivePath;
                                                    Info.IffName     = ArchiveFile.Key;
                                                    Info.NumChunks   = NumChunks;

                                                    InfoList.Add(Info);
                                                }
                                            }

                                            m_IffInfoList.Add(Path.GetFileName(ArchivePath) + "\\" + ArchiveFile.Key, InfoList);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please specify a chunktype to search for!");
                }
            }

            LblScanning.Invoke((MethodInvoker) delegate()
            {
                LblScanning.Text = "Done, found: " + TotalNumberOfChunksFound() + " chunks.";
            });
            BtnAbort.Invoke((MethodInvoker) delegate() { BtnAbort.Visible = false; });
            m_WorkerThread.Abort();
        }
コード例 #7
0
ファイル: Browser.aspx.cs プロジェクト: hdgardner/ECF
    /// <summary>
    /// Binds the storage.
    /// </summary>
    private void BindStorage()
    {
        //show current path
        if (VersionId != -2)
        {
            lbPath.Text = CurrentFolder.Substring(1).Replace(ArchivePath.Substring(1) + VersionId.ToString() + "/", "/Repository/Private/");
        }
        else
        {
            lbPath.Text = CurrentFolder.Substring(1).Replace(ArchivePath.Substring(1) + Membership.GetUser().UserName + "/", "/Repository/Private/");
        }

        DataTable dt = CreateDataTable();

        DirectoryInfo dir = SelectDirectory();

        DataRow dr;

        #region Create back/private folder icon
        //add folder icon
        StringBuilder url = new StringBuilder();
        url.Append("Browser.aspx");
        url.Append("?PageVersionId=" + VersionId.ToString());
        url.Append("&RepositoryPath=" + RepositoryPath);
        url.Append("&ArchivePath=" + ArchivePath);
        url.Append("&TempPath=" + TempPath);
        url.Append("&Mode=" + Request.QueryString["Mode"]);
        dr                 = dt.NewRow();
        dr["Weight"]       = 0;
        dr["Icon"]         = string.Empty;
        dr["sortName"]     = string.Empty;
        dr["ActionEdit"]   = string.Empty;
        dr["ActionVS"]     = string.Empty;
        dr["sortSize"]     = 0;
        dr["ModifiedDate"] = string.Empty;
        dr["sortModified"] = DateTime.Now;
        dr["Modifier"]     = string.Empty;
        dr["sortModifier"] = string.Empty;
        dr["CanDelete"]    = false;
        dr["Size"]         = string.Empty;

        //add back icon
        if (CurrentFolder != RepositoryPath)
        {
            //get parent directory url
            DirectoryInfo currentDir = new DirectoryInfo(MapPath(CurrentFolder));

            string parentPath = currentDir.Parent.FullName.Replace(MapPath(Request.ApplicationPath), "").Replace("\\", "/");

            if (!parentPath.EndsWith("/"))
            {
                parentPath += "/";
            }

            if (!parentPath.StartsWith("/"))
            {
                parentPath = "/" + parentPath;
            }

            if (!parentPath.StartsWith("~"))
            {
                parentPath = "~" + parentPath;
            }

            //if parent folder is resource folder
            // then set current folder to RepositoryPath
            if (parentPath == TempPath || parentPath == ArchivePath)
            {
                url.Append("&CurrentFolder=" + RepositoryPath);
            }
            else
            {
                url.Append("&CurrentFolder=" + parentPath);
            }

            dr["Name"]    = "<a id='divId__a' href='" + url.ToString() + "'>[..]</a>";;
            dr["BigIcon"] = "<a href='" + url.ToString() + "'><img src='" + Mediachase.Commerce.Shared.CommerceHelper.GetAbsolutePath("/images/back.gif") + "' align='absmiddle' border='0' /></a>";
        }
        //add icon for user or version resource
        else
        {
            if (VersionId == -2)
            {
                url.Append("&CurrentFolder=" + ArchivePath + Membership.GetUser().UserName + "/");
            }
            else
            {
                url.Append("&CurrentFolder=" + ArchivePath + VersionId.ToString() + "/");
            }

            dr["Name"]    = "<a id='divId__a' href='" + url.ToString() + "'><b>Private</b></a>";;
            dr["BigIcon"] = "<a href='" + url.ToString() + "'><img src='" + Mediachase.Commerce.Shared.CommerceHelper.GetAbsolutePath("/images/private.gif") + "' align='absmiddle' border='0' /></a>";
        }

        dt.Rows.Add(dr);
        #endregion

        #region Get Folders
        DirectoryInfo[] dirs = dir.GetDirectories();
        foreach (DirectoryInfo d in dirs)
        {
            url = new StringBuilder();
            url.Append("Browser.aspx");
            url.Append("?PageVersionId=" + VersionId.ToString());
            url.Append("&RepositoryPath=" + RepositoryPath);
            url.Append("&ArchivePath=" + ArchivePath);
            url.Append("&TempPath=" + TempPath);
            url.Append("&Mode=" + Request.QueryString["Mode"]);
            url.Append("&CurrentFolder=" + CurrentFolder + d.Name + "/");
            url.Append("&ParentFolder=" + CurrentFolder);

            dr             = dt.NewRow();
            dr["Id"]       = d.FullName.Replace("\\", "").Replace(".", "").Replace(" ", "").Replace(":", "");
            dr["FullPath"] = d.FullName;
            dr["Weight"]   = 1;
            dr["Icon"]     = string.Empty;
            dr["BigIcon"]  = String.Format("<a id={2} href=\"{0}\"><img src='{1}' align='absmiddle' border='0' /></a>",
                                           url.ToString(), Mediachase.Commerce.Shared.CommerceHelper.GetAbsolutePath("/images/folder1.gif"), "divId_" + (string)dr["Id"] + "_a");

            dr["Name"]         = String.Format("<a href=\"{0}\">{1}</a>", url.ToString(), d.Name);
            dr["sortName"]     = string.Empty;
            dr["ActionVS"]     = string.Empty;
            dr["ActionEdit"]   = string.Empty;
            dr["sortSize"]     = 0;
            dr["ModifiedDate"] = d.LastWriteTime.ToShortDateString();
            dr["sortModified"] = d.LastWriteTime;
            dr["Modifier"]     = string.Empty;
            dr["sortModifier"] = string.Empty;
            dr["CanDelete"]    = true;
            dr["Size"]         = string.Empty;
            dt.Rows.Add(dr);
        }
        #endregion

        #region Get Files
        //fill datatable
        FileInfo[] files = dir.GetFiles();
        foreach (FileInfo file in files)
        {
            if (!IsImage(file.Extension) && Mode == ViewMode.ImageOnly)
            {
                continue;
            }
            if (!IsFlash(file.Extension) && Mode == ViewMode.FlashOnly)
            {
                continue;
            }

            string fileUrl = string.Empty;
            string resUrl  = string.Empty;
            string appPath = MapPath(Request.ApplicationPath);

            fileUrl = Request.ApplicationPath + file.FullName.Replace(appPath, "").Replace("\\", "/");

            if (!CurrentFolder.StartsWith(RepositoryPath))
            {
                string patt = CurrentFolder.Substring(1);
                if (VersionId != -2)
                {
                    resUrl = fileUrl.Replace(ArchivePath.Substring(1) + VersionId.ToString() + "/", "/Repository/Private/");
                }
                else
                {
                    resUrl = fileUrl.Replace(ArchivePath.Substring(1) + Membership.GetUser().UserName + "/", "/Repository/Private/");
                }
            }
            else
            {
                resUrl = fileUrl;
            }

            dr             = dt.NewRow();
            dr["Id"]       = file.FullName.Replace("\\", "").Replace(".", "").Replace(" ", "").Replace(":", "");
            dr["FullPath"] = file.FullName;
            dr["Weight"]   = 2;
            dr["Icon"]     = string.Empty;

            //add preview or type icon
            if (IsImage(file.Extension))
            {
                //add preview
                dr["BigIcon"] = String.Format("<a href=\"{0}\"><img src='{1}' align='absmiddle' border='0' " + ImageResize(fileUrl, 90, 90) + "/></a>",
                                              "javascript:window.opener.SetUrl('" + resUrl.ToLower() + "');window.close();", fileUrl);
            }
            else
            {
                //add type icon
                if (File.Exists(MapPath("~/images/filetype/") + file.Extension.Replace(".", "") + ".gif"))
                {
                    dr["BigIcon"] = String.Format("<a href=\"{0}\" style='height:48px;width:48px;overflow:hidden;'><img src='{1}' align='absmiddle' border='0'/></a>",
                                                  "javascript:window.opener.SetUrl('" + resUrl.ToLower() + "');window.close();", Mediachase.Commerce.Shared.CommerceHelper.GetAbsolutePath("/images/filetype/" + file.Extension.Replace(".", "") + ".gif"));
                }
                else
                {
                    dr["BigIcon"] = String.Format("<a href=\"{0}\" style='height:48px;width:48px;overflow:hidden;'><img src='{1}' align='absmiddle' border='0'/></a>",
                                                  "javascript:window.opener.SetUrl('" + resUrl.ToLower() + "');window.close();", Mediachase.Commerce.Shared.CommerceHelper.GetAbsolutePath("/images/filetype/unknown.gif"));
                }
            }

            dr["Name"]         = String.Format("<a id={2} href=\"{0}\">{1}</a>", "javascript:window.opener.SetUrl('" + resUrl.ToLower() + "');window.close();", file.Name, "divId_" + (string)dr["Id"] + "_aa");
            dr["sortName"]     = string.Empty;
            dr["ActionVS"]     = string.Empty;
            dr["ActionEdit"]   = string.Empty;
            dr["sortSize"]     = 0;
            dr["ModifiedDate"] = file.LastWriteTime.ToShortDateString();
            dr["sortModified"] = file.LastWriteTime;
            dr["Modifier"]     = string.Empty;
            dr["sortModifier"] = string.Empty;
            dr["CanDelete"]    = true;
            dr["Size"]         = FormatBytes((long)file.Length);
            dt.Rows.Add(dr);
        }
        #endregion

        DataView dv = dt.DefaultView;
        repThumbs.DataSource = dv;
        repThumbs.DataBind();
    }