Exemplo n.º 1
0
        virtual protected void save_editor(string _strPath, string _strFilename)
        {
            StreamWriter sw;

            try
            {
                string strLocalFilename = Path.Combine(_strPath, _strFilename);
                string strTempFileName  = string.Format("{0}.csv.temp", strLocalFilename);
                EditDirectory.MakeDirectory(_strPath, Application.dataPath);
                sw = Textreader.Open(Application.dataPath, strTempFileName);
                //Debug.Log(test++);
                T           dummy     = new T();
                FieldInfo[] infoArray = dummy.GetType().GetFields();
                //Debug.Log(test++);
                bool   bIsFirst = true;
                string strHead  = "";
                foreach (FieldInfo info in infoArray)
                {
                    if (!WritableField(info))
                    {
                        continue;
                    }
                    if (bIsFirst == true)
                    {
                        bIsFirst = false;
                    }
                    else
                    {
                        strHead += ",";
                    }
                    strHead += info.Name;
                }

                Textreader.Write(sw, strHead);
                foreach (T data in list)
                {
                    bIsFirst = true;
                    string strData = "";
                    foreach (FieldInfo info in infoArray)
                    {
                        if (!WritableField(info))
                        {
                            continue;
                        }

                        if (bIsFirst == true)
                        {
                            bIsFirst = false;
                        }
                        else
                        {
                            strData += ",";
                        }
                        string temp = data.GetString(info.Name);
                        //Debug.Log(string.Format("info.Name{0} value={1}", info.Name, temp));
                        //temp = temp.Replace("\n", "\\n");

                        /*
                         * if (temp.Contains("\n"))
                         * {
                         *      //Debug.Log(temp);
                         * }
                         */

                        strData += temp;
                    }
                    strData = strData.Replace("\n", "\\n");
                    Textreader.Write(sw, strData);
                }
                Textreader.Close(sw);

                fileMove(
                    Application.dataPath,
                    string.Format("{0}", strTempFileName),
                    string.Format("{0}.csv", strLocalFilename));
            }
            catch (Exception ex)
            {
                Debug.LogError(_strFilename);
                Debug.LogError(ex);
                return;
            }
            return;
        }
Exemplo n.º 2
0
        /*
         * 特に指定が無い場合は自動書き込み
         * 独自実装をしたい場合は個別にoverrideしてください
         * */
        virtual protected void save(string _strFilename)
        {
            //Debug.LogWarning (string.Format( "kvs.save {0}" , list.Count));
            //int test = 0;
            //Debug.Log(test++);
            StreamWriter sw;

            try
            {
                string strTempFilename = string.Format("{0}.csv.tmp", _strFilename);
                EditDirectory.MakeDirectory(strTempFilename);
                sw = Textreader.Open(Application.persistentDataPath, strTempFilename);
                //Debug.Log(test++);
                T           dummy     = new T();
                FieldInfo[] infoArray = dummy.GetType().GetFields();
                //Debug.Log(test++);
                bool   bIsFirst = true;
                string strHead  = "";
                foreach (FieldInfo info in infoArray)
                {
                    if (!WritableField(info))
                    {
                        continue;
                    }
                    if (bIsFirst == true)
                    {
                        bIsFirst = false;
                    }
                    else
                    {
                        strHead += ",";
                    }
                    strHead += info.Name;
                }
                //Debug.Log(test++);

                Textreader.Write(sw, strHead);
                //Debug.Log(test++);
                foreach (T data in list)
                {
                    bIsFirst = true;
                    string strData = "";
                    foreach (FieldInfo info in infoArray)
                    {
                        //Debug.Log(test++);
                        if (!WritableField(info))
                        {
                            //Debug.Log(test++);
                            continue;
                        }

                        if (bIsFirst == true)
                        {
                            bIsFirst = false;
                            //Debug.Log(test++);
                        }
                        else
                        {
                            strData += ",";
                            //Debug.Log(test++);
                        }
                        //Debug.Log(info.Name);
                        //Debug.Log(data);
                        //Debug.Log(data.GetString(info.Name));
                        strData += data.GetString(info.Name);
                        //Debug.Log(strData);
                    }
                    //Debug.Log(strData);
                    Textreader.Write(sw, strData);
                }
                Textreader.Close(sw);

                fileMove(
                    Application.persistentDataPath,
                    string.Format("{0}.csv.tmp", _strFilename),
                    string.Format("{0}.csv", _strFilename));
            }
            catch (Exception ex)
            {
                Debug.LogError(_strFilename);
                Debug.LogError(ex);
                return;
            }
            return;
        }