コード例 #1
0
        /// <summary>
        /// Function takes path to ini file and returns data object
        /// </summary>
        /// <param name="path">path to ini file</param>
        /// <returns>Returns null on error</returns>
        public static IniData ReadFromIni(string path)
        {
            string[] lines;

            // Read the whole file
            try
            {
                lines = System.IO.File.ReadAllLines(path);
            }
            catch (System.Exception ex)
            {
                ValkyrieDebug.Log(ex.Message);
                return(null);
            }
            // Parse text data
            return(ReadFromStringArray(lines, path));
        }
コード例 #2
0
ファイル: Android.cs プロジェクト: kiloforce/valkyrie
 public static string GetStorage()
 {
     try
     {
         AndroidJavaClass jc   = new AndroidJavaClass("android.os.Environment");
         string           path = jc.CallStatic <AndroidJavaObject>("getExternalStorageDirectory").Call <string>("getAbsolutePath");
         if (path != null)
         {
             ValkyrieDebug.Log(path);
             return(path);
         }
     }
     catch (System.Exception e)
     {
         ValkyrieDebug.Log(e.ToString());
     }
     return("");
 }
コード例 #3
0
ファイル: Android.cs プロジェクト: zcaalock/valkyrie
 public static string GetStorage()
 {
     try
     {
         // we import in a thread, we have to attach JNI, otherwise we would crash
         int ret               = AndroidJNI.AttachCurrentThread();
         AndroidJavaClass jc   = new AndroidJavaClass("android.os.Environment");
         string           path = jc.CallStatic <AndroidJavaObject>("getExternalStorageDirectory").Call <string>("getAbsolutePath");
         if (ret != 0)
         {
             AndroidJNI.DetachCurrentThread();
         }
         if (path != null)
         {
             return(path);
         }
     }
     catch (System.Exception e)
     {
         ValkyrieDebug.Log(e.ToString());
     }
     return("");
 }
コード例 #4
0
        /// <summary>
        /// Parse ini data into data structure
        /// </summary>
        /// <param name="lines">array of text lines</param>
        /// <param name="path">path from where lines came</param>
        /// <returns></returns>
        public static IniData ReadFromStringArray(string[] lines, string path)
        {
            // Create a dictionary for the first section
            Dictionary <string, string> entryData = new Dictionary <string, string>();
            // Name for the current section
            string entryName = "";
            // Create object to hold output
            IniData output = new IniData();

            // Section headers have these chars removed
            char[] charsToTrim = { '[', ']' };

            // Parse all lines
            foreach (string l in lines)
            {
                // ignore comments
                if (l.Length > 0 && l.Trim()[0] == '#')
                {
                    continue;
                }

                // Start of new section
                if (l.Length > 0 && l.Trim()[0] == '[')
                {
                    // If not first section, add the last section of data
                    if (entryName != "")
                    {
                        if (!output.Add(entryName, entryData))
                        {
                            ValkyrieDebug.Log("Warning: duplicate section \"" + entryName + "\" in " + path + " will be ignored.");
                        }
                    }
                    // create new data for new section
                    entryData = new Dictionary <string, string>();
                    // Get name of new section
                    entryName = l.Trim().Trim(charsToTrim);
                    // Blank section names not allowed, but not fatal
                    if (entryName.Equals(""))
                    {
                        ValkyrieDebug.Log("Warning: empty section in " + path + " will be ignored.");
                    }
                }
                // If the line is not a comment (starts with ;)
                else if (l.Length > 0 && l.Trim()[0] != ';')
                {
                    int equalsLocation = l.IndexOf('=');
                    // Add data as entry with no value
                    if (equalsLocation == -1)
                    {
                        if (entryData.ContainsKey(l.Trim()))
                        {
                            ValkyrieDebug.Log("Warning: duplicate \"" + l.Trim() + "\" data in section \"" + entryName + "\" in " + path + " will be ignored.");
                        }
                        else
                        {
                            entryData.Add(l.Trim(), "");
                        }
                    }
                    // If there is an = add data as key and value
                    else
                    {
                        string key = l.Substring(0, equalsLocation).Trim();
                        if (entryData.ContainsKey(key))
                        {
                            ValkyrieDebug.Log("Warning: duplicate \"" + key + "\" data in section \"" + entryName + "\" in " + path + " will be ignored.");
                        }
                        else
                        {
                            string value = l.Substring(equalsLocation + 1).Trim().Trim('\"');
                            //string translatedValue = LocalizationRead.FFGLookup(value);
                            entryData.Add(key, value);
                        }
                    }
                    // This won't go anywhere if we don't have a section
                    if (entryName.Equals(""))
                    {
                        ValkyrieDebug.Log("Warning: data " + l + " without section in " + path + " will be ignored.");
                    }
                }
            }

            // Add the last section
            if (entryName != "")
            {
                if (!output.Add(entryName, entryData))
                {
                    ValkyrieDebug.Log("Warning: duplicate section \"" + entryName + "\" in " + path + " will be ignored.");
                }
            }

            return(output);
        }