Пример #1
0
 /// <summary> Add an entry to the profile if it is not loaded. </summary>
 /// <param name="userName"></param>
 /// <param name="profile"></param>
 public static void AddEntry(string userName, HandProfile profile)
 {
     //if (DBLoaded)
     {
         if (!IsLoaded(userName))
         {
             UserProfiles.profiles.Add(userName, profile);
         }
         else //update the key-value pair
         {
             profiles[userName] = profile;
         }
     }
 }
Пример #2
0
        /// <summary> Load the Database, if not already done. </summary>
        /// <param name="directory"></param>
        public static void LoadDB(string directory)
        {
            if (!DBLoaded)
            {
                string[] lines;
                if (Util.FileIO.ReadTxtFile(directory + databaseName, out lines))
                {
                    DBLoaded = true;

                    List <string> block = new List <string>();

                    int line = 1; //skip the @lastProfiles

                    //fill the block with all of the "LastProfiles"
                    while (line <= lines.Length && !(lines[line].Length > 0 && lines[line][0] == '@'))
                    {
                        if (line < lines.Length)
                        {
                            block.Add(lines[line]);
                            line++;
                        }
                    }

                    //process lastProfiles
                    for (int i = 0; i < block.Count; i++)
                    {
                        string[] split = block[i].Split('\t');
                        if (split.Length > 1)
                        {
                            lastProfiles.Add(split[0], split[1]);
                        }
                    }

                    block.Clear();
                    line++;
                    string lastEntry = "";
                    while (line <= lines.Length)
                    {
                        if (line >= lines.Length || (lines[line].Length > 0 && lines[line][0] == '#')) //its a new Material
                        {
                            if (block.Count > 0 && lastEntry.Length > 0)                               //parse & add previous Material if it has a good name
                            {
                                //UserProfiles.AddEntry(lastEntry, HandProfile.Parse(block));
                                profiles.Add(lastEntry, HandProfile.Parse(block));
                            }
                            block.Clear();

                            if (line < lines.Length)
                            {
                                try                                                                                                      //extract name of new material
                                {
                                    lastEntry = lines[line].Split(new char[] { '\t' }, System.StringSplitOptions.RemoveEmptyEntries)[1]; //condition name
                                }
                                catch (System.Exception Ex)
                                {
                                    SenseGlove_Debugger.LogWarning(Ex.Message);
                                    lastEntry = "";
                                }
                            }
                        }
                        if (line < lines.Length)
                        {
                            block.Add(lines[line]);
                        }
                        line++;
                    }

                    DBLoaded = true;
                    //SenseGlove_Debugger.Log("Loaded Database!");
                }
                else
                {
                    //could not load this data base asset
                }
            }
        }