コード例 #1
0
        public List <PlayerItem> EmptyStash(string filename)
        {
            Logger.InfoFormat("Looting {0}", filename);

            var pCrypto = new GDCryptoDataBuffer(DataBuffer.ReadBytesFromDisk(filename));
            var items   = new List <Item>();
            var stash   = new Stash();

            if (stash.Read(pCrypto))
            {
                var isHardcore = GlobalPaths.IsHardcore(filename);

                foreach (var tab in stash.Tabs)
                {
                    // Grab the items and clear the tab
                    items.AddRange(Classify(tab).Remaining);
                    tab.Items.Clear();
                }

                _stashWriter.SafelyWriteStash(filename, stash); // TODO: Ideally we should check if it worked.
                Logger.InfoFormat("Looted {0} items from stash", items.Count);

                return(items.Select(m => TransferStashService.Map(m, stash.ModLabel, isHardcore)).ToList());
            }

            Logger.Error("Could not load stash file.");
            Logger.Error("An update from the developer is most likely required.");

            return(new List <PlayerItem>());
        }
コード例 #2
0
        public List <PlayerItem> EmptyStash(string filename)
        {
            Logger.InfoFormat("Looting {0}", filename);

            var pCrypto = new GDCryptoDataBuffer(DataBuffer.ReadBytesFromDisk(filename));
            var items   = new List <Item>();
            var stash   = new Stash();

            if (stash.Read(pCrypto))
            {
                var isHardcore = GlobalPaths.IsHardcore(filename);

                foreach (var tab in stash.Tabs)
                {
                    // Grab the items and clear the tab
                    items.AddRange(tab.Items);
                    tab.Items.Clear();
                }

                SafelyWriteStash(filename, stash);
                Logger.InfoFormat("Looted {0} items from stash", items.Count);

                return(items.Select(m => Map(m, stash.ModLabel, isHardcore, stash.IsExpansion1)).ToList());
            }

            Logger.Error("Could not load stash file.");
            Logger.Error("An update from the developer is most likely required.");

            return(new List <PlayerItem>());
        }
コード例 #3
0
ファイル: ModSelectionHandler.cs プロジェクト: marius00/iagd
        public GDTransferFile[] GetAvailableModSelection()
        {
            var mods = GlobalPaths.GetTransferFiles(_settings.GetPersistent().EnableDowngrades);

            foreach (var entry in _playerItemDao.GetModSelection())
            {
                if (!mods.Any(m =>
                              m.IsHardcore == entry.IsHardcore && m.Mod?.ToLowerInvariant() == entry.Mod?.ToLowerInvariant()))
                {
                    mods.Add(new GDTransferFile {
                        Mod        = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(entry.Mod ?? string.Empty),
                        IsHardcore = entry.IsHardcore,
                        Enabled    = true
                    });
                }
            }

            if (mods.Count != _numAvailableModFiltersLastUpdate)
            {
                List <GDTransferFile> result = new List <GDTransferFile>();
                foreach (var item in mods)
                {
                    item.Enabled = true;
                    result.Add(item);
                }

                mods = result;
            }

            _numAvailableModFiltersLastUpdate = mods.Count;

            return(mods.ToArray());
        }
コード例 #4
0
ファイル: Globals.cs プロジェクト: jacksoncougar/Moonfish2015
        static Halo2( )
        {
            Paths = new GlobalPaths( );
            definedTagGroupsDictionary = new Dictionary <TagClass, Type>(3);
            var assembly = typeof(Moonfish.Tag).Assembly;

            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }
            Type[] types;
            try
            {
                types = assembly.GetTypes( );
            }
            catch (ReflectionTypeLoadException e)

            {
                types = e.Types.Where(t => t != null).ToArray( );
            }
            foreach (var type in types)
            {
                //if (!type.IsNested)
                {
                    if (type.IsDefined(typeof(Tags.TagClassAttribute), false))
                    {
                        TagClass class_of_tag = (type.GetCustomAttributes(typeof(Tags.TagClassAttribute), false)[0] as Tags.TagClassAttribute).TagClass;
                        definedTagGroupsDictionary.Add(class_of_tag, type);
                    }
                }
            }
        }
コード例 #5
0
        static Halo2()
        {
            Paths = new GlobalPaths();
            definedTagGroupsDictionary = new Dictionary <TagClass, Type>(3);
            var assembly = typeof(TagClass).Assembly;

            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }
            Type[] types;
            try
            {
                types = assembly.GetTypes();
            }
            catch (ReflectionTypeLoadException e)
            {
                types = e.Types.Where(t => t != null).ToArray();
            }
            foreach (var type in types.Where(x => x.IsDefined(typeof(TagClassAttribute), false)))
            {
                var tagClassAttribute = type.GetCustomAttributes(typeof(TagClassAttribute), false)[0] as
                                        TagClassAttribute;
                if (tagClassAttribute == null)
                {
                    continue;
                }
                definedTagGroupsDictionary.Add(tagClassAttribute.TagClass, type);
            }
        }
コード例 #6
0
ファイル: LoadFiles.cs プロジェクト: femoreti/BCC_PI_5
 public static void SetPaths()
 {
     globalPaths = new GlobalPaths(
         "C:/Users/Casa Not/Desktop/Senac/Pi 5/trunk/Entrega 3/src/execute.bat",
         "C:/Users/Casa Not/Desktop/Senac/Pi 5/trunk/Entrega 3/predictions/",
         "C:/Users/Casa Not/Desktop/Senac/Pi 5/trunk/Entrega 3/assets/"
         );
 }
コード例 #7
0
ファイル: LoadFiles.cs プロジェクト: femoreti/BCC_PI_5
    public static void LoadXML()
    {
        var         serializer = new XmlSerializer(typeof(GlobalPaths));
        var         stream     = new FileStream(Application.streamingAssetsPath + "/Paths.xml", FileMode.Open);
        GlobalPaths container  = serializer.Deserialize(stream) as GlobalPaths;

        stream.Close();

        globalPaths = container;
    }
コード例 #8
0
        private void StashPicker_Load(object sender, EventArgs e)
        {
            int n = 0;

            foreach (var mod in GlobalPaths.GetTransferFiles(true))
            {
                Control cb = new FirefoxRadioButton {
                    Location = new Point(10, 25 + n * 33),
                    Text     = mod.ToString(),
                    Tag      = mod,
                    Enabled  = !string.IsNullOrEmpty(mod.Filename),
                };

                cb.TabIndex = n;
                cb.TabStop  = true;
                groupBox1.Controls.Add(cb);
                n++;
            }

            this.Height += n * 33;
        }
コード例 #9
0
ファイル: Paths.cs プロジェクト: markchipman/templating-1
 public Paths(IEngineEnvironmentSettings environmentSettings)
 {
     _environmentSettings = environmentSettings;
     Global = new GlobalPaths(this);
     User   = new UserPaths(this);
 }
コード例 #10
0
        /// <summary>
        ///     Loot all the items stored on page X, and store them to the local database
        /// </summary>
        /// <param name="filename"></param>
        private string EmptyPageX(string filename)
        {
            Logger.InfoFormat("Looting {0}", filename);

            var pCrypto = new GDCryptoDataBuffer(DataBuffer.ReadBytesFromDisk(filename));
            var stash   = new Stash();

            if (stash.Read(pCrypto))
            {
                var lootFromIndex = GetStashToLootFrom(stash);
                var isHardcore    = GlobalPaths.IsHardcore(filename);

#if DEBUG
                if (stash.Tabs.Count < 5)
                {
                    while (stash.Tabs.Count < 5)
                    {
                        stash.Tabs.Add(new StashTab());
                    }

                    SafelyWriteStash(filename, stash);
                    Logger.Info("Upgraded stash to 5 pages.");

                    return(string.Empty);
                }
#endif

                // Update the internal listing of unlooted items (in other stash tabs)
                var unlootedLocal = new List <Item>();

                for (var idx = 0; idx < stash.Tabs.Count; idx++)
                {
                    if (idx != lootFromIndex)
                    {
                        unlootedLocal.AddRange(stash.Tabs[idx].Items);
                    }
                }

                Interlocked.Exchange(ref _unlootedItems, new ConcurrentBag <Item>(unlootedLocal));
                StashUpdated?.Invoke(null, null);

                if (stash.Tabs.Count < 2)
                {
                    Logger.WarnFormat($"File \"{filename}\" only contains {stash.Tabs.Count} pages. IA requires at least 2 stash pages to function properly.");
                    return(GlobalSettings.Language.GetTag("iatag_not_enough_stash", filename, stash.Tabs.Count));
                }

                if (stash.Tabs.Count < lootFromIndex + 1)
                {
                    Logger.Warn($"You have configured IA to loot from stash {lootFromIndex + 1} but you only have {stash.Tabs.Count} pages");
                    return(GlobalSettings.Language.GetTag("iatag_invalid_loot_stash_number", lootFromIndex + 1, stash.Tabs.Count));
                }

                if (stash.Tabs[lootFromIndex].Items.Count > 0)
                {
                    _hasLootedItemsOnceThisSession = true;

                    // Grab the items and clear the tab
                    var items = stash.Tabs[lootFromIndex].Items
                                .Where(m => m.StackCount <= 1)
                                .Where(m => !_playerItemDao.Exists(Map(m, stash.ModLabel, isHardcore, stash.IsExpansion1)))
                                .ToList();
                    var notLootedDueToStackSize = stash.Tabs[lootFromIndex].Items.Where(m => m.StackCount > 1).ToList();

                    if (notLootedDueToStackSize.Count > 0)
                    {
                        _setFeedback("Warning", GlobalSettings.Language.GetTag("iatag_feedback_stacked_not_looted", notLootedDueToStackSize.Count));
                    }

                    var notLootedDueToDuplicate = stash.Tabs[lootFromIndex].Items.ToList();

                    notLootedDueToDuplicate.RemoveAll(m => items.Contains(m) || m.StackCount > 1);

                    if (notLootedDueToDuplicate.Count > 0)
                    {
                        _setFeedback("Warning", GlobalSettings.Language.GetTag("iatag_feedback_duplicates_not_looted", notLootedDueToDuplicate.Count));
                    }

                    stash.Tabs[lootFromIndex].Items.RemoveAll(e => items.Any(m => m.Equals(e)));

                    var storedItems = StoreItemsToDatabase(items, stash.ModLabel, isHardcore, stash.IsExpansion1);
                    var message     = GlobalSettings.Language.GetTag("iatag_looted_from_stash", items.Count, lootFromIndex + 1);

                    if (storedItems != null)
                    {
                        Logger.Info(message);

                        if (!SafelyWriteStash(filename, stash))
                        {
                            _playerItemDao.Remove(storedItems);
                        }
                    }

                    _performedLootCallback();

                    return(message);
                }

                Logger.Info($"Looting of stash {lootFromIndex + 1} halted, no items available.");

                return(GlobalSettings.Language.GetTag("iatag_feedback_no_items_to_loot"));
            }

            Logger.Error("Could not load stash file.");
            Logger.Error("An update from the developer is most likely required.");

            return(string.Empty);
        }
コード例 #11
0
ファイル: TransferStashService2.cs プロジェクト: gmy77/iagd
        public List <UserFeedback> Loot(string transferFile)
        {
            Logger.Info($"Checking {transferFile} for items to loot");
            lock (_fileLock) {
                var(stash, errors) = Load(transferFile);
                if (errors.Count > 0)
                {
                    return(errors); // Cannot recover from any of these
                }

                // TODO: Delegate the stash to the crafting service
                List <UserFeedback> feedbacks = new List <UserFeedback>();
                var lootFromStashIdx          = _transferStashService.GetStashToLootFrom(stash);
                if (HasItems(stash, lootFromStashIdx))
                {
                    var classifiedItems = Classify(stash.Tabs[lootFromStashIdx]);

                    // Warn or auto delete bugged duplicates
                    if (classifiedItems.Duplicates.Count > 0)
                    {
                        if (_settings.GetPersistent().DeleteDuplicates)
                        {
                            stash.Tabs[lootFromStashIdx].Items.RemoveAll(e => classifiedItems.Duplicates.Any(m => m.Equals(e)));

                            // No items to loot, so just delete the duplicates.
                            if (classifiedItems.Remaining.Count == 0)
                            {
                                if (!_stashWriter.SafelyWriteStash(transferFile, stash))
                                {
                                    Logger.Error("Fatal error deleting items from Grim Dawn, items has been duplicated.");
                                }
                            }
                        }
                        else
                        {
                            classifiedItems.Duplicates.ForEach(item => Logger.Debug($"NotLootedDuplicate: {item}"));
                            feedbacks.Add(new UserFeedback(UserFeedbackLevel.Warning,
                                                           RuntimeSettings.Language.GetTag("iatag_feedback_duplicates_not_looted", classifiedItems.Duplicates.Count),
                                                           HelpService.GetUrl(HelpService.HelpType.DuplicateItem)
                                                           ));
                        }
                    }

                    if (classifiedItems.Stacked.Count > 0)
                    {
                        classifiedItems.Stacked.ForEach(item => Logger.Debug($"NotLootedStacked: {item}"));
                        feedbacks.Add(new UserFeedback(RuntimeSettings.Language.GetTag("iatag_feedback_stacked_not_looted", classifiedItems.Stacked.Count)));
                    }

                    // Unknown items, database not parsed for these items, IA can't deal with them.
                    if (classifiedItems.Unknown.Count > 0)
                    {
                        classifiedItems.Unknown.ForEach(item => Logger.Debug($"NotLootedUnknown: {item}"));
                        feedbacks.Add(new UserFeedback(
                                          UserFeedbackLevel.Warning,
                                          RuntimeSettings.Language.GetTag("iatag_feedback_unknown_not_looted", classifiedItems.Unknown.Count),
                                          HelpService.GetUrl(HelpService.HelpType.NotLootingUnidentified)
                                          ));
                    }

                    // The items we can actually loot (or delete duplicates)
                    if (classifiedItems.Remaining.Count > 0)
                    {
                        OnUpdate?.Invoke(this, null);

                        stash.Tabs[lootFromStashIdx].Items.RemoveAll(e => classifiedItems.Remaining.Any(m => m.Equals(e)));

                        var isHardcore = GlobalPaths.IsHardcore(transferFile);
                        if (StoreItemsToDatabase(classifiedItems.Remaining, stash.ModLabel, isHardcore))
                        {
                            feedbacks.Add(new UserFeedback(RuntimeSettings.Language.GetTag("iatag_looted_from_stash", classifiedItems.Remaining.Count, lootFromStashIdx + 1)));

                            if (!_stashWriter.SafelyWriteStash(transferFile, stash))
                            {
                                Logger.Error("Fatal error deleting items from Grim Dawn, items has been duplicated.");
                            }

                            // TODO: Do a quick check to see if the items are TRUUUULY gone from the stash?
                        }
                        else
                        {
                            feedbacks.Add(UserFeedback.FromTag("iatag_feedback_unable_to_loot_stash")); // TODO: Not sure what to report here..
                        }
                    }
                }
                else
                {
                    Logger.Info($"No items found in transfer stash {lootFromStashIdx + 1}.");
                    feedbacks.Add(UserFeedback.FromTag("iatag_feedback_no_items_to_loot"));
                }

                return(feedbacks);
            }
        }
コード例 #12
0
        private void MainWindow_Load(object sender, EventArgs e)
        {
            if (Thread.CurrentThread.Name == null)
            {
                Thread.CurrentThread.Name = "UI";
            }

            Logger.Debug("Starting UI initialization");


            // Set version number
            var      version   = Assembly.GetExecutingAssembly().GetName().Version;
            DateTime buildDate = new DateTime(2000, 1, 1)
                                 .AddDays(version.Build)
                                 .AddSeconds(version.Revision * 2);

            statusLabel.Text = statusLabel.Text + $" - {version.Major}.{version.Minor}.{version.Build}.{version.Revision} from {buildDate.ToString("dd/MM/yyyy")}";


            var settingsService = _serviceProvider.Get <SettingsService>();

            ExceptionReporter.EnableLogUnhandledOnThread();
            SizeChanged += OnMinimizeWindow;


            // Chicken and the egg.. search controller needs browser, browser needs search controllers var.
            var databaseItemDao  = _serviceProvider.Get <IDatabaseItemDao>();
            var searchController = _serviceProvider.Get <SearchController>();

            searchController.JsIntegration.OnRequestSetItemAssociations += (s, evvv) => { (evvv as GetSetItemAssociationsEventArgs).Elements = databaseItemDao.GetItemSetAssociations(); };

            _cefBrowserHandler.InitializeChromium(searchController.JsIntegration, Browser_IsBrowserInitializedChanged, tabControl1);
            searchController.Browser = _cefBrowserHandler;
            searchController.JsIntegration.OnClipboard += SetItemsClipboard;

            var playerItemDao = _serviceProvider.Get <IPlayerItemDao>();
            var cacher        = _serviceProvider.Get <TransferStashServiceCache>();

            _parsingService.OnParseComplete += (o, args) => cacher.Refresh();


            var replicaItemDao        = _serviceProvider.Get <IReplicaItemDao>();
            var stashWriter           = new SafeTransferStashWriter(settingsService, _cefBrowserHandler);
            var transferStashService  = new TransferStashService(_serviceProvider.Get <IDatabaseItemStatDao>(), settingsService, stashWriter);
            var transferStashService2 = new TransferStashService2(playerItemDao, cacher, transferStashService, stashWriter, settingsService, _cefBrowserHandler, replicaItemDao);

            _serviceProvider.Add(transferStashService2);

            _transferStashWorker = new TransferStashWorker(transferStashService2, _userFeedbackService);

            _stashFileMonitor.OnStashModified += (_, __) => {
                StashEventArg args = __ as StashEventArg;
                _transferStashWorker.Queue(args?.Filename);

                // May not minimize, but
                _usageStatisticsReporter.ResetLastMinimized();
                _automaticUpdateChecker.ResetLastMinimized();
            };

            if (!_stashFileMonitor.StartMonitoring(GlobalPaths.SavePath))
            {
                MessageBox.Show(RuntimeSettings.Language.GetTag("iatag_ui_cloudsync_mb"));
                _cefBrowserHandler.ShowHelp(HelpService.HelpType.CloudSavesEnabled);

                Logger.Warn("Shutting down IA, unable to monitor stash files.");

                if (!Debugger.IsAttached)
                {
                    Close();
                }
            }



            // Load the grim database
            var grimDawnDetector = _serviceProvider.Get <GrimDawnDetector>();

            if (grimDawnDetector.GetGrimLocations().Count == 0)
            {
                Logger.Warn("Could not find the Grim Dawn install location");
                statusLabel.Text = "Could not find the Grim Dawn install location";

                var timer = new System.Windows.Forms.Timer();
                timer.Tick    += TimerTickLookForGrimDawn;
                timer.Interval = 10000;
                timer.Start();
            }

            // Load recipes
            foreach (string file in GlobalPaths.FormulasFiles)
            {
                if (!string.IsNullOrEmpty(file))
                {
                    bool isHardcore = file.EndsWith("gsh");
                    Logger.InfoFormat("Reading recipes at \"{0}\", IsHardcore={1}", file, isHardcore);
                    _recipeParser.UpdateFormulas(file, isHardcore);
                }
            }


            var buddyItemDao         = _serviceProvider.Get <IBuddyItemDao>();
            var buddySubscriptionDao = _serviceProvider.Get <IBuddySubscriptionDao>();



            _authService = new AuthService(_cefBrowserHandler, new AuthenticationProvider(settingsService), playerItemDao);
            var backupSettings = new BackupSettings(playerItemDao, settingsService, _cefBrowserHandler);

            UIHelper.AddAndShow(backupSettings, backupPanel);

            var onlineSettings = new OnlineSettings(playerItemDao, _authService, settingsService, _cefBrowserHandler, buddyItemDao, buddySubscriptionDao);

            UIHelper.AddAndShow(onlineSettings, onlinePanel);
            _cefBrowserHandler.OnAuthSuccess += (_, __) => onlineSettings.UpdateUi();


            UIHelper.AddAndShow(new ModsDatabaseConfig(DatabaseLoadedTrigger, playerItemDao, _parsingService, grimDawnDetector, settingsService, _cefBrowserHandler, databaseItemDao), modsPanel);

            UIHelper.AddAndShow(new LoggingWindow(), panelLogging);

            var itemTagDao    = _serviceProvider.Get <IItemTagDao>();
            var backupService = new BackupService(_authService, playerItemDao, settingsService);

            _charBackupService   = new CharacterBackupService(settingsService, _authService);
            _backupServiceWorker = new BackupServiceWorker(backupService, _charBackupService);
            searchController.JsIntegration.OnRequestBackedUpCharacterList += (_, args) => {
                RequestCharacterListEventArg a = args as RequestCharacterListEventArg;
                a.Characters = _charBackupService.ListBackedUpCharacters();
            };
            searchController.JsIntegration.OnRequestCharacterDownloadUrl += (_, args) => {
                RequestCharacterDownloadUrlEventArg a = args as RequestCharacterDownloadUrlEventArg;
                a.Url = _charBackupService.GetDownloadUrl(a.Character);
            };

            searchController.OnSearch += (o, args) => backupService.OnSearch();

            _searchWindow = new SplitSearchWindow(_cefBrowserHandler.BrowserControl, SetFeedback, playerItemDao, searchController, itemTagDao, settingsService);
            UIHelper.AddAndShow(_searchWindow, searchPanel);

            searchPanel.Height = searchPanel.Parent.Height;
            searchPanel.Width  = searchPanel.Parent.Width;

            transferStashService2.OnUpdate += (_, __) => { _searchWindow.UpdateListView(); };

            var languagePackPicker = new LanguagePackPicker(itemTagDao, playerItemDao, _parsingService, settingsService);


            var dm = new DarkMode(this);

            UIHelper.AddAndShow(
                new SettingsWindow(
                    _cefBrowserHandler,
                    _tooltipHelper,
                    ListviewUpdateTrigger,
                    playerItemDao,
                    _searchWindow.ModSelectionHandler.GetAvailableModSelection(),
                    transferStashService,
                    transferStashService2,
                    languagePackPicker,
                    settingsService,
                    grimDawnDetector,
                    dm,
                    _automaticUpdateChecker
                    ),
                settingsPanel);


            _itemReplicaService = _serviceProvider.Get <ItemReplicaService>();
            _itemReplicaService.Start();


#if !DEBUG
            _automaticUpdateChecker.CheckForUpdates();
#endif

            Shown += (_, __) => { StartInjector(); };
            _buddyItemsService = new BuddyItemsService(
                buddyItemDao,
                3 * 60 * 1000,
                settingsService,
                _authService,
                buddySubscriptionDao
                );

            // Start the backup task
            _backupBackgroundTask = new BackgroundTask(new FileBackup(playerItemDao, settingsService));

            LocalizationLoader.ApplyLanguage(Controls, RuntimeSettings.Language);
            new EasterEgg(settingsService).Activate(this);

            // Initialize the "stash packer" used to find item positions for transferring items ingame while the stash is open
            {
                _dynamicPacker.Initialize(8, 16);

                var transferFiles = GlobalPaths.GetTransferFiles(settingsService.GetPersistent().EnableDowngrades);
                if (transferFiles.Count > 0)
                {
                    var maxLastAccess = transferFiles.Max(m => m.LastAccess);
                    var file          = transferFiles.First(x => x.LastAccess == maxLastAccess);

                    var stash = TransferStashService.GetStash(file.Filename);
                    if (stash != null)
                    {
                        _dynamicPacker.Initialize(stash.Width, stash.Height);
                        if (stash.Tabs.Count >= 3)
                        {
                            foreach (var item in stash.Tabs[2].Items)
                            {
                                byte[] bx = BitConverter.GetBytes(item.XOffset);
                                uint   x  = (uint)BitConverter.ToSingle(bx, 0);

                                byte[] by = BitConverter.GetBytes(item.YOffset);
                                uint   y  = (uint)BitConverter.ToSingle(by, 0);

                                _dynamicPacker.Insert(item.BaseRecord, item.Seed, x, y);
                            }
                        }
                    }
                }
            }

            var itemReplicaProcessor = _serviceProvider.Get <ItemReplicaProcessor>();
            _messageProcessors.Add(new ItemPositionFinder(_dynamicPacker));
            _messageProcessors.Add(new PlayerPositionTracker(Debugger.IsAttached && false));
            _messageProcessors.Add(new StashStatusHandler());
            _messageProcessors.Add(new CloudDetectorProcessor(SetFeedback));
            _messageProcessors.Add(new GenericErrorHandler());
            _messageProcessors.Add(itemReplicaProcessor);


            RuntimeSettings.StashStatusChanged += GlobalSettings_StashStatusChanged;

            _transferController = new ItemTransferController(
                _cefBrowserHandler,
                SetFeedback,
                SetTooltipAtmouse,
                _searchWindow,
                playerItemDao,
                transferStashService,
                _serviceProvider.Get <ItemStatService>(),
                settingsService
                );
            _transferController.Start();
            Application.AddMessageFilter(new MousewheelMessageFilter());


            var titleTag = RuntimeSettings.Language.GetTag("iatag_ui_itemassistant");
            if (!string.IsNullOrEmpty(titleTag))
            {
                this.Text += $" - {titleTag}";
            }


            // Popup login diag
            if (_authService.CheckAuthentication() == AuthService.AccessStatus.Unauthorized && !settingsService.GetLocal().OptOutOfBackups)
            {
                var t = new System.Windows.Forms.Timer {
                    Interval = 100
                };
                t.Tick += (o, args) => {
                    if (_cefBrowserHandler.BrowserControl.CanExecuteJavascriptInMainFrame)
                    {
                        _authService.Authenticate();
                        t.Stop();
                    }
                };
                t.Start();
            }


            searchController.JsIntegration.ItemTransferEvent += TransferItem;
            new WindowSizeManager(this, settingsService);


            // Suggest translation packs if available
            if (string.IsNullOrEmpty(settingsService.GetLocal().LocalizationFile) && !settingsService.GetLocal().HasSuggestedLanguageChange)
            {
                if (LocalizationLoader.HasSupportedTranslations(grimDawnDetector.GetGrimLocations()))
                {
                    Logger.Debug("A new language pack has been detected, informing end user..");
                    new LanguagePackPicker(itemTagDao, playerItemDao, _parsingService, settingsService).Show(grimDawnDetector.GetGrimLocations());

                    settingsService.GetLocal().HasSuggestedLanguageChange = true;
                }
            }


            if (settingsService.GetPersistent().DarkMode)
            {
                dm.Activate(); // Needs a lot more work before its ready, for example custom components uses Draw and does not respect coloring.
                _cefBrowserHandler.SetDarkMode(settingsService.GetPersistent().DarkMode);
            }

            settingsService.GetLocal().OnMutate += delegate(object o, EventArgs args) { _cefBrowserHandler.SetOnlineBackupsEnabled(!settingsService.GetLocal().OptOutOfBackups); };


            _csvParsingService          = new CsvParsingService(playerItemDao, replicaItemDao, _userFeedbackService, cacher, _transferController, transferStashService, settingsService);
            _csvFileMonitor.OnModified += (_, arg) => {
                var csvEvent = arg as CsvFileMonitor.CsvEvent;
                _csvParsingService.Queue(csvEvent.Filename, csvEvent.Cooldown);
            };
            _csvFileMonitor.StartMonitoring();
            _csvParsingService.Start();

            Logger.Debug("UI initialization complete");
        }
コード例 #13
0
ファイル: StartupService.cs プロジェクト: marius00/iagd
        // TODO: This creates another session instance, should be executed inside the ThreadExecuter
        public static void PrintStartupInfo(SessionFactory factory, SettingsService settings, SqlDialect dialect)
        {
            Logger.Info(settings.GetLocal().StashToLootFrom == 0
                ? "IA is configured to loot from the last stash page"
                : $"IA is configured to loot from stash page #{settings.GetLocal().StashToLootFrom}");

            Logger.Info(settings.GetLocal().StashToDepositTo == 0
                ? "IA is configured to deposit to the second-to-last stash page"
                : $"IA is configured to deposit to stash page #{settings.GetLocal().StashToDepositTo}");

            using (ISession session = factory.OpenSession()) {
                long numItemsStored = session.CreateCriteria <PlayerItem>()
                                      .SetProjection(NHibernate.Criterion.Projections.RowCountInt64())
                                      .UniqueResult <long>();

                if (numItemsStored == 0)
                {
                    Logger.Warn($"There are {numItemsStored} items stored in the database. <---- Unless you just installed IA, this is bad. No items.");
                }
                else
                {
                    Logger.Info($"There are {numItemsStored} items stored in the database.");
                }
            }

            Logger.Info(settings.GetPersistent().ShowRecipesAsItems
                ? "Show recipes as items is enabled"
                : "Show recipes as items is disabled");

            Logger.Info("Transfer to any mod is " + (settings.GetPersistent().TransferAnyMod ? "enabled" : "disabled"));
            Logger.Info("Experimental updates is " + (settings.GetPersistent().SubscribeExperimentalUpdates ? "enabled" : "disabled"));
            Logger.Info("Delete duplicates is " + (settings.GetPersistent().DeleteDuplicates ? "enabled" : "disabled"));
            Logger.Info((new WindowsPrincipal(WindowsIdentity.GetCurrent())).IsInRole(WindowsBuiltInRole.Administrator) ? "Running as administrator" : "Not running with low privileges");

            List <GDTransferFile> mods = GlobalPaths.GetTransferFiles(true);

            if (mods.Count == 0)
            {
                Logger.Warn("No transfer files has been found");
            }
            else
            {
                Logger.Info("The following transfer files has been found:");

                foreach (GDTransferFile mod in mods)
                {
                    var stash = TransferStashService.GetStash(mod.Filename);
                    if (stash?.Tabs.Count < 2)
                    {
                        Logger.Warn($"\"{mod.Filename}\": Mod: \"{mod.Mod}\", HC: {mod.IsHardcore}, Downgrade: {mod.Downgrade}, Tabs: {stash?.Tabs.Count} <=======");
                        Logger.Warn("Stash file does not have enough tabs");
                    }
                    else
                    {
                        Logger.Info($"\"{mod.Filename}\": Mod: \"{mod.Mod}\", HC: {mod.IsHardcore}, Downgrade: {mod.Downgrade}, Tabs: {stash?.Tabs.Count}");
                    }
                }
            }

            Logger.Info("There are items stored for the following mods:");

            foreach (ModSelection entry in new PlayerItemDaoImpl(factory, new DatabaseItemStatDaoImpl(factory, dialect), dialect)
                     .GetModSelection())
            {
                Logger.Info($"Mod: \"{entry.Mod}\", HC: {entry.IsHardcore}");
            }


            string gdPath = settings.GetLocal().CurrentGrimdawnLocation;

            Logger.Info(string.IsNullOrEmpty(gdPath)
                ? "The path to Grim Dawn is unknown (not great)"
                : $"The path to Grim Dawn is \"{gdPath}\"");

            Logger.Info($"Using IA on multiple PCs: {settings.GetPersistent().UsingDualComputer}");

            Logger.Info($"Logged into online backups: {!string.IsNullOrEmpty(settings.GetPersistent().CloudUser)}");
            Logger.Info($"Opted out of online backups: {settings.GetLocal().OptOutOfBackups}");



            using (ISession session = factory.OpenSession()) {
                long num = session.CreateCriteria <DatabaseItem>()
                           .SetProjection(NHibernate.Criterion.Projections.RowCountInt64())
                           .UniqueResult <long>();

                var isGdParsed = num > 0;
                settings.GetLocal().IsGrimDawnParsed = isGdParsed;

                if (isGdParsed)
                {
                    Logger.Info("The Grim Dawn database has been parsed");
                }
                else
                {
                    Logger.Warn("The Grim Dawn database has not been parsed");
                }
            }

            Logger.Info("Startup data dump complete");
        }
コード例 #14
0
        /// <summary>
        ///     Loot all the items stored on page X, and store them to the local database
        /// </summary>
        /// <param name="filename"></param>
        private string EmptyPageX(string filename)
        {
            Logger.InfoFormat("Looting {0}", filename);

            GDCryptoDataBuffer pCrypto = new GDCryptoDataBuffer(DataBuffer.ReadBytesFromDisk(filename));

            Stash stash = new Stash();

            if (stash.Read(pCrypto))
            {
                int lootFromIndex;
                if (Settings.Default.StashToLootFrom == 0)
                {
                    lootFromIndex = stash.Tabs.Count - 1;
                }
                else
                {
                    lootFromIndex = Settings.Default.StashToLootFrom - 1;
                }

                bool isHardcore = GlobalPaths.IsHardcore(filename);

#if DEBUG
                if (stash.Tabs.Count < 5)
                {
                    while (stash.Tabs.Count < 5)
                    {
                        stash.Tabs.Add(new StashTab());
                    }
                    SafelyWriteStash(filename, stash);
                    Logger.Info("Upgraded stash to 5 pages.");
                    return(string.Empty);
                }
#endif

                // Update the internal listing of unlooted items (in other stash tabs)
                List <Item> unlootedLocal = new List <Item>();
                for (var idx = 0; idx < stash.Tabs.Count; idx++)
                {
                    if (idx != lootFromIndex)
                    {
                        unlootedLocal.AddRange(stash.Tabs[idx].Items);
                    }
                }
                Interlocked.Exchange(ref _unlootedItems, new ConcurrentBag <Item>(unlootedLocal));
                StashUpdated?.Invoke(null, null);

                if (stash.Tabs.Count < 2)
                {
                    Logger.WarnFormat(
                        "File \"{0}\" only contains {1} pages, must have at least 2 pages to function properly.",
                        filename, stash.Tabs.Count);
                    return
                        ($"File \"{filename}\" only contains {stash.Tabs.Count} pages, must have at least 2 pages to function properly.");
                }
                if (stash.Tabs.Count < lootFromIndex + 1)
                {
                    var message =
                        $"You have configured IA to loot from {lootFromIndex + 1} but you only have {stash.Tabs.Count} pages";
                    Logger.Warn(message);
                    return(message);
                }

                if (stash.Tabs[lootFromIndex].Items.Count > 0)
                {
                    //_hasLootedItemsOnceThisSession = true;

                    // Grab the items and clear the tab
                    List <Item> items = new List <Item>(stash.Tabs[lootFromIndex].Items);
                    stash.Tabs[lootFromIndex].Items.Clear();

                    List <PlayerItem> storedItems =
                        StoreItemsToDatabase(items, stash.ModLabel, isHardcore, stash.IsExpansion1);
                    if (storedItems != null)
                    {
                        Logger.Info($"Looted {items.Count} items from stash {lootFromIndex + 1}");

                        if (!SafelyWriteStash(filename, stash))
                        {
                            // TODO: Delete from DB
                            _playerItemDao.Remove(storedItems);
                        }
                    }

                    _performedLootCallback();
                    return($"Looted {items.Count} items from stash {lootFromIndex + 1}");
                }
                Logger.Info($"Looting of stash {lootFromIndex + 1} halted, no items available.");
                return(GlobalSettings.Language.GetTag("iatag_feedback_no_items_to_loot"));
            }
            Logger.Error("Could not load stash file.");
            Logger.Error("An update from the developer is most likely required.");

            return(string.Empty);
        }