Example #1
0
        private void overlayUpdate(object sender, EventArgs e)
        {
            if (SharedData.refreshTheme == true)
            {
                loadTheme(SharedData.settings.Theme);

                overlay.Left = SharedData.settings.OverlayX;
                overlay.Top = SharedData.settings.OverlayY;
                overlay.Width = SharedData.settings.OverlayW;
                overlay.Height = SharedData.settings.OverlayH;

                resizeOverlay(overlay.Width, overlay.Height);
                SharedData.refreshTheme = false;
            }

            // offline functionality hax
            if(SharedData.Sessions.SessionList.Count < 1) {
                Sessions.SessionInfo dummysession = new Sessions.SessionInfo();
                SharedData.Sessions.SessionList.Add(dummysession);
            }

            if (SharedData.themeCacheSessionTime != SharedData.currentSessionTime || true)
            {
                SharedData.themeDriverCache = new string[64][][];
                for (Int16 i = 0; i < 64; i++)
                    SharedData.themeDriverCache[i] = new string[4][];
                SharedData.themeSessionStateCache = new string[0];
                SharedData.themeCacheSessionTime = SharedData.currentSessionTime;
                SharedData.cacheFrameCount++;
            }

            // do we allow retirement
            SharedData.allowRetire = true;

            if (SharedData.Sessions.SessionList.Count > 0 &&
                SharedData.Sessions.SessionList[SharedData.overlaySession].State == Sessions.SessionInfo.sessionState.racing &&
                (SharedData.Sessions.SessionList[SharedData.overlaySession].LapsRemaining > 0 &&
                    SharedData.Sessions.SessionList[SharedData.overlaySession].LapsComplete > 1)
                )
            {
                SharedData.allowRetire = true;
            }
            else
            {
                SharedData.allowRetire = false;
            }

            // wait
            SharedData.mutex.WaitOne();
            DateTime mutexLocked = DateTime.Now;

            // calculate points
            SharedData.externalCurrentPoints.Clear();
            Sessions.SessionInfo racesession = SharedData.Sessions.findSessionType(Sessions.SessionInfo.sessionType.race);
            Double leaderpos = racesession.FindPosition(1, dataorder.position).CurrentTrackPct;

            foreach (Sessions.SessionInfo.StandingsItem si in racesession.Standings)
            {
                if (SharedData.externalPoints.ContainsKey(si.Driver.UserId))
                {
                    if (si.Position <= SharedData.theme.pointschema.Length &&
                        (si.CurrentTrackPct / leaderpos) > SharedData.theme.minscoringdistance)
                        SharedData.externalCurrentPoints.Add(si.Driver.UserId, SharedData.externalPoints[si.Driver.UserId] + SharedData.theme.pointschema[si.Position - 1]);
                    else
                        SharedData.externalCurrentPoints.Add(si.Driver.UserId, SharedData.externalPoints[si.Driver.UserId]);
                }
            }

            foreach (KeyValuePair<int, int> driver in SharedData.externalPoints)
            {
                if (!SharedData.externalCurrentPoints.ContainsKey(driver.Key))
                {
                    SharedData.externalCurrentPoints.Add(driver.Key, SharedData.externalPoints[driver.Key]);
                }
            }

            // images
            for (int i = 0; i < images.Length; i++)
            {
                if(SharedData.theme.images[i].presistent) {
                    images[i].Visibility = System.Windows.Visibility.Visible;
                }
                else if (SharedData.theme.images[i].visible != visibility2boolean[images[i].Visibility] || SharedData.theme.images[i].dynamic == true)
                {
                    if (SharedData.theme.images[i].dynamic == true)
                        loadImage(images[i], SharedData.theme.images[i]);

                    images[i].Visibility = boolean2visibility[SharedData.theme.images[i].visible];

                }
            }

            // objects
            for (int i = 0; i < SharedData.theme.objects.Length; i++)
            {
                if (SharedData.theme.objects[i].presistent)
                    objects[i].Visibility = System.Windows.Visibility.Visible;
                else if (SharedData.theme.objects[i].visible != visibility2boolean[objects[i].Visibility])
                    objects[i].Visibility = boolean2visibility[SharedData.theme.objects[i].visible];

                int session;

                if (objects[i].Visibility == System.Windows.Visibility.Visible)
                {
                    switch (SharedData.theme.objects[i].dataset)
                    {
                        case Theme.dataset.standing:
                        case Theme.dataset.points:
                            for (int j = 0; j < SharedData.theme.objects[i].labels.Length; j++) // items
                            {
                                for (int k = 0; k < SharedData.theme.objects[i].itemCount; k++) // drivers
                                {
                                    int driverPos = 1 + k + ((SharedData.theme.objects[i].itemCount + SharedData.theme.objects[i].skip) * SharedData.theme.objects[i].page) + SharedData.theme.objects[i].labels[j].offset + SharedData.theme.objects[i].offset;
                                    Int32 standingsCount = 0;

                                    if (SharedData.theme.objects[i].dataset == Theme.dataset.standing)
                                    {
                                        if (SharedData.theme.objects[i].carclass == null)
                                            standingsCount = SharedData.Sessions.SessionList[SharedData.overlaySession].Standings.Count;
                                        else
                                            standingsCount = SharedData.Sessions.SessionList[SharedData.overlaySession].getClassCarCount(SharedData.theme.objects[i].carclass);
                                    }
                                    else if (SharedData.theme.objects[i].dataset == Theme.dataset.points)
                                        standingsCount = SharedData.externalCurrentPoints.Count;

                                    SharedData.theme.objects[i].pagecount = (int)Math.Ceiling((Double)standingsCount / (Double)SharedData.theme.objects[i].itemCount);

                                    if (SharedData.theme.objects[i].carclass != null)
                                    {
                                        if ((SharedData.theme.objects[i].page + 1) * (SharedData.theme.objects[i].itemCount + SharedData.theme.objects[i].skip) >= SharedData.Sessions.SessionList[SharedData.overlaySession].getClassCarCount(SharedData.theme.objects[i].carclass) ||
                                            (SharedData.theme.objects[i].maxpages > 0 && SharedData.theme.objects[i].page >= SharedData.theme.objects[i].maxpages - 1))
                                        {
                                            SharedData.lastPage[i] = true;
                                        }
                                    }
                                    else
                                    {
                                        if ((SharedData.theme.objects[i].page + 1) * (SharedData.theme.objects[i].itemCount + SharedData.theme.objects[i].skip) >= standingsCount ||
                                            (SharedData.theme.objects[i].maxpages > 0 && SharedData.theme.objects[i].page >= SharedData.theme.objects[i].maxpages - 1))
                                        {
                                            SharedData.lastPage[i] = true;
                                        }
                                    }

                                    if (driverPos <= standingsCount)
                                    {
                                        labels[i][(j * SharedData.theme.objects[i].itemCount) + k].Visibility = System.Windows.Visibility.Visible;

                                        if (SharedData.theme.objects[i].labels[j].session != Theme.sessionType.none)
                                            session = SharedData.sessionTypes[SharedData.theme.objects[i].labels[j].session];
                                        else
                                            session = SharedData.overlaySession;

                                        Sessions.SessionInfo.StandingsItem driver = new Sessions.SessionInfo.StandingsItem();

                                        if (SharedData.theme.objects[i].dataset == Theme.dataset.standing)
                                        {
                                            if (SharedData.Sessions.SessionList[SharedData.overlaySession].Type != Sessions.SessionInfo.sessionType.race && SharedData.theme.objects[i].dataorder == dataorder.liveposition)
                                                driver = SharedData.Sessions.SessionList[session].FindPosition(driverPos, dataorder.position, SharedData.theme.objects[i].carclass);
                                            else
                                                driver = SharedData.Sessions.SessionList[session].FindPosition(driverPos, SharedData.theme.objects[i].dataorder, SharedData.theme.objects[i].carclass);
                                        }
                                        else if (SharedData.theme.objects[i].dataset == Theme.dataset.points)
                                        {
                                            KeyValuePair<int, int> item = SharedData.externalCurrentPoints.OrderByDescending(key => key.Value).Skip(driverPos - 1).FirstOrDefault();
                                            driver = SharedData.Sessions.SessionList[session].Standings.SingleOrDefault(si => si.Driver.UserId == item.Key);
                                            if (driver == null)
                                            {
                                                driver = new Sessions.SessionInfo.StandingsItem();
                                                driver.Driver.UserId = item.Key;
                                            }
                                        }

                                        labels[i][(j * SharedData.theme.objects[i].itemCount) + k].Content = SharedData.theme.formatFollowedText(
                                            SharedData.theme.objects[i].labels[j],
                                            driver,
                                            SharedData.Sessions.SessionList[session]);

                                        if (SharedData.theme.objects[i].labels[j].dynamic == true)
                                        {
                                            Theme.LabelProperties label = new Theme.LabelProperties();
                                            label.text = SharedData.theme.objects[i].labels[j].backgroundImage;

                                            string filename = Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.formatFollowedText(
                                                label,
                                                driver,
                                                SharedData.Sessions.SessionList[session]
                                            );

                                            labels[i][(j * SharedData.theme.objects[i].itemCount) + k].Background = new SolidColorBrush(System.Windows.Media.Colors.Transparent);

                                            if (File.Exists(filename))
                                            {
                                                Brush bg = new ImageBrush(new BitmapImage(new Uri(filename)));
                                                labels[i][(j * SharedData.theme.objects[i].itemCount) + k].Background = bg;
                                            }
                                            else if (File.Exists(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.objects[i].labels[j].defaultBackgroundImage))
                                            {
                                                Brush bg = new ImageBrush(new BitmapImage(new Uri(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.objects[i].labels[j].defaultBackgroundImage)));
                                                labels[i][(j * SharedData.theme.objects[i].itemCount) + k].Background = bg;
                                            }
                                            else
                                            {
                                                labels[i][(j * SharedData.theme.objects[i].itemCount) + k].Background = SharedData.theme.objects[i].labels[j].backgroundColor;
                                            }

                                        }
                                        else if (File.Exists(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.objects[i].labels[j].backgroundImage))
                                        {
                                            Brush bg = new ImageBrush(new BitmapImage(new Uri(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.objects[i].labels[j].backgroundImage)));
                                            labels[i][(j * SharedData.theme.objects[i].itemCount) + k].Background = bg;
                                        }
                                    }
                                    else
                                    {
                                        labels[i][(j * SharedData.theme.objects[i].itemCount) + k].Visibility = System.Windows.Visibility.Hidden;
                                        labels[i][(j * SharedData.theme.objects[i].itemCount) + k].Content = null;
                                        labels[i][(j * SharedData.theme.objects[i].itemCount) + k].Background = SharedData.theme.objects[i].labels[j].backgroundColor;
                                    }
                                }
                            }
                            break;
                        case Theme.dataset.sessionstate:
                            for (int j = 0; j < SharedData.theme.objects[i].labels.Length; j++)
                            {
                                if (SharedData.theme.objects[i].labels[j].session != Theme.sessionType.none)
                                    session = SharedData.sessionTypes[SharedData.theme.objects[i].labels[j].session];
                                else
                                    session = SharedData.overlaySession;

                                labels[i][j].Content = SharedData.theme.formatSessionstateText(
                                        SharedData.theme.objects[i].labels[j],
                                        session);
                            }
                            break;
                        default:
                        case Theme.dataset.followed:
                        case Theme.dataset.radio:
                            bool isRadio = SharedData.theme.objects[i].dataset == Theme.dataset.radio;
                            for (int j = 0; j < SharedData.theme.objects[i].labels.Length; j++)
                            {
                                if (SharedData.theme.objects[i].labels[j].session != Theme.sessionType.none)
                                    session = SharedData.sessionTypes[SharedData.theme.objects[i].labels[j].session];
                                else
                                    session = SharedData.overlaySession;

                                int pos;
                                if (SharedData.theme.objects[i].dataorder == dataorder.liveposition && SharedData.Sessions.SessionList[session].Type == Sessions.SessionInfo.sessionType.race)
                                    pos = SharedData.Sessions.SessionList[session].FollowedDriver.PositionLive;
                                else if (SharedData.theme.objects[i].dataorder == dataorder.trackposition)
                                    pos = 0;
                                else
                                    pos = SharedData.Sessions.SessionList[session].FollowedDriver.Position;

                                int offset = SharedData.theme.objects[i].labels[j].offset + SharedData.theme.objects[i].offset;

                                if ( !isRadio )
                                    labels[i][j].Content = SharedData.theme.formatFollowedText(
                                    SharedData.theme.objects[i].labels[j],
                                     SharedData.Sessions.SessionList[session].FindPosition(pos + offset, SharedData.theme.objects[i].dataorder),
                                    SharedData.Sessions.SessionList[session]);
                                else // Special Case: This is a Voice-Chat
                                    labels[i][j].Content = SharedData.theme.formatFollowedText(
                                    SharedData.theme.objects[i].labels[j],
                                     SharedData.Sessions.SessionList[session].FindDriver(SharedData.currentRadioTransmitcarIdx),
                                    SharedData.Sessions.SessionList[session]);

                                if (SharedData.theme.objects[i].labels[j].dynamic == true)
                                {
                                    Theme.LabelProperties label = new Theme.LabelProperties();
                                    label.text = SharedData.theme.objects[i].labels[j].backgroundImage;

                                    string filename = Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.formatFollowedText(
                                        label,
                                        SharedData.Sessions.SessionList[session].FindPosition(pos + offset, SharedData.theme.objects[i].dataorder),
                                        SharedData.Sessions.SessionList[session]
                                    );

                                    if (File.Exists(filename))
                                    {
                                        Brush bg = new ImageBrush(new BitmapImage(new Uri(filename)));
                                        labels[i][j].Background = bg;
                                    }
                                    else if (File.Exists(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.objects[i].labels[j].defaultBackgroundImage))
                                    {
                                        Brush bg = new ImageBrush(new BitmapImage(new Uri(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.objects[i].labels[j].defaultBackgroundImage)));
                                        labels[i][j].Background = bg;
                                    }
                                    else
                                    {
                                        labels[i][j].Background = SharedData.theme.objects[i].labels[j].backgroundColor;
                                    }
                                }
                            }
                            break;
                    }
                }
                else
                {
                    SharedData.theme.objects[i].page = -1;
                    SharedData.lastPage[i] = false;
                }
            }

            // tickers
            for (int i = 0; i < SharedData.theme.tickers.Length; i++)
            {
                if (SharedData.theme.tickers[i].presistent)
                {
                    tickers[i].Visibility = System.Windows.Visibility.Visible;
                }
                else if (SharedData.theme.tickers[i].visible != visibility2boolean[tickers[i].Visibility])
                {
                    tickers[i].Visibility = boolean2visibility[SharedData.theme.tickers[i].visible];
                    tickerStackpanels[i].Margin = new Thickness(0 - tickerStackpanels[i].ActualWidth, 0, 0, 0);
                }

                if (tickers[i].Visibility == System.Windows.Visibility.Visible)
                {
                    switch (SharedData.theme.tickers[i].dataset)
                    {
                        case Theme.dataset.standing:
                            if (tickerStackpanels[i].Margin.Left + tickerStackpanels[i].ActualWidth <= 0)
                            {
                                // Create tickers
                                int length;
                                if (SharedData.theme.tickers[i].carclass != null)
                                    length = SharedData.Sessions.SessionList[SharedData.overlaySession].getClassCarCount(SharedData.theme.tickers[i].carclass);
                                else
                                    length = SharedData.Sessions.SessionList[SharedData.overlaySession].Standings.Count;

                                tickerScrolls[i].Children.Clear();
                                tickerStackpanels[i].Children.Clear();

                                tickerStackpanels[i] = new StackPanel();
                                tickerStackpanels[i].Margin = new Thickness(SharedData.theme.tickers[i].width, 0, 0, 0);
                                tickerStackpanels[i].Orientation = Orientation.Horizontal;

                                if (SharedData.theme.tickers[i].fillVertical)
                                    tickerRowpanels[i] = new StackPanel[length];

                                //tickers[i].Children.Add(tickerStackpanels[i]);
                                tickerScrolls[i].Children.Add(tickerStackpanels[i]);
                                tickerLabels[i] = new Label[SharedData.Sessions.SessionList[SharedData.overlaySession].Standings.Count * SharedData.theme.tickers[i].labels.Length];

                                // add headers
                                if (SharedData.theme.tickers[i].header.text != null)
                                {
                                    tickerHeaders[i] = DrawLabel(SharedData.theme.tickers[i].header);
                                    tickerHeaders[i].Content = SharedData.theme.tickers[i].header.text;
                                    tickerHeaders[i].Width = Double.NaN;
                                    tickerStackpanels[i].Children.Add(tickerHeaders[i]);
                                }

                                for (int j = 0; j < length; j++) // drivers
                                {
                                    if (SharedData.theme.tickers[i].fillVertical)
                                    {
                                        tickerRowpanels[i][j] = new StackPanel();
                                        tickerStackpanels[i].Children.Add(tickerRowpanels[i][j]);
                                    }

                                    for (int k = 0; k < SharedData.theme.tickers[i].labels.Length; k++) // labels
                                    {
                                        tickerLabels[i][(j * SharedData.theme.tickers[i].labels.Length) + k] = DrawLabel(SharedData.theme.tickers[i].labels[k]);
                                        tickerLabels[i][(j * SharedData.theme.tickers[i].labels.Length) + k].Content = SharedData.theme.formatFollowedText(
                                            SharedData.theme.tickers[i].labels[k],
                                            SharedData.Sessions.SessionList[SharedData.overlaySession].FindPosition(j + 1, SharedData.theme.tickers[i].dataorder, SharedData.theme.tickers[i].carclass),
                                            SharedData.Sessions.SessionList[SharedData.overlaySession]);
                                        if (SharedData.theme.tickers[i].labels[k].width == 0)
                                            tickerLabels[i][(j * SharedData.theme.tickers[i].labels.Length) + k].Width = Double.NaN;

                                        if (SharedData.theme.tickers[i].labels[k].dynamic == true)
                                        {
                                            Theme.LabelProperties label = new Theme.LabelProperties();
                                            label.text = SharedData.theme.tickers[i].labels[k].backgroundImage;

                                            string filename = Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.formatFollowedText(
                                                label,
                                                SharedData.Sessions.SessionList[SharedData.overlaySession].FindPosition(j + 1, SharedData.theme.tickers[i].dataorder),
                                                SharedData.Sessions.SessionList[SharedData.overlaySession]
                                            );

                                            if (File.Exists(filename))
                                            {
                                                Brush bg = new ImageBrush(new BitmapImage(new Uri(filename)));
                                                tickerLabels[i][(j * SharedData.theme.tickers[i].labels.Length) + k].Background = bg;
                                            }
                                            else if (File.Exists(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.tickers[i].labels[k].defaultBackgroundImage))
                                            {
                                                Brush bg = new ImageBrush(new BitmapImage(new Uri(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.tickers[i].labels[k].defaultBackgroundImage)));
                                                tickerLabels[i][(j * SharedData.theme.tickers[i].labels.Length) + k].Background = bg;
                                            }
                                            else
                                            {
                                                tickerLabels[i][(j * SharedData.theme.tickers[i].labels.Length) + k].Background = SharedData.theme.tickers[i].labels[k].backgroundColor;
                                            }
                                        }

                                        if (SharedData.theme.tickers[i].fillVertical)
                                            tickerRowpanels[i][j].Children.Add(tickerLabels[i][(j * SharedData.theme.tickers[i].labels.Length) + k]);
                                        else
                                            tickerStackpanels[i].Children.Add(tickerLabels[i][(j * SharedData.theme.tickers[i].labels.Length) + k]);

                                    }
                                }

                                // add footers
                                if (SharedData.theme.tickers[i].footer.text != null)
                                {
                                    tickerFooters[i] = DrawLabel(SharedData.theme.tickers[i].footer);
                                    tickerFooters[i].Content = SharedData.theme.tickers[i].footer.text;
                                    tickerFooters[i].Width = Double.NaN;
                                    tickerStackpanels[i].Children.Add(tickerFooters[i]);
                                }

                                if(this.FindName("tickerScroll" + i) == null)
                                    this.RegisterName("tickerScroll" + i, tickerStackpanels[i]);

                                Storyboard.SetTargetName(tickerAnimations[i], "tickerScroll" + i);
                                Storyboard.SetTargetProperty(tickerAnimations[i], new PropertyPath(StackPanel.MarginProperty));
                                tickerAnimations[i].From = new Thickness(SharedData.theme.tickers[i].width + tickerStackpanels[i].ActualWidth, 0, 0, 0);
                                tickerAnimations[i].To = new Thickness(0);
                                //tickerAnimations[i].Completed += tickerCompleted;
                                tickerAnimations[i].RepeatBehavior = System.Windows.Media.Animation.RepeatBehavior.Forever;

                                tickerStoryboards[i].Children.Clear();
                                tickerStoryboards[i].Children.Add(tickerAnimations[i]);

                                tickerScrolls[i].Margin = new Thickness(0, 0, 0, 0);

                            }
                            else if (tickerScrolls[i].Margin.Left >= 0 && SharedData.tickerReady[i])
                            {
                                tickerScrolls[i].Margin = new Thickness(0 - tickerStackpanels[i].ActualWidth, 0, 0, 0);
                                tickerAnimations[i].From = new Thickness(SharedData.theme.tickers[i].width + tickerStackpanels[i].ActualWidth, 0, 0, 0);
                                tickerAnimations[i].To = new Thickness(0);
                                tickerAnimations[i].Duration = TimeSpan.FromSeconds(tickerAnimations[i].From.Value.Left / (60 * SharedData.theme.tickers[i].speed));
                                tickerStoryboards[i].Begin(this);
                            }
                            else
                            {
                                // update data
                                tickerAnimations[i].From = new Thickness(SharedData.theme.tickers[i].width + tickerStackpanels[i].ActualWidth, 0, 0, 0);
                                tickerAnimations[i].To = new Thickness(0);
                                Double margin = tickerStackpanels[i].Margin.Left; // +tickerScrolls[i].Margin.Left;

                                int length;
                                if (SharedData.theme.tickers[i].carclass != null)
                                    length = SharedData.Sessions.SessionList[SharedData.overlaySession].getClassCarCount(SharedData.theme.tickers[i].carclass);
                                else
                                    length = SharedData.Sessions.SessionList[SharedData.overlaySession].Standings.Count;

                                for (int j = 0; j < length; j++) // drivers
                                {
                                    for (int k = 0; k < SharedData.theme.tickers[i].labels.Length; k++) // labels
                                    {
                                        if ((j * SharedData.theme.tickers[i].labels.Length) + k < tickerLabels[i].Length)
                                        {
                                            if (margin > (0 - tickerLabels[i][(j * SharedData.theme.tickers[i].labels.Length) + k].DesiredSize.Width) && margin <= SharedData.theme.tickers[i].width)
                                            {
                                                tickerLabels[i][(j * SharedData.theme.tickers[i].labels.Length) + k].Content = SharedData.theme.formatFollowedText(
                                                    SharedData.theme.tickers[i].labels[k],
                                                    SharedData.Sessions.SessionList[SharedData.overlaySession].FindPosition(j + 1, SharedData.theme.tickers[i].dataorder, SharedData.theme.tickers[i].carclass),
                                                    SharedData.Sessions.SessionList[SharedData.overlaySession]);

                                                // fixing label width screwing up ticker.From
                                                if (tickerLabels[i][(j * SharedData.theme.tickers[i].labels.Length) + k].Content.ToString() != "")
                                                    SharedData.tickerReady[i] = true;

                                                if (SharedData.theme.tickers[i].labels[k].dynamic == true)
                                                {
                                                    Theme.LabelProperties label = new Theme.LabelProperties();
                                                    label.text = SharedData.theme.tickers[i].labels[k].backgroundImage;

                                                    string filename = Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.formatFollowedText(
                                                        label,
                                                        SharedData.Sessions.SessionList[SharedData.overlaySession].FindPosition(j + 1, SharedData.theme.tickers[i].dataorder),
                                                        SharedData.Sessions.SessionList[SharedData.overlaySession]
                                                    );

                                                    if (File.Exists(filename))
                                                    {
                                                        Brush bg = new ImageBrush(new BitmapImage(new Uri(filename)));
                                                        tickerLabels[i][(j * SharedData.theme.tickers[i].labels.Length) + k].Background = bg;
                                                    }
                                                    else if (File.Exists(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.tickers[i].labels[k].defaultBackgroundImage))
                                                    {
                                                        Brush bg = new ImageBrush(new BitmapImage(new Uri(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.tickers[i].labels[k].defaultBackgroundImage)));
                                                        tickerLabels[i][(j * SharedData.theme.tickers[i].labels.Length) + k].Background = bg;
                                                    }
                                                    else
                                                    {
                                                        tickerLabels[i][(j * SharedData.theme.tickers[i].labels.Length) + k].Background = SharedData.theme.tickers[i].labels[k].backgroundColor;
                                                    }

                                                }
                                            }

                                            if (SharedData.theme.tickers[i].fillVertical == false)
                                            {
                                                //margin += tickerLabels[i][(j * SharedData.theme.tickers[i].labels.Length) + k].DesiredSize.Width;
                                            }
                                        }
                                    }

                                    if (SharedData.theme.tickers[i].fillVertical == true && j < tickerRowpanels[i].Length)
                                    {
                                        //margin += tickerRowpanels[i][j].DesiredSize.Width;
                                    }
                                }
                            }
                            break;
                        case Theme.dataset.sessionstate:
                            if (/*tickerScrolls[i].Margin.Left +*/ tickerStackpanels[i].ActualWidth + tickerStackpanels[i].Margin.Left <= 0)
                            {
                                // create
                                //tickerScrolls[i].Children.Clear();
                                tickerStackpanels[i].Children.Clear();

                                tickerStackpanels[i] = new StackPanel();
                                tickerStackpanels[i].Margin = new Thickness(SharedData.theme.tickers[i].width, 0, 0, 0);

                                if (SharedData.theme.tickers[i].fillVertical)
                                    tickerStackpanels[i].Orientation = Orientation.Vertical;
                                else
                                    tickerStackpanels[i].Orientation = Orientation.Horizontal;

                                //tickerScrolls[i].Children.Add(tickerStackpanels[i]);
                                tickers[i].Children.Add(tickerStackpanels[i]);
                                tickerLabels[i] = new Label[SharedData.theme.tickers[i].labels.Length];

                                // add headers
                                if (SharedData.theme.tickers[i].header.text != null)
                                {
                                    tickerHeaders[i] = DrawLabel(SharedData.theme.tickers[i].header);
                                    tickerHeaders[i].Content = SharedData.theme.tickers[i].header.text;
                                    tickerHeaders[i].Width = Double.NaN;
                                    tickerStackpanels[i].Children.Add(tickerHeaders[i]);
                                }

                                for (int j = 0; j < SharedData.theme.tickers[i].labels.Length; j++) // drivers
                                {
                                    tickerLabels[i][j] = DrawLabel(SharedData.theme.tickers[i].labels[j]);
                                    tickerLabels[i][j].Content = SharedData.theme.formatSessionstateText(
                                        SharedData.theme.tickers[i].labels[j],
                                        SharedData.overlaySession);
                                    if (SharedData.theme.tickers[i].labels[j].width == 0)
                                        tickerLabels[i][j].Width = Double.NaN;

                                    tickerStackpanels[i].Children.Add(tickerLabels[i][j]);
                                }

                                // add footers
                                if (SharedData.theme.tickers[i].footer.text != null)
                                {
                                    tickerFooters[i] = DrawLabel(SharedData.theme.tickers[i].footer);
                                    tickerFooters[i].Content = SharedData.theme.tickers[i].footer.text;
                                    tickerFooters[i].Width = Double.NaN;
                                    tickerStackpanels[i].Children.Add(tickerFooters[i]);
                                }

                                /*
                                if (this.FindName("tickerScroll" + i) == null)
                                    this.RegisterName("tickerScroll" + i, tickerStackpanels[i]);

                                Storyboard.SetTargetName(tickerAnimations[i], "tickerScroll" + i);
                                Storyboard.SetTargetProperty(tickerAnimations[i], new PropertyPath(StackPanel.MarginProperty));
                                tickerAnimations[i].From = new Thickness(SharedData.theme.tickers[i].width + tickerStackpanels[i].ActualWidth, 0, 0, 0);
                                tickerAnimations[i].To = new Thickness(0);
                                tickerAnimations[i].RepeatBehavior = System.Windows.Media.Animation.RepeatBehavior.Forever;

                                tickerStoryboards[i].Children.Clear();
                                tickerStoryboards[i].Children.Add(tickerAnimations[i]);

                                tickerScrolls[i].Margin = new Thickness(0, 0, 0, 0);
                                */

                            }
                            else
                            {
                                /*
                                if (tickerScrolls[i].Margin.Left == 0)
                                {
                                    tickerScrolls[i].Margin = new Thickness(0 - tickerStackpanels[i].ActualWidth, 0, 0, 0);
                                    tickerAnimations[i].From = new Thickness(SharedData.theme.tickers[i].width + tickerStackpanels[i].ActualWidth, 0, 0, 0);
                                    tickerAnimations[i].Duration = TimeSpan.FromSeconds(tickerAnimations[i].From.Value.Left / 120);
                                    tickerStoryboards[i].Begin(this);
                                }
                                */

                                // update data
                                Double margin = tickerStackpanels[i].Margin.Left; // + tickerScrolls[i].Margin.Left;
                                for (int k = 0; k < SharedData.theme.tickers[i].labels.Length; k++) // labels
                                {
                                    if (k < tickerLabels[i].Length)
                                    {
                                        if (margin > (0 - tickerLabels[i][k].DesiredSize.Width) && margin < SharedData.theme.tickers[i].width)
                                        {
                                            tickerLabels[i][k].Content = SharedData.theme.formatSessionstateText(
                                                SharedData.theme.tickers[i].labels[k],
                                                SharedData.overlaySession);

                                            if (SharedData.theme.tickers[i].labels[k].dynamic == true)
                                            {
                                                Theme.LabelProperties label = new Theme.LabelProperties();
                                                label.text = SharedData.theme.tickers[i].labels[k].backgroundImage;

                                                string filename = Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.formatSessionstateText(
                                                    label,
                                                    SharedData.overlaySession
                                                );

                                                if (File.Exists(filename))
                                                {
                                                    Brush bg = new ImageBrush(new BitmapImage(new Uri(filename)));
                                                    tickerLabels[i][k].Background = bg;
                                                }
                                                else if (File.Exists(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.tickers[i].labels[k].defaultBackgroundImage))
                                                {
                                                    Brush bg = new ImageBrush(new BitmapImage(new Uri(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.tickers[i].labels[k].defaultBackgroundImage)));
                                                    tickerLabels[i][k].Background = bg;
                                                }
                                                else
                                                {
                                                    tickerLabels[i][k].Background = SharedData.theme.tickers[i].labels[k].backgroundColor;
                                                }

                                            }
                                        }
                                        margin += tickerLabels[i][k].DesiredSize.Width;
                                    }
                                }
                                /*
                                // old scroll
                                Thickness scroller = tickerStackpanels[i].Margin;
                                scroller.Left -= Properties.Settings.Default.TickerSpeed;
                                tickerStackpanels[i].Margin = scroller;
                                    * */
                            }
                            break;
                        default:
                        case Theme.dataset.followed:
                            if (tickerStackpanels[i].ActualWidth + tickerStackpanels[i].Margin.Left <= 0)
                            {
                                // create
                                //tickerScrolls[i].Children.Clear();
                                tickerStackpanels[i].Children.Clear();

                                tickerStackpanels[i] = new StackPanel();
                                tickerStackpanels[i].Margin = new Thickness(SharedData.theme.tickers[i].width, 0, 0, 0);

                                if (SharedData.theme.tickers[i].fillVertical)
                                    tickerStackpanels[i].Orientation = Orientation.Vertical;
                                else
                                    tickerStackpanels[i].Orientation = Orientation.Horizontal;

                                //tickerScrolls[i].Children.Add(tickerStackpanels[i]);
                                tickers[i].Children.Add(tickerStackpanels[i]);

                                tickerLabels[i] = new Label[SharedData.theme.tickers[i].labels.Length];

                                // add headers
                                if (SharedData.theme.tickers[i].header.text != null)
                                {
                                    tickerHeaders[i] = DrawLabel(SharedData.theme.tickers[i].header);
                                    tickerHeaders[i].Content = SharedData.theme.tickers[i].header.text;
                                    tickerHeaders[i].Width = Double.NaN;
                                    tickerStackpanels[i].Children.Add(tickerHeaders[i]);
                                }

                                for (int j = 0; j < SharedData.theme.tickers[i].labels.Length; j++) // drivers
                                {
                                    tickerLabels[i][j] = DrawLabel(SharedData.theme.tickers[i].labels[j]);
                                    if (SharedData.theme.tickers[i].labels[j].width == 0)
                                        tickerLabels[i][j].Width = Double.NaN;

                                    tickerStackpanels[i].Children.Add(tickerLabels[i][j]);
                                }

                                // add footers
                                if (SharedData.theme.tickers[i].footer.text != null)
                                {
                                    tickerFooters[i] = DrawLabel(SharedData.theme.tickers[i].footer);
                                    tickerFooters[i].Content = SharedData.theme.tickers[i].footer.text;
                                    tickerFooters[i].Width = Double.NaN;
                                    tickerStackpanels[i].Children.Add(tickerFooters[i]);
                                }

                                /*
                                if (this.FindName("tickerScroll" + i) == null)
                                    this.RegisterName("tickerScroll" + i, tickerStackpanels[i]);

                                Storyboard.SetTargetName(tickerAnimations[i], "tickerScroll" + i);
                                Storyboard.SetTargetProperty(tickerAnimations[i], new PropertyPath(StackPanel.MarginProperty));

                                tickerAnimations[i].From = new Thickness(SharedData.theme.tickers[i].width, 0, 0, 0);
                                tickerStackpanels[i].Margin = new Thickness(SharedData.theme.tickers[i].width, 0, 0, 0);
                                tickerAnimations[i].To = new Thickness(0);
                                tickerAnimations[i].RepeatBehavior = System.Windows.Media.Animation.RepeatBehavior.Forever;
                                tickerAnimations[i].Duration = TimeSpan.FromSeconds(tickerAnimations[i].From.Value.Left / 120);

                                tickerStoryboards[i].Children.Clear();
                                tickerStoryboards[i].Children.Add(tickerAnimations[i]);
                                //tickerStoryboards[i].Begin(this);

                                tickerScrolls[i].Margin = new Thickness(0, 0, 0, 0);
                                    * */
                            }
                            else
                            {
                                /*
                                if (tickerScrolls[i].Margin.Left == 0)
                                {

                                    tickerScrolls[i].Margin = new Thickness(0 - tickerStackpanels[i].ActualWidth, 0, 0, 0);
                                    tickerAnimations[i].From = new Thickness(SharedData.theme.tickers[i].width + tickerStackpanels[i].ActualWidth, 0, 0, 0);
                                    //tickerAnimations[i].To = new Thickness(0);
                                    //tickerAnimations[i].RepeatBehavior = System.Windows.Media.Animation.RepeatBehavior.Forever;
                                    //tickerAnimations[i].Duration = TimeSpan.FromSeconds(tickerAnimations[i].From.Value.Left / 120);
                                    //tickerStackpanels[i].Margin = new Thickness(SharedData.theme.tickers[i].width + (tickerStackpanels[i].ActualWidth * 2), 0, 0, 0);
                                    //tickerStoryboards[i].Begin(this);
                                    //tickerStoryboards[i].Resume(this);

                                }
                                */
                                // update data
                                for (int k = 0; k < SharedData.theme.tickers[i].labels.Length; k++) // labels
                                {
                                    if (k < tickerLabels[i].Length)
                                    {
                                        tickerLabels[i][k].Content = SharedData.theme.formatFollowedText(
                                            SharedData.theme.tickers[i].labels[k],
                                            SharedData.Sessions.SessionList[SharedData.overlaySession].FollowedDriver,
                                            SharedData.Sessions.SessionList[SharedData.overlaySession]);

                                        if (SharedData.theme.tickers[i].labels[k].dynamic == true)
                                        {
                                            Theme.LabelProperties label = new Theme.LabelProperties();
                                            label.text = SharedData.theme.tickers[i].labels[k].backgroundImage;

                                            string filename = Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.formatFollowedText(
                                                label,
                                                SharedData.Sessions.SessionList[SharedData.overlaySession].FollowedDriver,
                                                SharedData.Sessions.SessionList[SharedData.overlaySession]
                                            );

                                            if (File.Exists(filename))
                                            {
                                                Brush bg = new ImageBrush(new BitmapImage(new Uri(filename)));
                                                tickerLabels[i][k].Background = bg;
                                            }
                                            else if (File.Exists(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.tickers[i].labels[k].defaultBackgroundImage))
                                            {
                                                Brush bg = new ImageBrush(new BitmapImage(new Uri(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.tickers[i].labels[k].defaultBackgroundImage)));
                                                tickerLabels[i][k].Background = bg;
                                            }
                                            else
                                            {
                                                tickerLabels[i][k].Background = SharedData.theme.tickers[i].labels[k].backgroundColor;
                                            }

                                        }
                                    }
                                }
                                /*
                                // old scroll
                                Thickness scroller = tickerStackpanels[i].Margin;
                                scroller.Left -= Properties.Settings.Default.TickerSpeed;
                                tickerStackpanels[i].Margin = scroller;
                                    * */
                            }
                            break;
                    }
                }
                    /*
                else if (tickerStackpanels[i].Margin.Left + tickerStackpanels[i].ActualWidth > 0)
                {
                    tickerStackpanels[i].Margin = new Thickness(0 - tickerStackpanels[i].ActualWidth, 0, 0, 0);
                }
                        * */
            }

            // start lights
            /*
            for (int i = 0; i < SharedData.theme.images.Length; i++)
            {
                if (SharedData.theme.images[i].light != Theme.lights.none && SharedData.theme.images[i].visible == true)
                {
                    if (SharedData.Sessions.SessionList[SharedData.overlaySession].StartLight == Sessions.SessionInfo.sessionStartLight.set)
                    {
                        if (SharedData.theme.images[i].light == Theme.lights.red)
                            images[i].Visibility = System.Windows.Visibility.Visible;
                        else
                            images[i].Visibility = System.Windows.Visibility.Hidden;
                    }
                    else if (SharedData.Sessions.SessionList[SharedData.overlaySession].StartLight == Sessions.SessionInfo.sessionStartLight.go)
                    {
                        if (SharedData.theme.images[i].light == Theme.lights.green)
                            images[i].Visibility = System.Windows.Visibility.Visible;
                        else
                            images[i].Visibility = System.Windows.Visibility.Hidden;
                    }
                    else if (SharedData.Sessions.SessionList[SharedData.overlaySession].StartLight == Sessions.SessionInfo.sessionStartLight.off)
                    {
                        if (SharedData.theme.images[i].light == Theme.lights.off)
                            images[i].Visibility = System.Windows.Visibility.Visible;
                        else
                            images[i].Visibility = System.Windows.Visibility.Hidden;
                    }
                }
            }

            for (int i = 0; i < SharedData.theme.images.Length; i++)
            {
                // flags
                if (SharedData.theme.images[i].flag != Theme.flags.none && SharedData.theme.images[i].visible == true)
                {
                    // race
                    if (SharedData.Sessions.SessionList[SharedData.overlaySession].State == Sessions.SessionInfo.sessionState.racing)
                    {
                        // yellow
                        if (SharedData.Sessions.SessionList[SharedData.overlaySession].Flag == Sessions.SessionInfo.sessionFlag.yellow)
                        {
                            if (SharedData.theme.images[i].flag == Theme.flags.yellow)
                                images[i].Visibility = System.Windows.Visibility.Visible;
                            else
                                images[i].Visibility = System.Windows.Visibility.Hidden;
                        }

                        // white
                        else if (SharedData.Sessions.SessionList[SharedData.overlaySession].Flag == Sessions.SessionInfo.sessionFlag.white)
                        {
                            if(SharedData.theme.images[i].flag == Theme.flags.white)
                                images[i].Visibility = System.Windows.Visibility.Visible;
                            else
                                images[i].Visibility = System.Windows.Visibility.Hidden;
                        }
                        // green
                        else
                        {
                            if (SharedData.theme.images[i].flag == Theme.flags.green)
                                images[i].Visibility = System.Windows.Visibility.Visible;
                            else
                                images[i].Visibility = System.Windows.Visibility.Hidden;
                        }

                    }
                    // finishing
                    else if (SharedData.Sessions.SessionList[SharedData.overlaySession].State == Sessions.SessionInfo.sessionState.checkered ||
                        SharedData.Sessions.SessionList[SharedData.overlaySession].State == Sessions.SessionInfo.sessionState.cooldown)
                    {
                        if (SharedData.theme.images[i].flag == Theme.flags.checkered)
                            images[i].Visibility = System.Windows.Visibility.Visible;
                        else
                            images[i].Visibility = System.Windows.Visibility.Hidden;
                    }
                    // gridding & pace lap
                    else if (SharedData.Sessions.SessionList[SharedData.overlaySession].State != Sessions.SessionInfo.sessionState.gridding ||
                        SharedData.Sessions.SessionList[SharedData.overlaySession].State != Sessions.SessionInfo.sessionState.pacing ||
                        SharedData.Sessions.SessionList[SharedData.overlaySession].State != Sessions.SessionInfo.sessionState.warmup)
                    {
                        if (SharedData.theme.images[i].flag == Theme.flags.yellow)
                            images[i].Visibility = System.Windows.Visibility.Visible;
                        else
                            images[i].Visibility = System.Windows.Visibility.Hidden;
                    }
                    else
                        images[i].Visibility = System.Windows.Visibility.Hidden;
                }

                // replay transition
                if (SharedData.theme.images[i].replay == true)
                {
                    if (SharedData.replayInProgress)
                        images[i].Visibility = System.Windows.Visibility.Visible;
                    else
                        images[i].Visibility = System.Windows.Visibility.Hidden;
                }
            }
            */
            // videos
            for (int i = 0; i < videos.Length; i++)
            {
                if (SharedData.theme.videos[i].visible != visibility2boolean[videos[i].Visibility])
                    videos[i].Visibility = boolean2visibility[SharedData.theme.videos[i].visible];

                if (videos[i].Visibility == System.Windows.Visibility.Visible && SharedData.theme.videos[i].playing == false)
                {
                    videoBoxes[i].Visibility = System.Windows.Visibility.Visible;

                    videos[i].Position = new TimeSpan(0);
                    videos[i].Play();

                    SharedData.theme.videos[i].playing = true;

                    if (SharedData.theme.videos[i].loop == true)
                    {
                        videos[i].UnloadedBehavior = MediaState.Manual;
                        videos[i].MediaEnded += new RoutedEventHandler(loopVideo);
                    }
                    else
                        videos[i].UnloadedBehavior = MediaState.Close;
                }
                else if (videos[i].NaturalDuration.HasTimeSpan && videos[i].Position >= videos[i].NaturalDuration.TimeSpan && SharedData.theme.videos[i].playing == true)
                {
                    SharedData.theme.videos[i].playing = false;
                    SharedData.theme.videos[i].visible = false;
                    videoBoxes[i].Visibility = System.Windows.Visibility.Hidden;
                    videos[i].Visibility = boolean2visibility[SharedData.theme.videos[i].visible];
                }
            }

            // sounds
            for (int i = 0; i < sounds.Length; i++)
            {
                if (SharedData.theme.sounds[i].playing == true)
                {

                    // start
                    if (sounds[i].Position == new TimeSpan(0))
                    {
                        sounds[i].Position = new TimeSpan(0);
                        sounds[i].Play();

                        if (SharedData.theme.sounds[i].loop == true)
                        {
                            sounds[i].MediaEnded += new EventHandler(loopSound);
                        }
                    }
                    // stop
                    else if (sounds[i].NaturalDuration.HasTimeSpan && sounds[i].Position >= sounds[i].NaturalDuration.TimeSpan)
                    {
                        SharedData.theme.sounds[i].playing = false;
                    }
                }
                else
                {
                    if(sounds[i].Position > new TimeSpan(0))
                        sounds[i].Stop();
                }
            }

            // scripts
            SharedData.scripting.OverlayTick(overlay);

            SharedData.overlayUpdateTime = (Int32)(DateTime.Now - mutexLocked).TotalMilliseconds;
            SharedData.mutex.ReleaseMutex();
        }
Example #2
0
        private void parser(string yaml)
        {
            int start = 0;
            int end = 0;
            int length = 0;

            length = yaml.Length;
            start = yaml.IndexOf("WeekendInfo:\n", 0, length);
            end = yaml.IndexOf("\n\n", start, length - start);

            string WeekendInfo = yaml.Substring(start, end - start);
            SharedData.Track.length = (Single)parseDoubleValue(WeekendInfo, "TrackLength", "km") * 1000;
            SharedData.Track.id = parseIntValue(WeekendInfo, "TrackID");
            SharedData.Track.turns = parseIntValue(WeekendInfo, "TrackNumTurns");
            SharedData.Track.city = parseStringValue(WeekendInfo, "TrackCity");
            SharedData.Track.country = parseStringValue(WeekendInfo, "TrackCountry");

            SharedData.Track.altitude = (Single)parseDoubleValue(WeekendInfo, "TrackAltitude", "m");
            SharedData.Track.sky = parseStringValue(WeekendInfo, "TrackSkies");
            SharedData.Track.tracktemp = (Single)parseDoubleValue(WeekendInfo, "TrackSurfaceTemp", "C");
            SharedData.Track.airtemp = (Single)parseDoubleValue(WeekendInfo, "TrackAirTemp", "C");
            SharedData.Track.airpressure = (Single)parseDoubleValue(WeekendInfo, "TrackAirPressure", "Hg");
            SharedData.Track.windspeed = (Single)parseDoubleValue(WeekendInfo, "TrackWindVel", "m/s");
            SharedData.Track.winddirection = (Single)parseDoubleValue(WeekendInfo, "TrackWindDir", "rad");
            SharedData.Track.humidity = parseIntValue(WeekendInfo, "TrackRelativeHumidity", "%");
            SharedData.Track.fog = parseIntValue(WeekendInfo, "TrackFogLevel", "%");

            if (parseIntValue(WeekendInfo, "Official") == 0 &&
                parseIntValue(WeekendInfo, "SeasonID") == 0 &&
                parseIntValue(WeekendInfo, "SeriesID") == 0)
                SharedData.Sessions.Hosted = true;
            else
                SharedData.Sessions.Hosted = false;

            IniFile trackNames;

            string filename = Directory.GetCurrentDirectory() + "\\themes\\" + SharedData.theme.name + "\\tracks.ini";
            if (!File.Exists(filename))
                filename = Directory.GetCurrentDirectory() + "\\tracks.ini";

            if (File.Exists(filename))
            {
                trackNames = new IniFile(filename);
                SharedData.Track.name = trackNames.IniReadValue("Tracks", SharedData.Track.id.ToString());
            }

            SharedData.Sessions.SessionId = parseIntValue(WeekendInfo, "SessionID");
            SharedData.Sessions.SubSessionId = parseIntValue(WeekendInfo, "SubSessionID");

            length = yaml.Length;
            start = yaml.IndexOf("DriverInfo:\n", 0, length);
            end = yaml.IndexOf("\n\n", start, length - start);

            string DriverInfo = yaml.Substring(start, end - start);

            length = DriverInfo.Length;
            start = DriverInfo.IndexOf(" Drivers:\n", 0, length);
            end = length;

            string Drivers = DriverInfo.Substring(start, end - start - 1);
            string[] driverList = Drivers.Split(new string[] { "\n - " }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string driver in driverList)
            {
                int userId = parseIntValue(driver, "UserID");
                if (userId < Int32.MaxValue && userId > 0)
                {
                    int index = SharedData.Drivers.FindIndex(d => d.UserId.Equals(userId));
                    if (index < 0 &&
                        parseStringValue(driver, "CarPath") != "safety pcfr500s" &&
                        parseStringValue(driver, "AbbrevName") != "Pace Car")
                    {
                        if (SharedData.settings.IncludeMe || (!SharedData.settings.IncludeMe && parseIntValue(driver, "CarIdx") != 63))
                        {
                            DriverInfo driverItem = new DriverInfo();

                            driverItem.Name = parseStringValue(driver, "UserName");

                            if (parseStringValue(driver, "AbbrevName") != null)
                            {
                                string[] splitName = parseStringValue(driver, "AbbrevName").Split(',');
                                if (splitName.Length > 1)
                                    driverItem.Shortname = splitName[1] + " " + splitName[0];
                                else
                                    driverItem.Shortname = parseStringValue(driver, "AbbrevName");
                            }
                            driverItem.Initials = parseStringValue(driver, "Initials");
                            driverItem.Club = parseStringValue(driver, "ClubName");
                            driverItem.NumberPlate = parseStringValue(driver, "CarNumber");
                            driverItem.CarId = parseIntValue(driver, "CarID");
                            driverItem.CarClass = parseIntValue(driver, "CarClassID");
                            driverItem.UserId = parseIntValue(driver, "UserID");
                            driverItem.CarIdx = parseIntValue(driver, "CarIdx");
                            driverItem.CarClassName = SharedData.theme.getCarClass(driverItem.CarId);
                            driverItem.iRating = parseIntValue(driver, "IRating");

                            int liclevel = parseIntValue(driver, "LicLevel");
                            int licsublevel = parseIntValue(driver, "LicSubLevel");

                            switch (liclevel)
                            {
                                case 0:
                                case 1:
                                case 2:
                                case 3:
                                case 4:
                                    driverItem.SR = "R" + ((double)licsublevel / 100).ToString("0.00");
                                    break;
                                case 5:
                                case 6:
                                case 7:
                                case 8:
                                    driverItem.SR = "D" + ((double)licsublevel / 100).ToString("0.00");
                                    break;
                                case 9:
                                case 10:
                                case 11:
                                case 12:
                                    driverItem.SR = "C" + ((double)licsublevel / 100).ToString("0.00");
                                    break;
                                case 14:
                                case 15:
                                case 16:
                                case 17:
                                    driverItem.SR = "B" + ((double)licsublevel / 100).ToString("0.00");
                                    break;
                                case 18:
                                case 19:
                                case 20:
                                case 21:
                                    driverItem.SR = "A" + ((double)licsublevel / 100).ToString("0.00");
                                    break;
                                case 22:
                                case 23:
                                case 24:
                                case 25:
                                    driverItem.SR = "P" + ((double)licsublevel / 100).ToString("0.00");
                                    break;
                                case 26:
                                case 27:
                                case 28:
                                case 29:
                                    driverItem.SR = "WC" + ((double)licsublevel / 100).ToString("0.00");
                                    break;
                                default:
                                    driverItem.SR = "Unknown";
                                    break;
                            }

                            driverItem.CarClass = -1;
                            int carclass = parseIntValue(driver, "CarClassID");
                            int freeslot = -1;

                            for (int i = 0; i < SharedData.Classes.Length; i++)
                            {
                                if (SharedData.Classes[i] == carclass)
                                {
                                    driverItem.CarClass = i;
                                }
                                else if (SharedData.Classes[i] == -1 && freeslot < 0)
                                {
                                    freeslot = i;
                                }
                            }

                            if (driverItem.CarClass < 0 && freeslot >= 0)
                            {
                                SharedData.Classes[freeslot] = carclass;
                                driverItem.CarClass = freeslot;
                            }

                            if (!SharedData.externalPoints.ContainsKey(userId) && driverItem.CarIdx < 60)
                                SharedData.externalPoints.Add(userId, 0);

                            // fix bugges
                            if (driverItem.NumberPlate == null)
                                driverItem.NumberPlate = "000";
                            if (driverItem.Initials == null)
                                driverItem.Initials = "";

                            SharedData.Drivers.Add(driverItem);
                        }
                    }
                }
            }

            length = yaml.Length;
            start = yaml.IndexOf("SessionInfo:\n", 0, length);
            end = yaml.IndexOf("\n\n", start, length - start);

            string SessionInfo = yaml.Substring(start, end - start);

            length = SessionInfo.Length;
            start = SessionInfo.IndexOf(" Sessions:\n", 0, length);
            end = length;

            string Sessions = SessionInfo.Substring(start, end - start);
            string[] sessionList = Sessions.Split(new string[] { "\n - " }, StringSplitOptions.RemoveEmptyEntries);

            // Get Current running Session
            int _CurrentSession = (int)sdk.GetData("SessionNum");

            foreach (string session in sessionList)
            {
                int sessionNum = parseIntValue(session, "SessionNum");
                if (sessionNum < Int32.MaxValue)
                {
                    int sessionIndex = SharedData.Sessions.SessionList.FindIndex(s => s.Id.Equals(sessionNum));
                    if (sessionIndex < 0) // add new session item
                    {
                        Sessions.SessionInfo sessionItem = new Sessions.SessionInfo();
                        sessionItem.Id = sessionNum;
                        sessionItem.LapsTotal = parseIntValue(session, "SessionLaps");
                        sessionItem.SessionLength = parseFloatValue(session, "SessionTime", "sec");
                        sessionItem.Type = sessionTypeMap[parseStringValue(session, "SessionType")];

                        if (sessionItem.Type == iRTVO.Sessions.SessionInfo.sessionType.race)
                        {
                            sessionItem.FinishLine = parseIntValue(session, "SessionLaps") + 1;
                        }
                        else
                        {
                            sessionItem.FinishLine = Int32.MaxValue;
                        }

                        if (sessionItem.FinishLine < 0)
                        {
                            sessionItem.FinishLine = Int32.MaxValue;
                        }

                        sessionItem.Cautions = parseIntValue(session, "ResultsNumCautionFlags");
                        sessionItem.CautionLaps = parseIntValue(session, "ResultsNumCautionLaps");
                        sessionItem.LeadChanges = parseIntValue(session, "ResultsNumLeadChanges");
                        sessionItem.LapsComplete = parseIntValue(session, "ResultsLapsComplete");

                        length = session.Length;
                        start = session.IndexOf("   ResultsFastestLap:\n", 0, length);
                        end = length;
                        string ResultsFastestLap = session.Substring(start, end - start);

                        sessionItem.FastestLap = parseFloatValue(ResultsFastestLap, "FastestTime");
                        int index = SharedData.Drivers.FindIndex(d => d.CarIdx.Equals(parseIntValue(ResultsFastestLap, "CarIdx")));
                        if (index >= 0)
                        {
                            sessionItem.FastestLapDriver = SharedData.Drivers[index];
                            sessionItem.FastestLapNum = parseIntValue(ResultsFastestLap, "FastestLap");
                        }
                        SharedData.Sessions.SessionList.Add(sessionItem);
                        sessionIndex = SharedData.Sessions.SessionList.FindIndex(s => s.Id.Equals(sessionNum));
                    }
                    else // update only non fixed fields
                    {
                        SharedData.Sessions.SessionList[sessionIndex].LeadChanges = parseIntValue(session, "ResultsNumLeadChanges");
                        SharedData.Sessions.SessionList[sessionIndex].LapsComplete = parseIntValue(session, "ResultsLapsComplete");

                        length = session.Length;
                        start = session.IndexOf("   ResultsFastestLap:\n", 0, length) + "   ResultsFastestLap:\n".Length;
                        end = length;
                        string ResultsFastestLap = session.Substring(start, end - start);

                        SharedData.Sessions.SessionList[sessionIndex].FastestLap = parseFloatValue(ResultsFastestLap, "FastestTime");
                        int index = SharedData.Drivers.FindIndex(d => d.CarIdx.Equals(parseIntValue(ResultsFastestLap, "CarIdx")));
                        if (index >= 0)
                        {
                            SharedData.Sessions.SessionList[sessionIndex].FastestLapDriver = SharedData.Drivers[index];
                            SharedData.Sessions.SessionList[sessionIndex].FastestLapNum = parseIntValue(ResultsFastestLap, "FastestLap");
                        }
                    }

                    // Trigger Overlay Event, but only in current active session
                    if ( (SharedData.Sessions.SessionList[sessionIndex].FastestLap != SharedData.Sessions.SessionList[sessionIndex].PreviousFastestLap)
                        && (_CurrentSession == SharedData.Sessions.SessionList[sessionIndex].Id )
                        )
                    {
                        // TODO ADD Logging!!
                        // remoteServer.debugLog(String.Format("Triggering fastedlap Old={0} new={1}",SharedData.Sessions.SessionList[sessionIndex].PreviousFastestLap,SharedData.Sessions.SessionList[sessionIndex].FastestLap));

                        // Push Event to Overlay
                        SharedData.triggers.Push(TriggerTypes.fastestlap);
                     }

                    length = session.Length;
                    start = session.IndexOf("   ResultsPositions:\n", 0, length);
                    end = session.IndexOf("   ResultsFastestLap:\n", start, length - start);

                    string Standings = session.Substring(start, end - start);
                    string[] standingList = Standings.Split(new string[] { "\n   - " }, StringSplitOptions.RemoveEmptyEntries);

                    Int32 position = 1;
                    List<iRTVO.DriverInfo> standingsDrivers = SharedData.Drivers.ToList();

                    foreach (string standing in standingList)
                    {
                        int carIdx = parseIntValue(standing, "CarIdx");
                        if (carIdx < Int32.MaxValue)
                        {
                            Sessions.SessionInfo.StandingsItem standingItem = new Sessions.SessionInfo.StandingsItem();
                            standingItem = SharedData.Sessions.SessionList[sessionIndex].FindDriver(carIdx);

                            standingsDrivers.Remove(standingsDrivers.Find(s => s.CarIdx.Equals(carIdx)));

                            if (parseFloatValue(standing, "LastTime") > 0)
                            {
                                if (parseFloatValue(standing, "LastTime") < SharedData.Sessions.SessionList[sessionIndex].FastestLap && SharedData.Sessions.SessionList[sessionIndex].FastestLap > 0)
                                {
                                    Event ev = new Event(
                                        Event.eventType.fastlap,
                                        (Int32)(((Double)sdk.GetData("SessionTime") * 60) + timeoffset),
                                        standingItem.Driver,
                                        "New session fastest lap (" + iRTVO.Overlay.floatTime2String(parseFloatValue(standing, "LastTime"), 3, false) + ")",
                                        SharedData.Sessions.SessionList[sessionIndex].Type,
                                        parseIntValue(standing, "LapsComplete")
                                    );
                                    SharedData.Events.List.Add(ev);
                                }
                            }

                            if (parseFloatValue(standing, "FastestTime") < SharedData.Sessions.SessionList[sessionIndex].FastestLap ||
                                SharedData.Sessions.SessionList[sessionIndex].FastestLap <= 0)
                            {
                                SharedData.Sessions.SessionList[sessionIndex].FastestLap = parseFloatValue(standing, "FastestTime");
                            }

                            /*
                            if (standingItem.Finished == false)
                            {
                                standingItem.PreviousLap.LapTime = parseFloatValue(standing, "LastTime");

                                if (standingItem.PreviousLap.LapTime <= 1)
                                {
                                    standingItem.PreviousLap.LapTime = standingItem.CurrentLap.LapTime;
                                }
                            }
                            */

                            if (SharedData.Sessions.SessionList[sessionIndex].Type == SharedData.Sessions.CurrentSession.Type)
                            {
                                if ((standingItem.CurrentTrackPct % 1.0) > 0.1)
                                {
                                    standingItem.PreviousLap.Position = parseIntValue(standing, "Position");
                                    standingItem.PreviousLap.Gap = parseFloatValue(standing, "Time");
                                    standingItem.PreviousLap.GapLaps = parseIntValue(standing, "Lap");
                                    standingItem.CurrentLap.Position = parseIntValue(standing, "Position");
                                }
                            }

                            if (standingItem.Driver.CarIdx < 0)
                            {
                                // insert item
                                int driverIndex = SharedData.Drivers.FindIndex(d => d.CarIdx.Equals(carIdx));
                                standingItem.setDriver(carIdx);
                                standingItem.FastestLap = parseFloatValue(standing, "FastestTime");
                                standingItem.LapsLed = parseIntValue(standing, "LapsLed");
                                standingItem.CurrentTrackPct = parseFloatValue(standing, "LapsDriven");
                                standingItem.Laps = new List<LapInfo>();

                                LapInfo newLap = new LapInfo();
                                newLap.LapNum = parseIntValue(standing, "LapsComplete");
                                newLap.LapTime = parseFloatValue(standing, "LastTime");
                                newLap.Position = parseIntValue(standing, "Position");
                                newLap.Gap = parseFloatValue(standing, "Time");
                                newLap.GapLaps = parseIntValue(standing, "Lap");
                                newLap.SectorTimes = new List<LapInfo.Sector>(3);
                                standingItem.Laps.Add(newLap);

                                standingItem.CurrentLap = new LapInfo();
                                standingItem.CurrentLap.LapNum = parseIntValue(standing, "LapsComplete") + 1;
                                standingItem.CurrentLap.Position = parseIntValue(standing, "Position");
                                standingItem.CurrentLap.Gap = parseFloatValue(standing, "Time");
                                standingItem.CurrentLap.GapLaps = parseIntValue(standing, "Lap");

                                SharedData.Sessions.SessionList[sessionIndex].Standings.Add(standingItem);
                                SharedData.Sessions.SessionList[sessionIndex].UpdatePosition();
                            }

                            int lapnum = parseIntValue(standing, "LapsComplete");
                            standingItem.FastestLap = parseFloatValue(standing, "FastestTime");
                            standingItem.LapsLed = parseIntValue(standing, "LapsLed");

                            if (SharedData.Sessions.SessionList[sessionIndex].Type == SharedData.Sessions.CurrentSession.Type)
                            {
                                standingItem.PreviousLap.LapTime = parseFloatValue(standing, "LastTime");
                            }

                            if (SharedData.Sessions.CurrentSession.State == iRTVO.Sessions.SessionInfo.sessionState.cooldown)
                            {
                                standingItem.CurrentLap.Gap = parseFloatValue(standing, "Time");
                                standingItem.CurrentLap.GapLaps = parseIntValue(standing, "Lap");
                                standingItem.CurrentLap.Position = parseIntValue(standing, "Position");
                                standingItem.CurrentLap.LapNum = parseIntValue(standing, "LapsComplete");
                            }

                            standingItem.Position = parseIntValue(standing, "Position");
                            standingItem.NotifySelf();
                            standingItem.NotifyLaps();

                            position++;
                        }
                    }

                    // update/add position for drivers not in results
                    foreach (DriverInfo driver in standingsDrivers)
                    {
                        Sessions.SessionInfo.StandingsItem standingItem = SharedData.Sessions.SessionList[sessionIndex].FindDriver(driver.CarIdx);
                        if (standingItem.Driver.CarIdx < 0)
                        {
                            if (SharedData.settings.IncludeMe || (!SharedData.settings.IncludeMe && standingItem.Driver.CarIdx != 63))
                            {
                                standingItem.setDriver(driver.CarIdx);
                                standingItem.Position = position;
                                standingItem.Laps = new List<LapInfo>();
                                SharedData.Sessions.SessionList[sessionIndex].Standings.Add(standingItem);
                                position++;
                            }
                        }
                        else if (!SharedData.settings.IncludeMe && driver.CarIdx < 63)
                        {
                            standingItem.Position = position;
                            position++;
                        }
                    }
                }
            }

            // add qualify session if it doesn't exist when race starts and fill it with YAML QualifyResultsInfo
            iRTVO.Sessions.SessionInfo qualifySession = SharedData.Sessions.findSessionType(iRTVO.Sessions.SessionInfo.sessionType.qualify);
            if (qualifySession.Type == iRTVO.Sessions.SessionInfo.sessionType.invalid)
            {
                qualifySession.Type = iRTVO.Sessions.SessionInfo.sessionType.qualify;

                length = yaml.Length;
                start = yaml.IndexOf("QualifyResultsInfo:\n", 0, length);

                // if found
                if (start >= 0)
                {
                    end = yaml.IndexOf("\n\n", start, length - start);

                    string QualifyResults = yaml.Substring(start, end - start);

                    length = QualifyResults.Length;
                    start = QualifyResults.IndexOf(" Results:\n", 0, length);
                    end = length;

                    string Results = QualifyResults.Substring(start, end - start - 1);
                    string[] resultList = Results.Split(new string[] { "\n - " }, StringSplitOptions.RemoveEmptyEntries);

                    qualifySession.FastestLap = float.MaxValue;

                    foreach (string result in resultList)
                    {
                        if (result != " Results:")
                        {
                            Sessions.SessionInfo.StandingsItem qualStandingsItem = qualifySession.FindDriver(parseIntValue(result, "CarIdx"));

                            if (qualStandingsItem.Driver.CarIdx > 0) // check if driver is in quali session
                            {
                                qualStandingsItem.Position = parseIntValue(result, "Position") + 1;
                            }
                            else // add driver to quali session
                            {
                                qualStandingsItem.setDriver(parseIntValue(result, "CarIdx"));
                                qualStandingsItem.Position = parseIntValue(result, "Position") + 1;
                                qualStandingsItem.FastestLap = parseFloatValue(result, "FastestTime");
                                qualifySession.Standings.Add(qualStandingsItem);

                                // update session fastest lap
                                if (qualStandingsItem.FastestLap < qualifySession.FastestLap && qualStandingsItem.FastestLap > 0)
                                    qualifySession.FastestLap = qualStandingsItem.FastestLap;
                            }
                        }
                    }
                    SharedData.Sessions.SessionList.Add(qualifySession); // add quali session
                }
            }

            // get qualify results if race session standings is empty
            foreach (Sessions.SessionInfo session in SharedData.Sessions.SessionList)
            {
                if (session.Type == iRTVO.Sessions.SessionInfo.sessionType.race && session.Standings.Count < 1)
                {
                    length = yaml.Length;
                    start = yaml.IndexOf("QualifyResultsInfo:\n", 0, length);

                    // if found
                    if (start >= 0)
                    {
                        end = yaml.IndexOf("\n\n", start, length - start);

                        string QualifyResults = yaml.Substring(start, end - start);

                        length = QualifyResults.Length;
                        start = QualifyResults.IndexOf(" Results:\n", 0, length);
                        end = length;

                        string Results = QualifyResults.Substring(start, end - start - 1);
                        string[] resultList = Results.Split(new string[] { "\n - " }, StringSplitOptions.RemoveEmptyEntries);

                        foreach (string result in resultList)
                        {
                            if (result != " Results:")
                            {
                                Sessions.SessionInfo.StandingsItem standingItem = new Sessions.SessionInfo.StandingsItem();
                                standingItem.setDriver(parseIntValue(result, "CarIdx"));
                                standingItem.Position = parseIntValue(result, "Position") + 1;
                                session.Standings.Add(standingItem);
                            }
                        }
                    }
                }
            }

            length = yaml.Length;
            start = yaml.IndexOf("CameraInfo:\n", 0, length);
            end = yaml.IndexOf("\n\n", start, length - start);

            string CameraInfo = yaml.Substring(start, end - start);

            length = CameraInfo.Length;
            start = CameraInfo.IndexOf(" Groups:\n", 0, length);
            end = length;

            string Cameras = CameraInfo.Substring(start, end - start - 1);
            string[] cameraList = Cameras.Split(new string[] { "\n - " }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string camera in cameraList)
            {
                int cameraNum = parseIntValue(camera, "GroupNum");
                if (cameraNum < Int32.MaxValue)
                {
                    CameraInfo.CameraGroup camgrp = SharedData.Camera.FindId(cameraNum);
                    if (camgrp.Id < 0)
                    {
                        CameraInfo.CameraGroup cameraGroupItem = new CameraInfo.CameraGroup();
                        cameraGroupItem.Id = cameraNum;
                        cameraGroupItem.Name = parseStringValue(camera, "GroupName");
                        SharedData.Camera.Groups.Add(cameraGroupItem);
                    }
                }
            }

            length = yaml.Length;
            start = yaml.IndexOf("SplitTimeInfo:\n", 0, length);
            end = yaml.IndexOf("\n\n", start, length - start);

            string SplitTimeInfo = yaml.Substring(start, end - start);

            length = SplitTimeInfo.Length;
            start = SplitTimeInfo.IndexOf(" Sectors:\n", 0, length);
            end = length;

            string Sectors = SplitTimeInfo.Substring(start, end - start - 1);
            string[] sectorList = Sectors.Split(new string[] { "\n - " }, StringSplitOptions.RemoveEmptyEntries);

            if (sectorList.Length != SharedData.Sectors.Count)
            {
                SharedData.Sectors.Clear();
                foreach (string sector in sectorList)
                {
                    int sectornum = parseIntValue(sector, "SectorNum");
                    if (sectornum < 100)
                    {
                        float sectorborder = parseFloatValue(sector, "SectorStartPct");
                        SharedData.Sectors.Add(sectorborder);
                    }
                }

                // automagic sector selection
                if (SharedData.SelectedSectors.Count == 0)
                {
                    SharedData.SelectedSectors.Clear();

                    // load sectors
                    IniFile sectorsIni = new IniFile(Directory.GetCurrentDirectory() + "\\sectors.ini");
                    string sectorValue = sectorsIni.IniReadValue("Sectors", SharedData.Track.id.ToString());
                    string[] selectedSectors = sectorValue.Split(';');
                    Array.Sort(selectedSectors);

                    SharedData.SelectedSectors.Clear();
                    if (sectorValue.Length > 0)
                    {
                        foreach (string sector in selectedSectors)
                        {
                            float number;
                            if (Single.TryParse(sector, out number))
                            {
                                SharedData.SelectedSectors.Add(number);
                            }
                        }
                    }
                    else
                    {
                        if (SharedData.Sectors.Count == 2)
                        {
                            foreach (float sector in SharedData.Sectors)
                                SharedData.SelectedSectors.Add(sector);
                        }
                        else
                        {
                            float prevsector = 0;
                            foreach (float sector in SharedData.Sectors)
                            {

                                if (sector == 0 && SharedData.SelectedSectors.Count == 0)
                                {
                                    SharedData.SelectedSectors.Add(sector);
                                }
                                else if (sector >= 0.333 && SharedData.SelectedSectors.Count == 1)
                                {
                                    if (sector - 0.333 < Math.Abs(prevsector - 0.333))
                                    {
                                        SharedData.SelectedSectors.Add(sector);
                                    }
                                    else
                                    {
                                        SharedData.SelectedSectors.Add(prevsector);
                                    }
                                }
                                else if (sector >= 0.666 && SharedData.SelectedSectors.Count == 2)
                                {
                                    if (sector - 0.666 < Math.Abs(prevsector - 0.666))
                                    {
                                        SharedData.SelectedSectors.Add(sector);
                                    }
                                    else
                                    {
                                        SharedData.SelectedSectors.Add(prevsector);
                                    }
                                }

                                prevsector = sector;
                            }
                        }
                    }
                }
            }
        }