コード例 #1
0
        // Handle via CASCLib
        public static void InitCasc(BackgroundWorkerEx worker = null, string basedir = null, string program = "wowt", LocaleFlags locale = LocaleFlags.enUS)
        {
            usingLocalAPI                  = false;
            CASCConfig.LoadFlags          &= ~(LoadFlags.Download | LoadFlags.Install);
            CASCConfig.ValidateData        = false;
            CASCConfig.ThrowOnFileNotFound = false;

            if (basedir == null)
            {
                Console.WriteLine("Initializing CASC from web for program " + program);
                cascHandler = CASCHandler.OpenOnlineStorage(program, "eu", worker);
            }
            else
            {
                basedir = basedir.Replace("_retail_", "").Replace("_ptr_", "");
                Console.WriteLine("Initializing CASC from local disk with basedir " + basedir);
                cascHandler = CASCHandler.OpenLocalStorage(basedir, worker);
            }

            BuildName = cascHandler.Config.BuildName;

            cascHandler.Root.SetFlags(locale, ContentFlags.None, false);

            IsCASCInit = true;
        }
コード例 #2
0
        public static void InitializeOnline(LocaleFlags locale, BackgroundWorkerEx worker = null)
        {
            Locale  = locale;
            Handler = CASCHandler.OpenOnlineStorage("wow", worker: worker);
            Handler.Root.SetFlags(locale, ContentFlags.None, false);

            Initialized = true;
        }
コード例 #3
0
        public static void Initialize(string path, LocaleFlags locale, BackgroundWorkerEx worker = null)
        {
            Locale  = locale;
            Handler = CASCHandler.OpenLocalStorage(path, worker);
            Handler.Root.SetFlags(locale, ContentFlags.None, false);

            Initialized = true;
        }
コード例 #4
0
ファイル: RenderView.cs プロジェクト: shmilyzxt/WoWMap
        public void SetCamera(Vector3 pos)
        {
            var worker = new BackgroundWorkerEx();

            worker.DoWork += (sender, e) =>
            {
                Camera = new Camera(pos, -Vector3.UnitZ);
                Camera.SetViewport(Control.Width, Control.Height);
                GL.Viewport(0, 0, Control.Width, Control.Height);
                Camera.OnMovement += () =>
                {
                    Renderer.Update();
                    Render();
                };
            };
            worker.RunWorkerAsync();
        }
コード例 #5
0
ファイル: InstanceViewModel.cs プロジェクト: radtek/Octopus
 private void Run()
 {
     ((MainWindow)ParentWindow).tabExecution.IsSelected = true;
     ((MainWindow)ParentWindow).tabParams.IsEnabled     = false;
     ((MainWindow)ParentWindow).tabMachines.IsEnabled   = false;
     ((MainWindow)ParentWindow).tabActions.IsEnabled    = false;
     ((MainWindow)ParentWindow).tabTasks.IsEnabled      = false;
     ((MainWindow)ParentWindow).m_actionVM.IsExecuting  = true;
     ((MainWindow)ParentWindow).m_machineVM.IsExecuting = true;
     ((MainWindow)ParentWindow).m_taskVM.IsExecuting    = true;
     ((MainWindow)ParentWindow).m_paramsVM.IsExecuting  = true;
     IsExecuting = true;
     runWorker   = new BackgroundWorkerEx();
     runWorker.WorkerSupportsCancellation = true;
     runWorker.DoWork             += this.Run_DoWork;
     runWorker.RunWorkerCompleted += this.Run_Completed;
     runWorker.RunWorkerAsync();
 }
コード例 #6
0
        public static void InitCasc(BackgroundWorkerEx worker = null, string basedir = null, string program = "wowt")
        {
            CASCConfig.LoadFlags &= ~(LoadFlags.Download | LoadFlags.Install);

            if (basedir == null)
            {
                CASCConfig config = CASCConfig.LoadOnlineStorageConfig(program, "us", true);

                Console.WriteLine("Initializing CASC from web with program " + program + " and build " + config.BuildName);
                cascHandler = CASCHandler.OpenStorage(config, worker);
            }
            else
            {
                Console.WriteLine("Initializing CASC from local disk with basedir " + basedir);
                cascHandler = CASCHandler.OpenLocalStorage(basedir, worker);
            }

            cascHandler.Root.SetFlags(LocaleFlags.enUS, ContentFlags.None, false);

            fIsCASCInit = true;
        }
コード例 #7
0
ファイル: RenderView.cs プロジェクト: shmilyzxt/WoWMap
 public void LoadMap(string mapName)
 {
     _loader         = new BackgroundWorkerEx();
     _loader.DoWork += (sender, e) =>
     {
         _loader.ReportProgress(1, "Loading WDT...");
         Renderer?.Delete();
         var wdt = new WDT(string.Format(@"World\Maps\{0}\{0}.wdt", mapName));
         Renderer = new WDTRenderer(this, mapName, wdt);
         _loader.ReportProgress(100, "Map loaded");
     };
     _loader.ProgressChanged += (sender, args) =>
     {
         if (OnProgress != null)
         {
             OnProgress(args.ProgressPercentage, (string)args.UserState);
         }
     };
     _loader.RunWorkerCompleted += (sender, e) => InitializeView();
     _loader.RunWorkerAsync();
 }
コード例 #8
0
        static void Main(string[] args)
        {
            if (args.Length != 4)
            {
                Console.WriteLine("Invalid arguments count!");
                Console.WriteLine("Usage: CASCConsole <pattern> <destination> <localeFlags> <contentFlags>");
                return;
            }

            Console.WriteLine("Settings:");
            Console.WriteLine("    WowPath: {0}", Settings.Default.StoragePath);
            Console.WriteLine("    OnlineMode: {0}", Settings.Default.OnlineMode);

            Console.WriteLine("Loading...");

            BackgroundWorkerEx bgLoader = new BackgroundWorkerEx();

            bgLoader.ProgressChanged += BgLoader_ProgressChanged;

            CASCConfig config = Settings.Default.OnlineMode
                ? CASCConfig.LoadOnlineStorageConfig(Settings.Default.Product, "us")
                : CASCConfig.LoadLocalStorageConfig(Settings.Default.StoragePath);

            CASCHandler cascHandler = CASCHandler.OpenStorage(config, bgLoader);

            string       pattern = args[0];
            string       dest    = args[1];
            LocaleFlags  locale  = (LocaleFlags)Enum.Parse(typeof(LocaleFlags), args[2]);
            ContentFlags content = (ContentFlags)Enum.Parse(typeof(ContentFlags), args[3]);

            cascHandler.Root.LoadListFile(Path.Combine(Environment.CurrentDirectory, "listfile.txt"), bgLoader);
            CASCFolder root = cascHandler.Root.SetFlags(locale, content);

            Console.WriteLine("Loaded.");

            Console.WriteLine("Extract params:", pattern, dest, locale);
            Console.WriteLine("    Pattern: {0}", pattern);
            Console.WriteLine("    Destination: {0}", dest);
            Console.WriteLine("    LocaleFlags: {0}", locale);
            Console.WriteLine("    ContentFlags: {0}", content);

            Wildcard wildcard = new Wildcard(pattern, true, RegexOptions.IgnoreCase);

            foreach (var file in root.GetFiles())
            {
                if (wildcard.IsMatch(file.FullName))
                {
                    Console.Write("Extracting '{0}'...", file.FullName);

                    try
                    {
                        cascHandler.SaveFileTo(file.FullName, dest);
                        Console.WriteLine(" Ok!");
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine(" Error!");
                        Logger.WriteLine(exc.Message);
                    }
                }
            }

            Console.WriteLine("Extracted.");
        }
コード例 #9
0
 public static void Initialize(string path, BackgroundWorkerEx worker = null)
 {
     Initialize(path, LocaleFlags.enUS, worker);
 }
コード例 #10
0
 public static void InitializeOnline(BackgroundWorkerEx worker = null)
 {
     InitializeOnline(LocaleFlags.enUS, worker);
 }
コード例 #11
0
ファイル: Program.cs プロジェクト: veserine/CASCExplorer
        //class Hashes
        //{
        //    public string[] install;
        //    public string[] encoding;
        //}

        static void Main(string[] args)
        {
            //HashSet<string> data = new HashSet<string>();
            //HashSet<string> installs = new HashSet<string>();

            //using (StreamReader sr = new StreamReader("list.txt"))
            //{
            //    string line1;

            //    while((line1 = sr.ReadLine()) != null)
            //    {
            //        data.Add(line1.Substring(19, 32));

            //        if (line1.Contains("install"))
            //        {
            //            installs.Add(line1.Substring(93, 32));
            //        }
            //    }
            //}

            ////foreach (var cfg in data)
            ////{
            ////    string url = string.Format("https://bnet.marlam.in/tpr/wow/config/{0}/{1}/{2}", cfg.Substring(0, 2), cfg.Substring(2, 2), cfg);

            ////    var stream = CDNIndexHandler.OpenFileDirect(url);

            ////    using (var fileStream = File.Create("builds\\" + cfg))
            ////    {
            ////        stream.CopyTo(fileStream);
            ////    }
            ////}

            //Dictionary<string, Hashes> data2 = new Dictionary<string, Hashes>();

            //foreach (var file in Directory.GetFiles("builds"))
            //{
            //    using(var sr = new StreamReader(file))
            //    {
            //        string line;

            //        while ((line = sr.ReadLine()) != null)
            //        {
            //            if (string.IsNullOrWhiteSpace(line) || line.StartsWith("#")) // skip empty lines and comments
            //                continue;

            //            string[] tokens = line.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries);

            //            if (tokens.Length != 2)
            //                throw new Exception("KeyValueConfig: tokens.Length != 2");

            //            var values = tokens[1].Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            //            var valuesList = values.ToList();

            //            if (!data2.ContainsKey(file))
            //                data2[file] = new Hashes();

            //            if (values[0] == "install")
            //            {
            //                data2[file].install = values;
            //            }

            //            if (values[0] == "encoding")
            //            {
            //                data2[file].encoding = values;
            //            }

            //            //sr.Data.Add(tokens[0].Trim(), valuesList);
            //        }
            //    }
            //}

            //Dictionary<string, string> realInstalls = new Dictionary<string, string>();

            //foreach(var kv in data2)
            //{
            //    for(int i = 6; i < kv.Value.install.Length; i++)
            //    {
            //        if (installs.Contains(kv.Value.install[i]))
            //        {
            //            //Console.WriteLine("{0} {1}", kv.Value.install[i], kv.Value.encoding[i]);

            //            realInstalls[kv.Value.install[i]] = kv.Value.encoding[i];
            //        }
            //    }
            //}

            //CASCConfig.ValidateData = false;

            //int buildIndex = 0;

            //foreach (var kvinstall in realInstalls)
            //{
            //    string url1 = string.Format("http://bnet.marlamin.com/tpr/wow/data/{0}/{1}/{2}", kvinstall.Key.Substring(0, 2), kvinstall.Key.Substring(2, 2), kvinstall.Key);

            //    BLTEStream instFile = new BLTEStream(CDNIndexHandler.OpenFileDirect(url1), new MD5Hash());

            //    InstallHandler install = new InstallHandler(new BinaryReader(instFile), null);

            //    //foreach(var ent  in install.GetEntries().Where(e => e.Name.Contains("MacOS")))
            //    //{
            //    //    Console.WriteLine(ent.Name);
            //    //}
            //    //continue;

            //    string url2 = string.Format("http://bnet.marlamin.com/tpr/wow/data/{0}/{1}/{2}", kvinstall.Value.Substring(0, 2), kvinstall.Value.Substring(2, 2), kvinstall.Value);

            //    BLTEStream encFile = new BLTEStream(CDNIndexHandler.OpenFileDirect(url2), new MD5Hash());

            //    EncodingHandler encoding = new EncodingHandler(new BinaryReader(encFile), null);

            //    string[] files = new string[] { "WowB.exe", "WowT.exe", "Wow.exe", "WowB-64.exe", "WowT-64.exe", "Wow-64.exe", "RenderService.exe", "RenderService-64.exe",
            //        @"World of Warcraft Public Test.app\Contents\MacOS\World of Warcraft",
            //        @"World of Warcraft Public Test.app\Contents\MacOS\World of Warcraft 64",
            //        @"World of Warcraft Beta.app\Contents\MacOS\World of Warcraft",
            //        @"World of Warcraft Beta.app\Contents\MacOS\World of Warcraft 64",
            //        @"World of Warcraft Retail.app\Contents\MacOS\World of Warcraft",
            //        @"World of Warcraft Retail.app\Contents\MacOS\World of Warcraft 64",
            //        @"World of Warcraft Test.app\Contents\MacOS\World of Warcraft",
            //        @"World of Warcraft.app\Contents\MacOS\World of Warcraft"
            //    };

            //    string outFolder = "build_" + buildIndex++;

            //    foreach (var file in files)
            //    {
            //        var entries = install.GetEntriesByName(file);

            //        foreach (var entry in entries)
            //        {
            //            bool ok = encoding.GetEntry(entry.MD5, out var encEntry);

            //            if (ok)
            //            {
            //                string chash = encEntry.Key.ToHexString().ToLower();

            //                Console.WriteLine("http://bnet.marlamin.com/tpr/wow/data/{0}/{1}/{2} {3}", chash.Substring(0, 2), chash.Substring(2, 2), chash, file);

            //                string url = string.Format("http://blzddist1-a.akamaihd.net/tpr/wow/data/{0}/{1}/{2}", chash.Substring(0, 2), chash.Substring(2, 2), chash);
            //                //string url = string.Format("http://bnet.marlamin.com/tpr/wow/data/{0}/{1}/{2}", chash.Substring(0, 2), chash.Substring(2, 2), chash);

            //                try
            //                {
            //                    var stream = CDNIndexHandler.OpenFileDirect(url);

            //                    BLTEStream blte3 = new BLTEStream(stream, new MD5Hash());

            //                    string outFile = Path.Combine(outFolder, chash + "_" + file);
            //                    string outDir = Path.GetDirectoryName(outFile);

            //                    if (!Directory.Exists(outDir))
            //                        Directory.CreateDirectory(outDir);

            //                    using (var fileStream = File.Create(outFile))
            //                    {
            //                        blte3.CopyTo(fileStream);
            //                    }
            //                }
            //                catch(Exception exc)
            //                {
            //                    Console.WriteLine(exc.Message);
            //                }
            //            }
            //        }
            //    }
            //}

            //ArmadilloCrypt crypt = new ArmadilloCrypt("sc1Dev");

            //var decr = crypt.DecryptFile(@"c:\Users\TOM_RUS\Downloads\e32f46c7245bfc154e43924555a5cf9f");

            //File.WriteAllBytes("test", decr);

            //byte[] keyBytes = new byte[16];

            //ArmadilloCrypt crypt = new ArmadilloCrypt(keyBytes);

            //string buildconfigfile = "9f6048f8bd01f38ec0be83f4a9fe5a10";

            //byte[] data = File.ReadAllBytes(buildconfigfile);

            //byte[] IV = buildconfigfile.Substring(16).ToByteArray();

            //unsafe
            //{
            //    fixed (byte* ptr = keyBytes)
            //    {
            //        for (ulong i = 0; i < ulong.MaxValue; i++)
            //        {
            //            for (ulong j = 0; j < ulong.MaxValue; j++)
            //            {
            //                byte[] decrypted = crypt.DecryptFile(IV, data);

            //                if (decrypted[0] == 0x23 && decrypted[1] == 0x20 && decrypted[2] == 0x42 && decrypted[3] == 0x75)
            //                {
            //                    Console.WriteLine("key found: {0} {1} ?", i, j);
            //                }

            //                *(ulong*)ptr = j;

            //                if (j % 1000000 == 0)
            //                    Console.WriteLine("{0}/{1}", j, ulong.MaxValue);
            //            }

            //            *(ulong*)(ptr + 8) = i;
            //        }
            //    }
            //}

            if (args.Length != 5)
            {
                Console.WriteLine("Invalid arguments count!");
                Console.WriteLine("Usage: CASCConsole <mode> <pattern|listfile> <destination> <localeFlags> <overrideArchive>");
                return;
            }

            Console.WriteLine("Settings:");
            Console.WriteLine("    WowPath: {0}", Settings.Default.StoragePath);
            Console.WriteLine("    OnlineMode: {0}", Settings.Default.OnlineMode);

            Console.WriteLine("Loading...");

            BackgroundWorkerEx bgLoader = new BackgroundWorkerEx();

            bgLoader.ProgressChanged += BgLoader_ProgressChanged;

            //CASCConfig.LoadFlags |= LoadFlags.Install;

            CASCConfig config = Settings.Default.OnlineMode
                ? CASCConfig.LoadOnlineStorageConfig(Settings.Default.Product, "us")
                : CASCConfig.LoadLocalStorageConfig(Settings.Default.StoragePath, Settings.Default.Product);

            CASCHandler cascHandler = CASCHandler.OpenStorage(config, bgLoader);

            string      mode            = args[0];
            string      pattern         = args[1];
            string      dest            = args[2];
            LocaleFlags locale          = (LocaleFlags)Enum.Parse(typeof(LocaleFlags), args[3]);
            bool        overrideArchive = bool.Parse(args[4]);

            cascHandler.Root.LoadListFile(Path.Combine(Environment.CurrentDirectory, "listfile.csv"), bgLoader);
            CASCFolder root = cascHandler.Root.SetFlags(locale, overrideArchive);

            //cascHandler.Root.MergeInstall(cascHandler.Install);

            Console.WriteLine("Loaded.");

            Console.WriteLine("Extract params:");
            Console.WriteLine("    Mode: {0}", mode);
            Console.WriteLine("    Pattern/Listfile: {0}", pattern);
            Console.WriteLine("    Destination: {0}", dest);
            Console.WriteLine("    LocaleFlags: {0}", locale);
            Console.WriteLine("    OverrideArchive: {0}", overrideArchive);

            if (mode == "pattern")
            {
                Wildcard wildcard = new Wildcard(pattern, true, RegexOptions.IgnoreCase);

                foreach (var file in CASCFolder.GetFiles(root.Entries.Select(kv => kv.Value)))
                {
                    if (wildcard.IsMatch(file.FullName))
                    {
                        ExtractFile(cascHandler, file.Hash, file.FullName, dest);
                    }
                }
            }
            else if (mode == "listfile")
            {
                if (cascHandler.Root is WowRootHandler wowRoot)
                {
                    char[] splitChar = new char[] { ';' };

                    var names = File.ReadLines(pattern).Select(s => s.Split(splitChar, 2)).Select(s => new { id = int.Parse(s[0]), name = s[1] });

                    foreach (var file in names)
                    {
                        ExtractFile(cascHandler, wowRoot.GetHashByFileDataId(file.id), file.name, dest);
                    }
                }
                else
                {
                    var names = File.ReadLines(pattern);

                    foreach (var file in names)
                    {
                        ExtractFile(cascHandler, 0, file, dest);
                    }
                }
            }

            Console.WriteLine("Extracted.");
        }
コード例 #12
0
        static void Main(string[] args)
        {
            //byte[] keyBytes = new byte[16];

            //ArmadilloCrypt crypt = new ArmadilloCrypt(keyBytes);

            //string buildconfigfile = "9f6048f8bd01f38ec0be83f4a9fe5a10";

            //byte[] data = File.ReadAllBytes(buildconfigfile);

            //byte[] IV = buildconfigfile.Substring(16).ToByteArray();

            //unsafe
            //{
            //    fixed (byte* ptr = keyBytes)
            //    {
            //        for (ulong i = 0; i < ulong.MaxValue; i++)
            //        {
            //            for (ulong j = 0; j < ulong.MaxValue; j++)
            //            {
            //                byte[] decrypted = crypt.DecryptFile(IV, data);

            //                if (decrypted[0] == 0x23 && decrypted[1] == 0x20 && decrypted[2] == 0x42 && decrypted[3] == 0x75)
            //                {
            //                    Console.WriteLine("key found: {0} {1} ?", i, j);
            //                }

            //                *(ulong*)ptr = j;

            //                if (j % 1000000 == 0)
            //                    Console.WriteLine("{0}/{1}", j, ulong.MaxValue);
            //            }

            //            *(ulong*)(ptr + 8) = i;
            //        }
            //    }
            //}

            if (args.Length != 4)
            {
                Console.WriteLine("Invalid arguments count!");
                Console.WriteLine("Usage: CASCConsole <pattern> <destination> <localeFlags> <contentFlags>");
                return;
            }

            Console.WriteLine("Settings:");
            Console.WriteLine("    WowPath: {0}", Settings.Default.StoragePath);
            Console.WriteLine("    OnlineMode: {0}", Settings.Default.OnlineMode);

            Console.WriteLine("Loading...");

            BackgroundWorkerEx bgLoader = new BackgroundWorkerEx();

            bgLoader.ProgressChanged += BgLoader_ProgressChanged;

            //CASCConfig.LoadFlags |= LoadFlags.Install;

            CASCConfig config = Settings.Default.OnlineMode
                ? CASCConfig.LoadOnlineStorageConfig(Settings.Default.Product, "us")
                : CASCConfig.LoadLocalStorageConfig(Settings.Default.StoragePath);

            CASCHandler cascHandler = CASCHandler.OpenStorage(config, bgLoader);

            string       pattern = args[0];
            string       dest    = args[1];
            LocaleFlags  locale  = (LocaleFlags)Enum.Parse(typeof(LocaleFlags), args[2]);
            ContentFlags content = (ContentFlags)Enum.Parse(typeof(ContentFlags), args[3]);

            cascHandler.Root.LoadListFile(Path.Combine(Environment.CurrentDirectory, "listfile.txt"), bgLoader);
            CASCFolder root = cascHandler.Root.SetFlags(locale, content);

            //cascHandler.Root.MergeInstall(cascHandler.Install);

            Console.WriteLine("Loaded.");

            Console.WriteLine("Extract params:");
            Console.WriteLine("    Pattern: {0}", pattern);
            Console.WriteLine("    Destination: {0}", dest);
            Console.WriteLine("    LocaleFlags: {0}", locale);
            Console.WriteLine("    ContentFlags: {0}", content);

            Wildcard wildcard = new Wildcard(pattern, true, RegexOptions.IgnoreCase);

            foreach (var file in CASCFolder.GetFiles(root.Entries.Select(kv => kv.Value)))
            {
                if (wildcard.IsMatch(file.FullName))
                {
                    Console.Write("Extracting '{0}'...", file.FullName);

                    try
                    {
                        cascHandler.SaveFileTo(file.FullName, dest);
                        Console.WriteLine(" Ok!");
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine(" Error!");
                        Logger.WriteLine(exc.Message);
                    }
                }
            }

            Console.WriteLine("Extracted.");
        }
コード例 #13
0
        private void Initialize()
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Loading local CASC storage...please wait");
            Console.ResetColor();

            TextWriter console = Console.Out;

            Stopwatch time = new Stopwatch();

            using ManualResetEvent resetEvent         = new ManualResetEvent(false);
            using BackgroundWorkerEx backgroundWorker = new BackgroundWorkerEx();

            backgroundWorker.DoWork += (_, e) =>
            {
                Console.SetOut(TextWriter.Null); // suppress output
                CASCConfig.ThrowOnFileNotFound         = true;
                CASCConfig.ThrowOnMissingDecryptionKey = true;
                CASCConfig config = CASCConfig.LoadLocalStorageConfig(_storagePath);
                CASCHandler = CASCHandler.OpenStorage(config, backgroundWorker);

                LocaleFlags locale = LocaleFlags.All;

                Console.SetOut(console); // enable output
                CASCHandler.Root.LoadListFile(Path.Combine(Environment.CurrentDirectory, "listfile.txt"), backgroundWorker);

                Console.SetOut(TextWriter.Null); // suppress output
                CASCFolderRoot = CASCHandler.Root.SetFlags(locale);
            };

            backgroundWorker.ProgressChanged += (_, e) =>
            {
                // main thread is blocked, so push it on another thread
                Task.Run(() => { DrawProgressBar(e.ProgressPercentage, 100, 72, '#'); });
            };

            backgroundWorker.RunWorkerCompleted += (_, e) =>
            {
                time.Stop();
                Console.SetOut(console); // enable output
                Console.Write("\r");
                DrawProgressBar(100, 100, 72, '#');

                Console.WriteLine();
                Console.WriteLine($"Finished in {time.Elapsed.TotalSeconds:0.####} seconds");
                Console.WriteLine();

                resetEvent.Set();
            };

            try
            {
                // use backgroundworker for progress reporting since it is provided by CASCLib
                // the main thread is blocked until the background process is completed
                time.Start();
                backgroundWorker.RunWorkerAsync();
                resetEvent.WaitOne();
            }
            catch (Exception ex)
            {
                resetEvent.Set();
                Console.SetOut(console);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine();
                Console.WriteLine("Error while opening storage");
                Console.WriteLine(ex.Message);

                Console.ResetColor();
                Environment.Exit(1);
            }
        }
コード例 #14
0
ファイル: Form1.cs プロジェクト: shmilyzxt/WoWMap
        private void OnLoad(object obj, EventArgs ea)
        {
            _cascAction         = new BackgroundWorkerEx();
            _cascAction.DoWork += (sender, e) =>
            {
                if (string.IsNullOrEmpty(_localCascPath))
                {
                    CASC.InitializeOnline(_cascAction);
                }
                else
                {
                    try
                    {
                        CASC.Initialize(_localCascPath, _cascAction);
                    }
                    catch (Exception /* ex */)
                    {
                        MessageBox.Show("Path '" + _localCascPath + "/Data' was not found.", "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            };
            _cascAction.ProgressChanged += (sender, e) =>
            {
                if (e.UserState != null && !string.IsNullOrEmpty((string)e.UserState))
                {
                    _feedbackText.Text = (string)e.UserState;
                }
                _backgroundTaskProgress.Style   = ProgressBarStyle.Continuous;
                _backgroundTaskProgress.Maximum = 100;
                _backgroundTaskProgress.Value   = e.ProgressPercentage;
            };
            _cascAction.RunWorkerCompleted += (sender, e) =>
            {
                if (CASC.Initialized)
                {
                    _dbcAction.RunWorkerAsync();
                }
            };

            _dbcAction         = new BackgroundWorkerEx();
            _dbcAction.DoWork += (sender, e) =>
            {
                switch (_dbcIndex)
                {
                case 0:
                    _mapRecords = new DBC <MapRecord>(@"DBFilesClient\Map.dbc", _dbcAction);
                    break;

                case 1:
                    _areaTableRecords = new DBC <AreaTableRecord>(@"DBFilesClient\AreaTable.dbc", _dbcAction);
                    break;

                case 2:
                    // _areaAssignmentRecords = new DB2<AreaAssignmentRecord>(@"DBFilesClient\AreaAssignment.db2");
                    break;
                }
            };
            _dbcAction.ProgressChanged += (sender, e) =>
            {
                _feedbackText.Text              = string.Format(@"Loading {0} ...", (new[] { "maps", "areas" })[_dbcIndex]);
                _backgroundTaskProgress.Style   = ProgressBarStyle.Continuous;
                _backgroundTaskProgress.Maximum = 100;
                _backgroundTaskProgress.Value   = e.ProgressPercentage;

                switch (_dbcIndex)
                {
                case 0:
                    var mapEntry = (MapRecord)e.UserState;
                    _mapListBox.Items.Add(new MapListBoxEntry
                    {
                        Name      = mapEntry.MapNameLang,
                        Directory = mapEntry.Directory,
                        MapID     = mapEntry.ID
                    });
                    break;

                case 1:
                    // Don't populate yet
                    break;
                }
            };
            _dbcAction.RunWorkerCompleted += (sender, e) =>
            {
                _feedbackText.Text = string.Format(@"{0} loaded.", (new[] { "Maps", "Areas" })[_dbcIndex]);
                ++_dbcIndex;
                if (_dbcIndex < 2)
                {
                    _dbcAction.RunWorkerAsync();
                }
            };
        }