Exemplo n.º 1
0
        private void loadAvailableLeagues()
        {
            availableLeagues = new List<League>();
            var challengeDir = System.AppDomain.CurrentDomain.BaseDirectory + "\\challengeData";
            var dirInfo = new DirectoryInfo(challengeDir);
            FileInfo[] info = dirInfo.GetFiles("challengeData??.*.xml", SearchOption.TopDirectoryOnly);
            foreach (var item in info)
            {
                string xmlPath = item.FullName;
                var league = new League();
                league.XmlFilePath = xmlPath;
                var filename = item.Name;
                int firstDot = filename.IndexOf('.');
                int lastDot = filename.Length - 5;
                var leaguename = filename.Substring(firstDot + 1, lastDot - firstDot);

                if (filename.Contains("1-Month"))
                {
                    //special rule for torment/bloodlines 1 month events
                    if (filename.Contains("HC"))
                    {
                        league.InAppName = "Torment/Bloodlines 1 Month HC";
                        league.ProgressFileName = "Torment-Bloodlines+1-Month+HC";
                        league.UrlName = "Torment%2BBloodlines+1-Month+HC";
                    }
                    else
                    {
                        league.InAppName = "Torment/Bloodlines 1 Month";
                        league.ProgressFileName = "Torment-Bloodlines+1-Month";
                        league.UrlName = "Torment%2BBloodlines+1-Month";
                    }
                }
                else
                {
                    //other leagues
                    league.UrlName = leaguename.Replace("-", "%2F");
                    league.InAppName = leaguename.Replace("-", "/");
                    league.ProgressFileName = leaguename;
                }
                availableLeagues.Add(league);
            }
        }
Exemplo n.º 2
0
        public void initModel()
        {
            IsInitialized = false;
            if (availableLeagues == null)
            {
                loadAvailableLeagues();
            }
            currentLeague = availableLeagues.Where(n => n.InAppName == Properties.Settings.Default.SelectedLeague)?.ElementAt(0);
            if (currentLeague == null)
            {
                currentLeague = availableLeagues.Last();
            }

            var accName = Properties.Settings.Default.AccountName;
            if (loginStatus == LoginStatus.UnChecked && accName != null && accName.Length > 0)
            {
                try
                {
                    CurrentLoginStatus = AccountCheck.checkAccountName(accName);
                }
                catch (WebException e)
                {
                    CurrentLoginStatus = LoginStatus.NetworkError;
                }
            }

            var creator = new DataCreator();
            var info = creator.createChallengeDataListFromXml(currentLeague.XmlFilePath);
            this.leagueInfo = info;
            info.Leaguename = currentLeague.InAppName;
            //try to load saved progress
            challengeProgresses = null;
            var container = SaveLoadPersistentData.loadData(currentLeague.ProgressFileName);
            if (container != null)
            {
                challengeProgresses = container.progress;
                viewOrder = container.order;
                foreach (var item in challengeProgresses)
                {
                    item.rewatchSubprogress();
                }
            }

            //create new progress if failed
            if (challengeProgresses == null)
            {
                challengeProgresses = creator.createChallengeProgressListFromChallengeList(info.ChallengeDatas);
            }

            //observe progress items for changes
            foreach (var item in challengeProgresses)
            {
                item.PropertyChanged += ProgressItemPropertyChanged;
            }
            if (saveProgressTimer != null)
            {
                saveProgressTimer.Dispose();
            }
            saveProgressTimer = new Timer(saveProgressTimerCallback, null, saveProgressInterval, saveProgressInterval);

            //sync if logged in
            if (CurrentLoginStatus == LoginStatus.ValidName)
            {
                syncProgress();
            }

            IsInitialized = true;
        }