Beispiel #1
0
 public void Init(string filename)
 {
     if (!FileReaderProxy.Exists(filename))
     {
         return;
     }
     try
     {
         float w = 1, h = 1;
         using (MemoryStream fs = FileReaderProxy.ReadFileAsMemoryStream(filename))
         {
             using (BinaryReader br = new BinaryReader(fs))
             {
                 w = (float)br.ReadDouble();
                 h = (float)br.ReadDouble();
                 br.Close();
             }
         }
         Init(w, h);
     }
     catch (Exception e)
     {
         LogSystem.Error("{0}\n{1}", e.Message, e.StackTrace);
     }
 }
Beispiel #2
0
        /**
         * @brief 载入文件
         *
         * @param path
         *
         * @return
         */
        public bool Load(string path)
        {
            bool ret = false;

            if (path == "" || !FileReaderProxy.Exists(path))
            {
                return(ret);
            }

            Stream       ms = null;
            StreamReader sr = null;

            try
            {
                ms = FileReaderProxy.ReadFileAsMemoryStream(path);
                if (ms == null)
                {
                    LogSystem.Debug("DBC, Warning, Load file error or file is empty: {0}", path);
                    return(false);
                }

                m_FileName = path;
                ms.Seek(0, SeekOrigin.Begin);
                m_FileSize = ms.Length;
                if (m_FileSize <= 0 || m_FileSize >= int.MaxValue)
                {
                    return(ret);
                }

                System.Text.Encoding encoding = System.Text.Encoding.UTF8;
                sr = new StreamReader(ms, encoding);

                ret = LoadFromStream(sr);
                ret = true;
            }
            catch (Exception e)
            {
                string err = "Exception:" + e.Message + "\n" + e.StackTrace + "\n";
                System.Diagnostics.Debug.WriteLine(err);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
                if (ms != null)
                {
                    ms.Close();
                }
            }

            return(ret);
        }