public string GetUserData(string token)
        {
            TokenList = GetCookies();
            SSOToken tokenModel = TokenList.FirstOrDefault(p => p.Token == token && p.OverdueTime > DateTime.Now);

            if (tokenModel != null)
            {
                return(tokenModel.UserData);
            }
            TokenList.RemoveAll(p => p.OverdueTime < DateTime.Now);
            return("");
        }
        public string SetToken(string userData, TimeSpan saveInterval)
        {
            TokenList = GetCookies();
            SSOToken tokenModel = TokenList.FirstOrDefault(p => p.UserData == userData && p.OverdueTime > DateTime.Now);

            if (tokenModel != null)
            {
                tokenModel.OverdueTime = DateTime.Now.Add(saveInterval);
                SetCookies();
                return(tokenModel.Token);
            }
            SSOToken ssoModel = new SSOToken
            {
                Token       = CreateToken(),
                UserData    = userData,
                OverdueTime = DateTime.Now.Add(saveInterval)
            };

            TokenList.Add(ssoModel);
            SetCookies();
            return(ssoModel.Token);
        }
Beispiel #3
0
        private void hb1_SelectionChanged(object sender, EventArgs e)
        {
            if (!TokenChanging)
            {
                HexBoxSelectionChanging = true;
                int start = (int)ScriptEditor_Hexbox.SelectionStart;
                int len   = (int)ScriptEditor_Hexbox.SelectionLength;
                int size  = (int)ScriptEditor_Hexbox.ByteProvider.Length;
                //TODO: Optimize this so this is only called when data has changed
                byte[] currentData = (ScriptEditor_Hexbox.ByteProvider as DynamicByteProvider).Bytes.ToArray();
                try
                {
                    if (currentData != null && start != -1 && start < size)
                    {
                        string s = $"Byte: {currentData[start]}"; //if selection is same as size this will crash.
                        if (start <= currentData.Length - 4)
                        {
                            int val = BitConverter.ToInt32(currentData, start);
                            s += $", Int: {val}";
                            s += $", Float: {BitConverter.ToSingle(currentData, start)}";
                            if (CurrentLoadedExport.FileRef.isName(val))
                            {
                                s += $", Name: {CurrentLoadedExport.FileRef.getNameEntry(val)}";
                            }
                            if (CurrentLoadedExport.FileRef.Game == MEGame.ME1)
                            {
                                ME1OpCodes m = (ME1OpCodes)currentData[start];
                                s += $", OpCode: {m}";
                            }

                            if (CurrentLoadedExport.FileRef.getEntry(val) is IEntry ent)
                            {
                                string type = ent is IExportEntry ? "Export" : "Import";
                                if (ent.ObjectName == CurrentLoadedExport.ObjectName)
                                {
                                    s += $", {type}: {ent.GetFullPath}";
                                }
                                else
                                {
                                    s += $", {type}: {ent.ObjectName}";
                                }
                            }
                        }
                        s += $" | Start=0x{start.ToString("X8")} ";
                        if (len > 0)
                        {
                            s += $"Length=0x{len.ToString("X8")} ";
                            s += $"End=0x{(start + len - 1).ToString("X8")}";
                        }
                        StatusBar_LeftMostText.Text = s;
                    }
                    else
                    {
                        StatusBar_LeftMostText.Text = "Nothing Selected";
                    }
                }
                catch (Exception)
                {
                }

                //Find which decompiled script block the cursor belongs to
                ListBox        selectedBox      = null;
                List <ListBox> allBoxesToUpdate = new List <ListBox>(new ListBox[] { Function_ListBox, Function_Header, Function_Footer });
                if (start >= 0x20 && start < CurrentLoadedExport.DataSize - 6)
                {
                    Token token = null;
                    foreach (object o in DecompiledScriptBlocks)
                    {
                        if (o is Token x && start >= x.pos && start < (x.pos + x.raw.Length))
                        {
                            token = x;
                            break;
                        }
                    }
                    if (token != null)
                    {
                        Function_ListBox.SelectedItem = token;
                        Function_ListBox.ScrollIntoView(token);
                    }

                    BytecodeSingularToken bst = TokenList.FirstOrDefault(x => x.StartPos == start);
                    if (bst != null)
                    {
                        Tokens_ListBox.SelectedItem = bst;
                        Tokens_ListBox.ScrollIntoView(bst);
                    }
                    selectedBox = Function_ListBox;
                }
                if (start >= 0x0C && start < 0x20)
                {
                    //header
                    int index = (start - 0xC) / 4;
                    Function_Header.SelectedIndex = index;
                    selectedBox = Function_Header;
                }
                if (start > CurrentLoadedExport.DataSize - 6)
                {
                    //footer
                    //yeah yeah I know this is very specific code.
                    if (start == CurrentLoadedExport.DataSize - 6 || start == CurrentLoadedExport.DataSize - 5)
                    {
                        Function_Footer.SelectedIndex = 0;
                    }
                    else
                    {
                        Function_Footer.SelectedIndex = 1;
                    }
                    selectedBox = Function_Footer;
                }

                //deselect the other boxes
                if (selectedBox != null)
                {
                    allBoxesToUpdate.Remove(selectedBox);
                }
                allBoxesToUpdate.ForEach(x => x.SelectedIndex = -1);
                HexBoxSelectionChanging = false;
            }
        }