Inheritance: ICASCEntry
Exemple #1
0
        protected void CreateSubTree(CASCFolder root, ulong filehash, string file)
        {
            string[] parts = file.Split(PathDelimiters);

            CASCFolder folder = root;

            for (int i = 0; i < parts.Length; ++i)
            {
                bool isFile = (i == parts.Length - 1);

                string entryName = parts[i];

                ICASCEntry entry = folder.GetEntry(entryName);

                if (entry == null)
                {
                    if (isFile)
                    {
                        entry = new CASCFile(filehash);
                        CASCFile.FileNames[filehash] = file;
                    }
                    else
                    {
                        entry = new CASCFolder(entryName);
                    }

                    folder.Entries[entryName] = entry;
                    folder.EntriesMirror[entryName] = entry;
                }

                folder = entry as CASCFolder;
            }
        }
 public void SetExtractData(CASCHandler _cascHandler, CASCFolder _folder, ListView.SelectedIndexCollection _selection)
 {
     cascHandler = _cascHandler;
     folder = _folder;
     selection = _selection.Cast<int>().ToArray();
     NumExtracted = 0;
     NumFiles = GetFilesCount(folder, selection);
     progressBar1.Value = 0;
 }
Exemple #3
0
        private void loadDataWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;

            cascHandler = Settings.Default.OnlineMode
                ? CASCHandler.OpenOnlineStorage(worker)
                : CASCHandler.OpenLocalStorage(Settings.Default.WowPath, worker);

            root = LoadListFile(cascHandler, Path.Combine(Application.StartupPath, "listfile.txt"), worker);
            e.Result = CASCHandler.FileNames.Count;
        }
Exemple #4
0
        private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            viewHelper.SetSort(e.Column);

            CASCFolder folder = viewHelper.CurrentFolder;

            if (folder == null)
            {
                return;
            }

            viewHelper.UpdateListView(folder, fileList, filterToolStripTextBox.Text);
        }
        public CASCFolder SetFlags(LocaleFlags locale, ContentFlags content, bool createTree = true)
        {
            using (var _ = new PerfCounter(GetType().Name + "::SetFlags()"))
            {
                Locale = locale;
                Content = content;

                if (createTree)
                    Root = CreateStorageTree();

                return Root;
            }
        }
        protected override CASCFolder CreateStorageTree()
        {
            var root = new CASCFolder("root");

            CountSelect = 0;

            // Cleanup fake names for unknown files
            CountUnknown = 0;

            Logger.WriteLine("AgentRootHandler: {0} file names missing for locale {1}", CountUnknown, Locale);

            return root;
        }
Exemple #7
0
        protected override CASCFolder CreateStorageTree()
        {
            var root = new CASCFolder("root");

            CountSelect = 0;

            // Cleanup fake names for unknown files
            CountUnknown = 0;

            Logger.WriteLine("AgentRootHandler: {0} file names missing for locale {1}", CountUnknown, Locale);

            return(root);
        }
Exemple #8
0
        private void OnStorageChanged()
        {
            CASCHandler  casc     = viewHelper.CASC;
            CASCConfig   cfg      = casc.Config;
            CASCGameType gameType = cfg.GameType;

            bool isWoW = gameType == CASCGameType.WoW;

            extractInstallFilesToolStripMenuItem.Enabled    = true;
            extractCASCSystemFilesToolStripMenuItem.Enabled = true;
            scanFilesToolStripMenuItem.Enabled           = isWoW;
            analyseUnknownFilesToolStripMenuItem.Enabled = isWoW || gameType == CASCGameType.Overwatch;
            localeFlagsToolStripMenuItem.Enabled         = CASCGame.SupportsLocaleSelection(gameType);
            useLVToolStripMenuItem.Enabled          = isWoW;
            exportListfileToolStripMenuItem.Enabled = true;

            CASCFolder root = viewHelper.Root;

            TreeNode node = new TreeNode()
            {
                Name = root.Name, Tag = root, Text = "Root [Read only]"
            };

            folderTree.Nodes.Add(node);
            node.Nodes.Add(new TreeNode()
            {
                Name = "tempnode"
            });                                                   // add dummy node
            node.Expand();
            folderTree.SelectedNode = node;

            if (cfg.OnlineMode)
            {
                CDNBuildsToolStripMenuItem.Enabled = true;
                if (cfg.Builds.Count > 1)
                {
                    foreach (var bld in cfg.Builds)
                    {
                        CDNBuildsToolStripMenuItem.DropDownItems.Add(bld["build-name"][0]);
                    }
                }
                else
                {
                    CDNBuildsToolStripMenuItem.DropDownItems.Add(cfg.BuildName);
                }
            }

            statusProgress.Visible = false;
            statusLabel.Text       = string.Format("Loaded {0} files ({1} names missing)", casc.Root.CountSelect - casc.Root.CountUnknown, casc.Root.CountUnknown);
        }
        public void Cleanup()
        {
            OnCleanup?.Invoke();

            Sorter.CASC = null;

            _root = null;

            if (_casc != null)
            {
                _casc.Clear();
                _casc = null;
            }
        }
Exemple #10
0
 private void ScanFolder(CASCFolder folder)
 {
     foreach (var entry in folder.Entries)
     {
         if (entry.Value is CASCFile file)
         {
             ScanFile(file);
         }
         else
         {
             ScanFolder(entry.Value as CASCFolder);
         }
     }
 }
        protected override CASCFolder CreateStorageTree()
        {
            var root = new CASCFolder("root");

            // Reset counts
            CountSelect = 0;
            UnknownFiles.Clear();

            // Create new tree based on specified locale
            foreach (var rootEntry in RootData)
            {
                var rootInfosLocale = rootEntry.Value.Where(re => (re.LocaleFlags & Locale) != 0);

                if (rootInfosLocale.Count() > 1)
                {
                    var rootInfosLocaleAndContent = rootInfosLocale.Where(re => (re.ContentFlags == Content));

                    if (rootInfosLocaleAndContent.Any())
                    {
                        rootInfosLocale = rootInfosLocaleAndContent;
                    }
                }

                if (!rootInfosLocale.Any())
                {
                    continue;
                }

                string filename;

                if (!CASCFile.Files.TryGetValue(rootEntry.Key, out CASCFile file))
                {
                    filename = "unknown\\" + rootEntry.Key.ToString("X16") + "_" + GetFileDataIdByHash(rootEntry.Key);

                    UnknownFiles.Add(rootEntry.Key);
                }
                else
                {
                    filename = file.FullName;
                }

                CreateSubTree(root, rootEntry.Key, filename);
                CountSelect++;
            }

            Logger.WriteLine("WowRootHandler: {0} file names missing for locale {1}", CountUnknown, Locale);

            return(root);
        }
Exemple #12
0
        public void Cleanup()
        {
            Sorter.CASC = null;

            _currentFolder = null;
            _root          = null;

            _displayedEntries?.Clear();
            _displayedEntries = null;

            _casc?.Clear();
            _casc = null;

            OnCleanup?.Invoke();
        }
Exemple #13
0
        public CASCFolder SetFlags(LocaleFlags locale, ContentFlags content, bool createTree = true)
        {
            using (var _ = new PerfCounter(GetType().Name + "::SetFlags()"))
            {
                Locale  = locale;
                Content = content;

                if (createTree)
                {
                    Root = CreateStorageTree();
                }

                return(Root);
            }
        }
Exemple #14
0
        public void ChangeLocale(string locale)
        {
            if (_casc == null)
            {
                return;
            }

            OnCleanup?.Invoke();

            Settings.Default.LocaleFlags = (LocaleFlags)Enum.Parse(typeof(LocaleFlags), locale);

            _root = _casc.Root.SetFlags(Settings.Default.LocaleFlags, Settings.Default.ContentFlags);
            _casc.Root.MergeInstall(_casc.Install);

            OnStorageChanged?.Invoke();
        }
Exemple #15
0
        public void SetOverrideArchive(bool set)
        {
            if (_casc == null)
            {
                return;
            }

            OnCleanup?.Invoke();

            Settings.Default.OverrideArchive = set;

            _root = _casc.Root.SetFlags(Settings.Default.LocaleFlags, Settings.Default.OverrideArchive);
            _casc.Root.MergeInstall(_casc.Install);

            OnStorageChanged?.Invoke();
        }
Exemple #16
0
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            CASCFolder folder = fileList.Tag as CASCFolder;

            if (folder == null)
            {
                return;
            }

            if (extractProgress == null)
            {
                extractProgress = new ExtractProgress();
            }

            extractProgress.SetExtractData(cascHandler, folder, fileList.SelectedIndices);
            extractProgress.ShowDialog();
        }
Exemple #17
0
        private void PreviewFile()
        {
            CASCFolder folder = fileList.Tag as CASCFolder;

            if (folder == null)
            {
                return;
            }

            var files = GetFiles(folder, fileList.SelectedIndices.Cast <int>());

            foreach (var file in files)
            {
                var extension = Path.GetExtension(file.Name);
                if (extension != null)
                {
                    switch (extension.ToLower())
                    {
                    case ".blp":
                    {
                        PreviewBlp(file.FullName);
                        break;
                    }

                    case ".txt":
                    case ".ini":
                    case ".wtf":
                    case ".lua":
                    case ".toc":
                    case ".xml":
                    case ".htm":
                    case ".html":
                    {
                        PreviewText(file.FullName);
                        break;
                    }

                    default:
                    {
                        MessageBox.Show(string.Format("Preview of {0} is not supported yet", extension), "Not supported file");
                        break;
                    }
                    }
                }
            }
        }
Exemple #18
0
        public void GetSize(NoFlickerListView fileList)
        {
            if (_currentFolder == null)
            {
                return;
            }

            if (!fileList.HasSelection)
            {
                return;
            }

            var files = CASCFolder.GetFiles(_displayedEntries, fileList.SelectedIndices.Cast <int>());

            long size = files.Sum(f => (long)f.GetSize(_casc));

            MessageBox.Show(string.Format(sizeNumberFmt, "{0:N} bytes", size));
        }
Exemple #19
0
        private void ScanFolder(CASCFolder folder)
        {
            foreach (var entry in folder.Entries)
            {
                if (entry.Value is CASCFile)
                {
                    var rootEntries = CASC.Root.GetEntries(entry.Value.Hash);

                    foreach (var rootEntry in rootEntries)
                    {
                        ScanFile(entry.Value as CASCFile);
                    }
                }
                else
                {
                    ScanFolder(entry.Value as CASCFolder);
                }
            }
        }
        public void GetSize(NoFlickerListView fileList)
        {
            CASCFolder folder = fileList.Tag as CASCFolder;

            if (folder == null)
            {
                return;
            }

            if (!fileList.HasSelection)
            {
                return;
            }

            var files = folder.GetFiles(fileList.SelectedIndices.Cast <int>());

            long size = files.Sum(f => (long)f.GetSize(_casc));

            MessageBox.Show(string.Format(sizeNumberFmt, "{0:N} bytes", size));
        }
Exemple #21
0
        private void copyNameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CASCFolder folder = fileList.Tag as CASCFolder;

            if (folder == null)
            {
                return;
            }

            if (!fileList.HasSelection)
            {
                return;
            }

            var files = folder.GetFiles(fileList.SelectedIndices.Cast <int>(), false).Select(f => f.FullName);

            string temp = string.Join(Environment.NewLine, files);

            Clipboard.SetText(temp);
        }
        public void UpdateListView(CASCFolder baseEntry, NoFlickerListView fileList, string filter)
        {
            Wildcard wildcard = new Wildcard(filter, false, RegexOptions.IgnoreCase);

            // Sort
            baseEntry.Entries = baseEntry.EntriesMirror.Where(v => v.Value is CASCFolder || (v.Value is CASCFile && wildcard.IsMatch(v.Value.Name))).
                                OrderBy(v => v.Value, Sorter).ToDictionary(pair => pair.Key, pair => pair.Value);

            // Update
            fileList.Tag             = baseEntry;
            fileList.VirtualListSize = 0;
            fileList.VirtualListSize = baseEntry.Entries.Count;

            if (fileList.VirtualListSize > 0)
            {
                fileList.EnsureVisible(0);
                fileList.SelectedIndex = 0;
                fileList.FocusedItem   = fileList.Items[0];
            }
        }
Exemple #23
0
        public void UpdateListView(CASCFolder baseEntry, NoFlickerListView fileList, string filter)
        {
            Wildcard wildcard = new Wildcard(filter, false, RegexOptions.IgnoreCase);

            // Sort
            _displayedEntries = baseEntry.Entries.Where(v => v.Value is CASCFolder || (v.Value is CASCFile && wildcard.IsMatch(v.Value.Name))).
                                OrderBy(v => v.Value, Sorter).Select(kv => kv.Value).ToList();

            _currentFolder = baseEntry;

            // Update
            fileList.VirtualListSize = 0;
            fileList.VirtualListSize = _displayedEntries.Count;

            if (fileList.VirtualListSize > 0)
            {
                fileList.EnsureVisible(0);
                fileList.SelectedIndex = 0;
                fileList.FocusedItem   = fileList.Items[0];
            }
        }
Exemple #24
0
        public void ExtractFiles(NoFlickerListView filesList)
        {
            if (_currentFolder == null)
            {
                return;
            }

            if (!filesList.HasSelection)
            {
                return;
            }

            if (extractProgress == null)
            {
                extractProgress = new ExtractProgress();
            }

            var files = CASCFolder.GetFiles(_displayedEntries, filesList.SelectedIndices.Cast <int>()).ToList();

            extractProgress.SetExtractData(_casc, files);
            extractProgress.ShowDialog();
        }
Exemple #25
0
        private static IEnumerable <CASCFile> GetFiles(CASCFolder folder, IEnumerable <int> selection)
        {
            if (selection != null)
            {
                foreach (int index in selection)
                {
                    var entry = folder.SubEntries.ElementAt(index);

                    if (entry.Value is CASCFile)
                    {
                        yield return(entry.Value as CASCFile);
                    }
                    else
                    {
                        foreach (var file in GetFiles(entry.Value as CASCFolder, null))
                        {
                            yield return(file);
                        }
                    }
                }
            }
            else
            {
                foreach (var entry in folder.SubEntries)
                {
                    if (entry.Value is CASCFile)
                    {
                        yield return(entry.Value as CASCFile);
                    }
                    else
                    {
                        foreach (var file in GetFiles(entry.Value as CASCFolder, null))
                        {
                            yield return(file);
                        }
                    }
                }
            }
        }
Exemple #26
0
        protected override CASCFolder CreateStorageTree()
        {
            var root = new CASCFolder("root");

            CountSelect  = 0;
            CountUnknown = 0;

            foreach (var rootEntry in _rootData)
            {
                if ((rootEntry.Value.baseEntry.LocaleFlags & Locale) == 0)
                {
                    continue;
                }

                CreateSubTree(root, rootEntry.Key, CASCFile.Files[rootEntry.Key].FullName);
                CountSelect++;
            }

            Logger.WriteLine("OwRootHandler: {0} file names missing for locale {1}", CountUnknown, Locale);

            return(root);
        }
        protected void CreateSubTree(CASCFolder root, ulong filehash, string file)
        {
            string[] parts = file.Split(PathDelimiters);

            CASCFolder folder = root;

            for (int i = 0; i < parts.Length; ++i)
            {
                bool isFile = (i == parts.Length - 1);

                string entryName = parts[i];

                ICASCEntry entry = folder.GetEntry(entryName);

                if (entry == null)
                {
                    if (isFile)
                    {
                        if (!CASCFile.Files.ContainsKey(filehash))
                        {
                            entry = new CASCFile(filehash, file);
                            CASCFile.Files[filehash] = (CASCFile)entry;
                        }
                        else
                        {
                            entry = CASCFile.Files[filehash];
                        }
                    }
                    else
                    {
                        entry = new CASCFolder(entryName);
                    }

                    folder.Entries[entryName] = entry;
                }

                folder = entry as CASCFolder;
            }
        }
Exemple #28
0
        private void listView1_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
        {
            CASCFolder folder = fileList.Tag as CASCFolder;

            if (folder == null)
            {
                return;
            }

            if (e.ItemIndex < 0 || e.ItemIndex >= folder.SubEntries.Count)
            {
                return;
            }

            ICASCEntry entry = folder.SubEntries.ElementAt(e.ItemIndex).Value;

            var flags = LocaleFlags.None;

            if (entry is CASCFile)
            {
                var rootInfos = cascHandler.GetRootInfo(entry.Hash);

                if (rootInfos == null)
                {
                    throw new Exception("root entry missing!");
                }

                foreach (var rootInfo in rootInfos)
                {
                    flags |= rootInfo.Block.Flags;
                }
            }

            var item = new ListViewItem(new string[] { entry.Name, entry is CASCFolder ? "Folder" : "File", flags.ToString() });

            item.ImageIndex = entry is CASCFolder ? 0 : 2;
            e.Item          = item;
        }
Exemple #29
0
        public void OpenStorage(bool online, string path, string product)
        {
            Cleanup();

            using (var initForm = new InitForm())
            {
                initForm.LoadStorage((online, path, product));

                DialogResult res = initForm.ShowDialog();

                if (res != DialogResult.OK)
                {
                    return;
                }

                _casc = initForm.CASC;
                _root = initForm.Root;
            }

            Sorter.CASC = _casc;

            OnStorageChanged?.Invoke();
        }
Exemple #30
0
        public void ChangeContentFlags(bool set)
        {
            if (_casc == null)
            {
                return;
            }

            OnCleanup?.Invoke();

            if (set)
            {
                Settings.Default.ContentFlags |= ContentFlags.LowViolence;
            }
            else
            {
                Settings.Default.ContentFlags &= ~ContentFlags.LowViolence;
            }

            _root = _casc.Root.SetFlags(Settings.Default.LocaleFlags, Settings.Default.ContentFlags);
            _casc.Root.MergeInstall(_casc.Install);

            OnStorageChanged?.Invoke();
        }
Exemple #31
0
        private int GetFilesCount(CASCFolder _folder, IEnumerable <int> _selection)
        {
            int count = 0;

            if (_selection != null)
            {
                foreach (int index in _selection)
                {
                    var entry = _folder.SubEntries.ElementAt(index);

                    if (entry.Value is CASCFile)
                    {
                        count++;
                    }
                    else
                    {
                        count += GetFilesCount(entry.Value as CASCFolder, null);
                    }
                }
            }
            else
            {
                foreach (var entry in _folder.SubEntries)
                {
                    if (entry.Value is CASCFile)
                    {
                        count++;
                    }
                    else
                    {
                        count += GetFilesCount(entry.Value as CASCFolder, null);
                    }
                }
            }

            return(count);
        }
        public void Search(NoFlickerListView fileList, SearchForVirtualItemEventArgs e)
        {
            bool ignoreCase    = true;
            bool searchUp      = false;
            int  SelectedIndex = fileList.SelectedIndex;

            CASCFolder folder = fileList.Tag as CASCFolder;

            var comparisonType = ignoreCase
                                    ? StringComparison.InvariantCultureIgnoreCase
                                    : StringComparison.InvariantCulture;

            if (searchUp)
            {
                for (var i = SelectedIndex - 1; i >= 0; --i)
                {
                    var op = folder.Entries.ElementAt(i).Value.Name;
                    if (op.IndexOf(e.Text, comparisonType) != -1)
                    {
                        e.Index = i;
                        break;
                    }
                }
            }
            else
            {
                for (int i = SelectedIndex + 1; i < fileList.Items.Count; ++i)
                {
                    var op = folder.Entries.ElementAt(i).Value.Name;
                    if (op.IndexOf(e.Text, comparisonType) != -1)
                    {
                        e.Index = i;
                        break;
                    }
                }
            }
        }
Exemple #33
0
        private void UpdateListView(CASCFolder baseEntry)
        {
            // Sort
            Dictionary <ulong, ICASCEntry> orderedEntries;

            if (fileList.Sorting == SortOrder.Ascending)
            {
                orderedEntries = baseEntry.SubEntries.OrderBy(v => v.Value).ToDictionary(pair => pair.Key, pair => pair.Value);
            }
            else
            {
                orderedEntries = baseEntry.SubEntries.OrderByDescending(v => v.Value).ToDictionary(pair => pair.Key, pair => pair.Value);
            }

            baseEntry.SubEntries = orderedEntries;

            // Update
            fileList.Tag             = baseEntry;
            fileList.VirtualListSize = 0;
            fileList.VirtualListSize = baseEntry.SubEntries.Count;
            fileList.EnsureVisible(0);
            fileList.SelectedIndices.Add(0);
            fileList.FocusedItem = fileList.Items[0];
        }
Exemple #34
0
        protected override CASCFolder CreateStorageTree()
        {
            var root = new CASCFolder("root");

            CountSelect = 0;

            foreach (var entry in RootData)
            {
                if ((entry.Value.LocaleFlags & Locale) == 0)
                {
                    continue;
                }

                CreateSubTree(root, entry.Key, CASCFile.FileNames[entry.Key]);
                CountSelect++;
            }

            // Cleanup fake names for unknown files
            CountUnknown = 0;

            Logger.WriteLine("S1RootHandler: {0} file names missing for locale {1}", CountUnknown, Locale);

            return(root);
        }
Exemple #35
0
        protected override CASCFolder CreateStorageTree()
        {
            var root = new CASCFolder("root");

            CountSelect = 0;

            // Create new tree based on specified locale
            foreach (var rootEntry in RootData)
            {
                var rootInfosLocale = rootEntry.Value.Where(re => (re.Block.LocaleFlags & Locale) != 0);

                if (!rootInfosLocale.Any())
                {
                    continue;
                }

                CreateSubTree(root, rootEntry.Key, CASCFile.FileNames[rootEntry.Key]);
                CountSelect++;
            }

            Logger.WriteLine("D3RootHandler: {0} file names missing extensions for locale {1}", CountUnknown, Locale);

            return(root);
        }
Exemple #36
0
 private void ScanFolder(CASCFolder folder)
 {
     foreach (var entry in folder.Entries)
     {
         if (entry.Value is CASCFile)
             ScanFile(entry.Value as CASCFile);
         else
             ScanFolder(entry.Value as CASCFolder);
     }
 }
        public void ChangeLocale(string locale)
        {
            if (_casc == null)
                return;

            OnCleanup?.Invoke();

            Settings.Default.LocaleFlags = (LocaleFlags)Enum.Parse(typeof(LocaleFlags), locale);

            _root = _casc.Root.SetFlags(Settings.Default.LocaleFlags, Settings.Default.ContentFlags);
            _casc.Root.MergeInstall(_casc.Install);

            OnStorageChanged?.Invoke();
        }
Exemple #38
0
        public void CreateListViewItem(RetrieveVirtualItemEventArgs e, CASCFolder folder)
        {
            if (folder == null)
                return;

            if (e.ItemIndex < 0 || e.ItemIndex >= folder.Entries.Count)
                return;

            ICASCEntry entry = folder.Entries.ElementAt(e.ItemIndex).Value;

            var localeFlags = LocaleFlags.None;
            var contentFlags = ContentFlags.None;
            var size = "<DIR>";

            if (entry is CASCFile)
            {
                var rootInfosLocale = _casc.Root.GetEntries(entry.Hash);

                if (rootInfosLocale.Any())
                {
                    var enc = _casc.Encoding.GetEntry(rootInfosLocale.First().MD5);

                    if (enc != null)
                        size = enc.Size.ToString("N", sizeNumberFmt);
                    else
                        size = "0";

                    foreach (var rootInfo in rootInfosLocale)
                    {
                        if (rootInfo.Block != null)
                        {
                            localeFlags |= rootInfo.Block.LocaleFlags;
                            contentFlags |= rootInfo.Block.ContentFlags;
                        }
                    }
                }
                else
                {
                    var installInfos = _casc.Install.GetEntries(entry.Hash);

                    if (installInfos.Any())
                    {
                        var enc = _casc.Encoding.GetEntry(installInfos.First().MD5);

                        if (enc != null)
                            size = enc.Size.ToString("N", sizeNumberFmt);
                        else
                            size = "0";

                        //foreach (var rootInfo in rootInfosLocale)
                        //{
                        //    if (rootInfo.Block != null)
                        //    {
                        //        localeFlags |= rootInfo.Block.LocaleFlags;
                        //        contentFlags |= rootInfo.Block.ContentFlags;
                        //    }
                        //}
                    }
                }
            }

            e.Item = new ListViewItem(new string[]
            {
                entry.Name,
                entry is CASCFolder ? "Folder" : Path.GetExtension(entry.Name),
                localeFlags.ToString(),
                contentFlags.ToString(),
                size
            })
            { ImageIndex = entry is CASCFolder ? 0 : 2 };
        }
        public void ChangeContentFlags(bool set)
        {
            if (_casc == null)
                return;

            OnCleanup?.Invoke();

            if (set)
                Settings.Default.ContentFlags |= ContentFlags.LowViolence;
            else
                Settings.Default.ContentFlags &= ~ContentFlags.LowViolence;

            _root = _casc.Root.SetFlags(Settings.Default.LocaleFlags, Settings.Default.ContentFlags);
            _casc.Root.MergeInstall(_casc.Install);

            OnStorageChanged?.Invoke();
        }
Exemple #40
0
        private int GetFilesCount(CASCFolder _folder, IEnumerable<int> _selection)
        {
            int count = 0;

            if (_selection != null)
            {
                foreach (int index in _selection)
                {
                    var entry = _folder.SubEntries.ElementAt(index);

                    if (entry.Value is CASCFile)
                        count++;
                    else
                        count += GetFilesCount(entry.Value as CASCFolder, null);
                }
            }
            else
            {
                foreach (var entry in _folder.SubEntries)
                {
                    if (entry.Value is CASCFile)
                        count++;
                    else
                        count += GetFilesCount(entry.Value as CASCFolder, null);
                }
            }

            return count;
        }
Exemple #41
0
        private static CASCFolder LoadListFile(CASCHandler cascHandler, string path, BackgroundWorker worker)
        {
            if (!File.Exists(path))
                throw new FileNotFoundException("list file missing!");

            var rootHash = CASCHandler.Hasher.ComputeHash("root");

            var root = new CASCFolder(rootHash);

            CASCHandler.FolderNames[rootHash] = "root";

            using (var sr = new StreamReader(path))
            {
                string file;
                int filesCount = 0;

                CASCFolder folder = root;

                while ((file = sr.ReadLine()) != null)
                {
                    filesCount++;

                    string[] parts = file.Split('\\');

                    for (int i = 0; i < parts.Length; ++i)
                    {
                        bool isFile = (i == parts.Length - 1);

                        ulong hash = isFile ? CASCHandler.Hasher.ComputeHash(file) : CASCHandler.Hasher.ComputeHash(parts[i]);

                        // skip invalid names
                        if (isFile && !cascHandler.RootData.ContainsKey(hash))
                            break;

                        ICASCEntry entry = folder.GetEntry(hash);

                        if (entry == null)
                        {
                            if (isFile)
                            {
                                entry = new CASCFile(hash);
                                CASCHandler.FileNames[hash] = file;
                            }
                            else
                            {
                                entry = new CASCFolder(hash);
                                CASCHandler.FolderNames[hash] = parts[i];
                            }

                            folder.SubEntries[hash] = entry;

                            if (isFile)
                            {
                                folder = root;
                                break;
                            }
                        }

                        folder = entry as CASCFolder;
                    }
                }
                Logger.WriteLine("CASCHandler: loaded {0} file names", CASCHandler.FileNames.Count);
            }
            return root;
        }
Exemple #42
0
        private void UpdateListView(CASCFolder baseEntry)
        {
            // Sort
            Dictionary<ulong, ICASCEntry> orderedEntries;

            if (fileList.Sorting == SortOrder.Ascending)
                orderedEntries = baseEntry.SubEntries.OrderBy(v => v.Value).ToDictionary(pair => pair.Key, pair => pair.Value);
            else
                orderedEntries = baseEntry.SubEntries.OrderByDescending(v => v.Value).ToDictionary(pair => pair.Key, pair => pair.Value);

            baseEntry.SubEntries = orderedEntries;

            // Update
            fileList.Tag = baseEntry;
            fileList.VirtualListSize = 0;
            fileList.VirtualListSize = baseEntry.SubEntries.Count;
            fileList.EnsureVisible(0);
            fileList.SelectedIndices.Add(0);
            fileList.FocusedItem = fileList.Items[0];
        }
        public void UpdateListView(CASCFolder baseEntry, NoFlickerListView fileList, string filter)
        {
            Wildcard wildcard = new Wildcard(filter, false, RegexOptions.IgnoreCase);

            // Sort
            _displayedEntries = baseEntry.Entries.Where(v => v.Value is CASCFolder || (v.Value is CASCFile && wildcard.IsMatch(v.Value.Name))).
                OrderBy(v => v.Value, Sorter).Select(kv => kv.Value).ToList();

            _currentFolder = baseEntry;

            // Update
            fileList.VirtualListSize = 0;
            fileList.VirtualListSize = _displayedEntries.Count;

            if (fileList.VirtualListSize > 0)
            {
                fileList.EnsureVisible(0);
                fileList.SelectedIndex = 0;
                fileList.FocusedItem = fileList.Items[0];
            }
        }
        public void OpenStorage(string arg, bool online)
        {
            Cleanup();

            using (var initForm = new InitForm())
            {
                if (online)
                    initForm.LoadOnlineStorage(arg);
                else
                    initForm.LoadLocalStorage(arg);

                DialogResult res = initForm.ShowDialog();

                if (res != DialogResult.OK)
                    return;

                _casc = initForm.CASC;
                _root = initForm.Root;
            }

            Sorter.CASC = _casc;

            OnStorageChanged?.Invoke();
        }
Exemple #45
0
        public void Cleanup()
        {
            OnCleanup?.Invoke();

            Sorter.CASC = null;

            _root = null;

            if (_casc != null)
            {
                _casc.Clear();
                _casc = null;
            }
        }
Exemple #46
0
        private static IEnumerable<CASCFile> GetFiles(CASCFolder folder, IEnumerable<int> selection)
        {
            if (selection != null)
            {
                foreach (int index in selection)
                {
                    var entry = folder.SubEntries.ElementAt(index);

                    if (entry.Value is CASCFile)
                    {
                        yield return entry.Value as CASCFile;
                    }
                    else
                    {
                        foreach (var file in GetFiles(entry.Value as CASCFolder, null))
                        {
                            yield return file;
                        }
                    }
                }
            }
            else
            {
                foreach (var entry in folder.SubEntries)
                {
                    if (entry.Value is CASCFile)
                    {
                        yield return entry.Value as CASCFile;
                    }
                    else
                    {
                        foreach (var file in GetFiles(entry.Value as CASCFolder, null))
                        {
                            yield return file;
                        }
                    }
                }
            }
        }
Exemple #47
0
 public void Initialize(CASCHandler casc, CASCFolder root)
 {
     CASC = casc;
     Root = root;
     scanner = new FileScanner(CASC, Root);
 }
Exemple #48
0
        private void ExtractData(CASCFolder _folder, IEnumerable<int> _selection)
        {
            if (_selection != null)
            {
                foreach (int index in _selection)
                {
                    var entry = _folder.SubEntries.ElementAt(index);

                    if (entry.Value is CASCFile)
                        ExtractFile(entry.Value as CASCFile);
                    else
                        ExtractData(entry.Value as CASCFolder, null);
                }
            }
            else
            {
                foreach (var entry in _folder.SubEntries)
                {
                    if (entry.Value is CASCFile)
                        ExtractFile(entry.Value as CASCFile);
                    else
                        ExtractData(entry.Value as CASCFolder, null);
                }
            }
        }
        protected override CASCFolder CreateStorageTree()
        {
            var root = new CASCFolder("root");

            CountSelect = 0;

            // Create new tree based on specified locale
            foreach (var rootEntry in RootData)
            {
                var rootInfosLocale = rootEntry.Value.Where(re => (re.LocaleFlags & Locale) != 0);

                if (!rootInfosLocale.Any())
                    continue;

                CreateSubTree(root, rootEntry.Key, CASCFile.FileNames[rootEntry.Key]);
                CountSelect++;
            }

            Logger.WriteLine("D3RootHandler: {0} file names missing extensions for locale {1}", CountUnknown, Locale);

            return root;
        }
        protected override CASCFolder CreateStorageTree()
        {
            var root = new CASCFolder("root");

            CountSelect = 0;

            // Cleanup fake names for unknown files
            CountUnknown = 0;

            foreach (var unkFile in UnknownFiles)
                CASCFile.FileNames.Remove(unkFile);

            // Create new tree based on specified locale
            foreach (var rootEntry in RootData)
            {
                var rootInfosLocale = rootEntry.Value.Where(re => (re.Block.LocaleFlags & Locale) != 0);

                if (rootInfosLocale.Count() > 1)
                {
                    var rootInfosLocaleAndContent = rootInfosLocale.Where(re => (re.Block.ContentFlags == Content));

                    if (rootInfosLocaleAndContent.Any())
                        rootInfosLocale = rootInfosLocaleAndContent;
                }

                if (!rootInfosLocale.Any())
                    continue;

                string file;

                if (!CASCFile.FileNames.TryGetValue(rootEntry.Key, out file))
                {
                    file = "unknown\\" + rootEntry.Key.ToString("X16") + "_" + rootEntry.Value.First().FileDataId;

                    CountUnknown++;
                    UnknownFiles.Add(rootEntry.Key);
                }

                CreateSubTree(root, rootEntry.Key, file);
                CountSelect++;
            }

            Logger.WriteLine("WowRootHandler: {0} file names missing for locale {1}", CountUnknown, Locale);

            return root;
        }
        protected override CASCFolder CreateStorageTree()
        {
            var root = new CASCFolder("root");

            // Reset counts
            CountSelect = 0;
            UnknownFiles.Clear();

            // Create new tree based on specified locale
            foreach (var rootEntry in RootData)
            {
                var rootInfosLocale = rootEntry.Value.Where(re => (re.LocaleFlags & Locale) != 0);

                if (rootInfosLocale.Count() > 1)
                {
                    var rootInfosLocaleAndContent = rootInfosLocale.Where(re => (re.ContentFlags == Content));

                    if (rootInfosLocaleAndContent.Any())
                        rootInfosLocale = rootInfosLocaleAndContent;
                }

                if (!rootInfosLocale.Any())
                    continue;

                string file;

                if (!CASCFile.FileNames.TryGetValue(rootEntry.Key, out file))
                {
                    file = "unknown\\" + rootEntry.Key.ToString("X16") + "_" + GetFileDataIdByHash(rootEntry.Key);

                    UnknownFiles[rootEntry.Key] = true;
                }

                CreateSubTree(root, rootEntry.Key, file);
                CountSelect++;
            }

            Logger.WriteLine("WowRootHandler: {0} file names missing for locale {1}", CountUnknown, Locale);

            return root;
        }
Exemple #52
0
        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            DialogResult = DialogResult.Cancel;

            if (e.Cancelled)
            {
                MessageBox.Show("Loading cancelled", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //Application.Exit();
                return;
            }

            if (e.Error != null)
            {
                MessageBox.Show("Loading failed due to:\n" + e.Error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //Application.Exit();
                return;
            }

            if (e.Result == null)
            {
                MessageBox.Show("Loading failed: Result is null", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //Application.Exit();
                return;
            }

            var result = (object[])e.Result;
            CASC = (CASCHandler)result[0];
            Root = (CASCFolder)result[1];

            DialogResult = DialogResult.OK;
        }
Exemple #53
0
        public void UpdateListView(CASCFolder baseEntry, NoFlickerListView fileList, string filter)
        {
            Wildcard wildcard = new Wildcard(filter, false, RegexOptions.IgnoreCase);

            // Sort
            baseEntry.Entries = baseEntry.EntriesMirror.Where(v => v.Value is CASCFolder || (v.Value is CASCFile && wildcard.IsMatch(v.Value.Name))).
                OrderBy(v => v.Value, Sorter).ToDictionary(pair => pair.Key, pair => pair.Value);

            // Update
            fileList.Tag = baseEntry;
            fileList.VirtualListSize = 0;
            fileList.VirtualListSize = baseEntry.Entries.Count;

            if (fileList.VirtualListSize > 0)
            {
                fileList.EnsureVisible(0);
                fileList.SelectedIndex = 0;
                fileList.FocusedItem = fileList.Items[0];
            }
        }
        public void Cleanup()
        {
            Sorter.CASC = null;

            _currentFolder = null;
            _root = null;

            _displayedEntries?.Clear();
            _displayedEntries = null;

            _casc?.Clear();
            _casc = null;

            OnCleanup?.Invoke();
        }
Exemple #55
0
 public FileScanner(CASCHandler casc, CASCFolder root)
 {
     CASC = casc;
     Root = root;
 }
Exemple #56
0
        public CASCHandler(CASCFolder root, BackgroundWorker worker)
        {
            if (!OnlineMode)
            {
                var idxFiles = GetIdxFiles(Properties.Settings.Default.WowPath);

                if (idxFiles.Count == 0)
                    throw new FileNotFoundException("idx files missing!");

                worker.ReportProgress(0);

                int idxIndex = 0;

                foreach (var idx in idxFiles)
                {
                    using (var fs = new FileStream(idx, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    using (var br = new BinaryReader(fs))
                    {
                        int h2Len = br.ReadInt32();
                        int h2Check = br.ReadInt32();
                        byte[] h2 = br.ReadBytes(h2Len);

                        long padPos = (8 + h2Len + 0x0F) & 0xFFFFFFF0;
                        fs.Position = padPos;

                        int dataLen = br.ReadInt32();
                        int dataCheck = br.ReadInt32();

                        int numBlocks = dataLen / 18;

                        for (int i = 0; i < numBlocks; i++)
                        {
                            IndexEntry info = new IndexEntry();
                            byte[] key = br.ReadBytes(9);
                            int indexHigh = br.ReadByte();
                            int indexLow = br.ReadInt32BE();

                            info.Index = (int)((byte)(indexHigh << 2) | ((indexLow & 0xC0000000) >> 30));
                            info.Offset = (indexLow & 0x3FFFFFFF);
                            info.Size = br.ReadInt32();

                            // duplicate keys wtf...
                            //IndexData[key] = info; // use last key
                            if (!LocalIndexData.ContainsKey(key)) // use first key
                                LocalIndexData.Add(key, info);
                        }

                        padPos = (dataLen + 0x0FFF) & 0xFFFFF000;
                        fs.Position = padPos;

                        fs.Position += numBlocks * 18;
                        //for (int i = 0; i < numBlocks; i++)
                        //{
                        //    var bytes = br.ReadBytes(18); // unknown data
                        //}

                        if (fs.Position != fs.Position)
                            throw new Exception("idx file under read");
                    }

                    worker.ReportProgress((int)((float)++idxIndex / (float)idxFiles.Count * 100));
                }

                Logger.WriteLine("CASCHandler: loaded {0} indexes", LocalIndexData.Count);
            }

            worker.ReportProgress(0);

            using (var fs = OpenEncodingFile())
            using (var br = new BinaryReader(fs))
            {
                br.ReadBytes(2); // EN
                byte b1 = br.ReadByte();
                byte b2 = br.ReadByte();
                byte b3 = br.ReadByte();
                ushort s1 = br.ReadUInt16();
                ushort s2 = br.ReadUInt16();
                int numEntries = br.ReadInt32BE();
                int i1 = br.ReadInt32BE();
                byte b4 = br.ReadByte();
                int entriesOfs = br.ReadInt32BE();

                fs.Position += entriesOfs; // skip strings

                fs.Position += numEntries * 32;
                //for (int i = 0; i < numEntries; ++i)
                //{
                //    br.ReadBytes(16);
                //    br.ReadBytes(16);
                //}

                for (int i = 0; i < numEntries; ++i)
                {
                    ushort keysCount;

                    while ((keysCount = br.ReadUInt16()) != 0)
                    {
                        int fileSize = br.ReadInt32BE();
                        byte[] md5 = br.ReadBytes(16);

                        var entry = new EncodingEntry();
                        entry.Size = fileSize;

                        for (int ki = 0; ki < keysCount; ++ki)
                        {
                            byte[] key = br.ReadBytes(16);

                            entry.Keys.Add(key);
                        }

                        //Encodings[md5] = entry;
                        EncodingData.Add(md5, entry);
                    }

                    //br.ReadBytes(28);
                    while (br.PeekChar() == 0)
                        fs.Position++;

                    worker.ReportProgress((int)((float)fs.Position / (float)fs.Length * 100));
                }
                //var pos = br.BaseStream.Position;
                //for (int i = 0; i < i1; ++i)
                //{
                //    br.ReadBytes(16);
                //    br.ReadBytes(16);
                //}
                Logger.WriteLine("CASCHandler: loaded {0} encoding data", EncodingData.Count);
            }

            worker.ReportProgress(0);

            using (var fs = OpenRootFile())
            using (var br = new BinaryReader(fs))
            {
                while (fs.Position < fs.Length)
                {
                    int count = br.ReadInt32();

                    RootBlock block = new RootBlock();
                    block.Unk1 = br.ReadUInt32();
                    block.Flags = (LocaleFlags)br.ReadUInt32();

                    if (block.Flags == LocaleFlags.None)
                        throw new Exception("block.Flags == LocaleFlags.None");

                    RootEntry[] entries = new RootEntry[count];

                    for (var i = 0; i < count; ++i)
                    {
                        entries[i] = new RootEntry();
                        entries[i].Block = block;
                        entries[i].Unk1 = br.ReadInt32();
                    }

                    for (var i = 0; i < count; ++i)
                    {
                        entries[i].MD5 = br.ReadBytes(16);

                        ulong hash = br.ReadUInt64();
                        entries[i].Hash = hash;

                        // don't load other locales
                        //if (block.Flags != LocaleFlags.All && (block.Flags & LocaleFlags.enUS) == 0)
                        //    continue;

                        if (!RootData.ContainsKey(hash))
                        {
                            RootData[hash] = new List<RootEntry>();
                            RootData[hash].Add(entries[i]);
                        }
                        else
                            RootData[hash].Add(entries[i]);
                    }

                    worker.ReportProgress((int)((float)fs.Position / (float)fs.Length * 100));
                }

                Logger.WriteLine("CASCHandler: loaded {0} root data", RootData.Count);
            }

            worker.ReportProgress(0);

            if (File.Exists(listFile))
            {
                FolderNames[Hasher.ComputeHash("root")] = "root";

                using (StreamReader sr = new StreamReader(listFile))
                {
                    string file;
                    int filesCount = 0;

                    CASCFolder folder = root;

                    while ((file = sr.ReadLine()) != null)
                    {
                        ulong fileHash = Hasher.ComputeHash(file);

                        // skip invalid names
                        if (!RootData.ContainsKey(fileHash))
                        {
                            Logger.WriteLine("Invalid file name: {0}", file);
                            continue;
                        }

                        filesCount++;

                        string[] parts = file.Split('\\');

                        for (int i = 0; i < parts.Length; ++i)
                        {
                            bool isFile = (i == parts.Length - 1);

                            ulong hash = isFile ? fileHash : Hasher.ComputeHash(parts[i]);

                            ICASCEntry entry = folder.GetEntry(hash);

                            if (entry == null)
                            {
                                if (isFile)
                                {
                                    entry = new CASCFile(hash);
                                    FileNames[hash] = file;
                                }
                                else
                                {
                                    entry = new CASCFolder(hash);
                                    FolderNames[hash] = parts[i];
                                }

                                folder.SubEntries[hash] = entry;

                                if (isFile)
                                {
                                    folder = root;
                                    break;
                                }
                            }

                            folder = entry as CASCFolder;
                        }

                        if ((filesCount % 1000) == 0)
                            worker.ReportProgress((int)((float)sr.BaseStream.Position / (float)sr.BaseStream.Length * 100));
                    }

                    Logger.WriteLine("CASCHandler: loaded {0} file names", FileNames.Count);
                }
            }
            else
            {
                throw new FileNotFoundException("list file missing!");
            }
        }
        protected override CASCFolder CreateStorageTree()
        {
            var root = new CASCFolder("root");

            CountSelect = 0;
            CountUnknown = 0;

            foreach (var rootEntry in _rootData)
            {
                if ((rootEntry.Value.baseEntry.LocaleFlags & Locale) == 0)
                    continue;

                CreateSubTree(root, rootEntry.Key, CASCFile.FileNames[rootEntry.Key]);
                CountSelect++;
            }

            Logger.WriteLine("OwRootHandler: {0} file names missing for locale {1}", CountUnknown, Locale);

            return root;
        }
Exemple #58
0
        private void ScanFolder(CASCFolder folder)
        {
            foreach (var entry in folder.Entries)
            {
                if (entry.Value is CASCFile)
                {
                    var rootEntries = CASC.Root.GetEntries(entry.Value.Hash);

                    foreach (var rootEntry in rootEntries)
                        ScanFile(entry.Value as CASCFile);
                }
                else
                    ScanFolder(entry.Value as CASCFolder);
            }
        }