public static List <int> ReadInFromFile()
        {
            string TempString;
            string VirtAddWidthString    = "Null";
            string TLBEntriesString      = "Null";
            string TLBOrganizationString = "Null";
            string PageSizeString        = "Null";
            string PhysAddWidthString    = "Null";
            string L1BlocksString        = "Null";
            string L1BlockSizeString     = "Null";
            string L1OrgString           = "Null";

            int VirtAddWidth    = -1;
            int TLBEntries      = -1;
            int TLBOrganization = -1;
            int PageSize        = -1;
            int PhysAddWidth    = -1;
            int L1Blocks        = -1;
            int L1BlockSize     = -1;
            int L1Org           = -1;

            List <int> ValuesFromFileList = new List <int>();

            try
            {
                StreamReader sr = new StreamReader("info.txt");
                TempString         = sr.ReadLine();
                VirtAddWidthString = TempString.Substring(22);
                VirtAddWidth       = int.Parse(VirtAddWidthString);

                TempString       = sr.ReadLine();
                TLBEntriesString = TempString.Substring(12);
                TLBEntries       = int.Parse(TLBEntriesString);

                TempString            = sr.ReadLine();
                TLBOrganizationString = TempString.Substring(17);
                if (TLBOrganizationString.Contains("8"))
                {
                    TLBOrganization = 8;
                }
                else if (TLBOrganizationString.Contains("2"))
                {
                    TLBOrganization = 2;
                }
                else if (TLBOrganizationString.Contains("4"))
                {
                    TLBOrganization = 4;
                }
                else if (TLBOrganizationString.Contains("16"))
                {
                    TLBOrganization = 16;
                }

                TempString     = sr.ReadLine();
                PageSizeString = TempString.Substring(10);
                PageSize       = int.Parse(PageSizeString);

                TempString         = sr.ReadLine();
                PhysAddWidthString = TempString.Substring(23);
                PhysAddWidth       = int.Parse(PhysAddWidthString);

                TempString     = sr.ReadLine();
                L1BlocksString = TempString.Substring(10);
                L1Blocks       = int.Parse(L1BlocksString);

                TempString        = sr.ReadLine();
                L1BlockSizeString = TempString.Substring(14);
                L1BlockSize       = int.Parse(L1BlockSizeString);

                TempString  = sr.ReadLine();
                L1OrgString = TempString.Substring(16);
                if (L1OrgString.Contains("2"))
                {
                    L1Org = 2;
                }
                else if (L1OrgString.Contains("4"))
                {
                    L1Org = 4;
                }
                else if (L1OrgString.Contains("8"))
                {
                    L1Org = 8;
                }
                else if (L1OrgString.Contains("16"))
                {
                    L1Org = 16;
                }

                ValuesFromFileList.Add(VirtAddWidth);
                ValuesFromFileList.Add(TLBEntries);
                ValuesFromFileList.Add(TLBOrganization);
                ValuesFromFileList.Add(PageSize);
                ValuesFromFileList.Add(PhysAddWidth);
                ValuesFromFileList.Add(L1Blocks);
                ValuesFromFileList.Add(L1BlockSize);
                ValuesFromFileList.Add(L1Org);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(ValuesFromFileList);
        }
Пример #2
0
        /// <summary>
        /// Parses a Byte Array at a specific location, and builds a Packet.
        /// </summary>
        /// <param name="buffer">The Array of Bytes</param>
        /// <param name="indx">The Start Index</param>
        /// <param name="count">The number of Bytes to process</param>
        /// <returns></returns>
        static public HTTPMessage ParseByteArray(byte[] buffer, int indx, int count)
        {
            HTTPMessage  TheMessage = new HTTPMessage();
            UTF8Encoding UTF8       = new UTF8Encoding();
            String       TempData   = UTF8.GetString(buffer, indx, count);
            DText        parser     = new DText();
            String       TempString;

            int idx = TempData.IndexOf("\r\n\r\n");

            if (idx < 0)
            {
                return(null);
            }
            TempData = TempData.Substring(0, idx);

            parser.ATTRMARK = "\r\n";
            parser.MULTMARK = ":";
            parser[0]       = TempData;
            string CurrentLine = parser[1];

            DText HdrParser = new DText();

            HdrParser.ATTRMARK = " ";
            HdrParser.MULTMARK = "/";
            HdrParser[0]       = CurrentLine;

            if (CurrentLine.ToUpper().StartsWith("HTTP/") == true)
            {
                TheMessage.ResponseCode = int.Parse(HdrParser[2]);
                int s1 = CurrentLine.IndexOf(" ");
                s1 = CurrentLine.IndexOf(" ", s1 + 1);
                TheMessage.ResponseData = HTTPMessage.UnEscapeString(CurrentLine.Substring(s1));
                try
                {
                    TheMessage.Version = HdrParser[1, 2];
                }
                catch (Exception ex)
                {
                    OpenSource.Utilities.EventLogger.Log(ex);
                    TheMessage.Version = "0.9";
                }
            }
            else
            {
                TheMessage.Directive = HdrParser[1];
                TempString           = CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1);
                if (TempString.ToUpper().StartsWith("HTTP/") == false)
                {
                    TheMessage.Version      = "0.9";
                    TheMessage.DirectiveObj = HTTPMessage.UnEscapeString(TempString);
                }
                else
                {
                    TheMessage.Version = TempString.Substring(TempString.IndexOf("/") + 1);
                    int fs = CurrentLine.IndexOf(" ") + 1;
                    TheMessage.DirectiveObj = HTTPMessage.UnEscapeString(CurrentLine.Substring(
                                                                             fs,
                                                                             CurrentLine.Length - fs - TempString.Length - 1));
                }
            }
            String Tag     = "";
            String TagData = "";

            for (int line = 2; line <= parser.DCOUNT(); ++line)
            {
                if (Tag != "" && parser[line, 1].StartsWith(" "))
                {
                    TagData = parser[line, 1].Substring(1);
                }
                else
                {
                    Tag     = parser[line, 1];
                    TagData = "";
                    for (int i = 2; i <= parser.DCOUNT(line); ++i)
                    {
                        if (TagData == "")
                        {
                            TagData = parser[line, i];
                        }
                        else
                        {
                            TagData = TagData + parser.MULTMARK + parser[line, i];
                        }
                    }
                }
                TheMessage.AppendTag(Tag, TagData);
            }
            int cl = 0;

            if (TheMessage.HasTag("Content-Length"))
            {
                try
                {
                    cl = int.Parse(TheMessage.GetTag("Content-Length"));
                }
                catch (Exception ex)
                {
                    OpenSource.Utilities.EventLogger.Log(ex);
                    cl = -1;
                }
            }
            else
            {
                cl = -1;
            }

            byte[] tbuffer;
            if (cl > 0)
            {
                tbuffer = new byte[cl];
                if ((idx + 4 + cl) > count)
                {
                    // NOP
                }
                else
                {
                    Array.Copy(buffer, idx + 4, tbuffer, 0, cl);
                    TheMessage.DataBuffer = tbuffer;
                }
            }
            if (cl == -1)
            {
                tbuffer = new Byte[count - (idx + 4)];
                Array.Copy(buffer, idx + 4, tbuffer, 0, tbuffer.Length);
                TheMessage.DataBuffer = tbuffer;
            }
            if (cl == 0)
            {
                TheMessage.DataBuffer = new byte[0];
            }
            return(TheMessage);
        }
Пример #3
0
    public void ReadNode(string Key)
    {
        HideChoiceButtons();

        GameManager.GetComponent <StatManager> ().ClearDebugUI();

        Node myNode;

        if (Suivant)
        {
            Suivant = false;
            Key     = Suivant_Node;
        }

        LastNode.GetNext().TryGetValue(Key, out myNode);

        UI_Text_Main.GetComponent <TypewritingScript> ().TypeWrite(myNode.content);
        int local = 0;

        LastNode = myNode;


        string Local_StatName;
        string TempStringDeux;
        int    Local_StatChangeValue;

        string[] TempArray;

        foreach (string LocalTag in myNode.Tags)
        {
            if (LocalTag.Length > 0)
            {
                TempArray      = LocalTag.Split(":" [0]);
                Local_StatName = TempArray [0];

                if (TempArray [1].Contains("="))
                {
                    TempStringDeux = TempArray [1].Replace("=", "");
                }
                else
                {
                    TempStringDeux = TempArray [1];
                }
                //Debug.Log (TempStringDeux);
                Local_StatChangeValue = int.Parse(TempStringDeux);
                StatManager.ins.ModifyStatValue(Local_StatName, Local_StatChangeValue);
            }
            else
            {
                GameManager.GetComponent <StatManager> ().ChangePersoName(0);
                //Debug.Log ("Empty Tags");
            }
        }
        foreach (Node n in myNode.GetNext().Values)
        {
            autoCondition = true;
            string CleanText;
            CleanText = n.choiceText;
            int tempBool = 0;
            if (n.choiceText.Contains("{"))
            {
                autoCondition = false;

                string output;
                output = n.choiceText.Split(new char[] { '{', '}' }) [1];

                string[]    conditions;
                string[]    TempArrayConditions_1;
                string[]    tempCleanText;
                List <bool> ListOfBool = new List <bool> ();
                conditions    = output.Split(";" [0]);
                tempCleanText = n.choiceText.Split("{" [0]);
                CleanText     = tempCleanText [0];

                foreach (string condition in conditions)
                {
                    string varName;
                    string TempString;
                    string signe;
                    string valueString;
                    int    value;
                    TempArrayConditions_1 = condition.Split(":" [0]);
                    varName     = TempArrayConditions_1 [0];
                    TempString  = TempArrayConditions_1 [1];
                    signe       = TempString.Substring(0, 1);
                    valueString = TempString.Substring(1, TempString.Length - 1);
                    value       = int.Parse(valueString);

                    ListOfBool.Add(GameManager.GetComponent <StatManager> ().CompareValue(varName, signe, value));
                    //Debug.Log ("Nom var: " + varName + " Signe: " + signe + " Valeur: " + value);
                }

                foreach (bool l in ListOfBool)
                {
                    if (l == false)
                    {
                        tempBool++;
                        //Debug.Log ("Something is false");
                    }
                }
            }
            if (tempBool != 0)
            {
                autoCondition = false;
            }
            else
            {
                autoCondition = true;
            }

            if (CleanText.Contains("("))
            {
                string[] TempArrayCleaner;
                TempArrayCleaner = CleanText.Split("(" [0]);
                CleanText        = TempArrayCleaner [0];
            }

            if (local == 4 && autoCondition)
            {
                UI_Text_Button5.transform.parent.gameObject.SetActive(true);
                UI_Text_Button5.GetComponent <TextRead> ().ShowText_External(CleanText);
                UI_Button5.GetComponent <ButtonTrigger> ().SetNextChoice(n.choiceText);
                //Debug.Log ("Max Choices Reached");
            }
            if (local == 3 && autoCondition)
            {
                UI_Text_Button4.transform.parent.gameObject.SetActive(true);
                UI_Text_Button4.GetComponent <TextRead> ().ShowText_External(CleanText);
                UI_Button4.GetComponent <ButtonTrigger> ().SetNextChoice(n.choiceText);
                local = 4;
            }
            if (local == 2 && autoCondition)
            {
                UI_Text_Button3.transform.parent.gameObject.SetActive(true);
                UI_Text_Button3.GetComponent <TextRead> ().ShowText_External(CleanText);
                UI_Button3.GetComponent <ButtonTrigger> ().SetNextChoice(n.choiceText);
                local = 3;
            }
            if (local == 1 && autoCondition)
            {
                UI_Text_Button2.transform.parent.gameObject.SetActive(true);
                UI_Text_Button2.GetComponent <TextRead> ().ShowText_External(CleanText);
                UI_Button2.GetComponent <ButtonTrigger> ().SetNextChoice(n.choiceText);
                local = 2;
            }

            if (local == 0 && autoCondition)
            {
                if (n.choiceText.Contains("Suivant") || n.choiceText.Contains("suivant"))
                {
                    Suivant      = true;
                    Suivant_Node = n.choiceText;
                    UI_Text_Button1.GetComponent <TextRead> ().ShowText_External("Suivant");
                }
                else
                {
                    UI_Text_Button1.GetComponent <TextRead> ().ShowText_External(CleanText);
                }
                UI_Text_Button1.transform.parent.gameObject.SetActive(true);
                UI_Button1.GetComponent <ButtonTrigger> ().SetNextChoice(n.choiceText);

                local = 1;
            }
        }
    }