Exemplo n.º 1
0
Arquivo: Csvex.cs Projeto: mengtest/fs
    public bool Load(byte[] uData, Encoding coding)
    {
        LusuoStream lf   = new LusuoStream(uData);
        bool        bRef = Load(lf, coding);

        lf.Close();
        return(bRef);
    }
Exemplo n.º 2
0
    private static bool ProcessCsvBytes()
    {
        // 用于检测CSV是否写人LogicSystem
        CsvManager.Inst = new CsvManager();
        LogicSystem logicSystem = new LogicSystem();

        logicSystem.InitCsv(ref CsvManager.Inst);

        // 将所有的csv文件写入到m_csvStream
        m_csvNums   = 0;
        m_csvStream = new LusuoStream(new FileStream(m_csvBytesPath, FileMode.Create));
        m_csvStream.WriteUInt(0); // 预留文件个数
        bool bSucc = ProcessCsvFile(new DirectoryInfo(m_csvPath));

        m_csvStream.Seek(0);
        m_csvStream.WriteUInt(m_csvNums);
        Debug.Log("成功写入csv个数:" + m_csvNums);
        m_csvStream.Close();

        return(bSucc);
    }
Exemplo n.º 3
0
Arquivo: Csvex.cs Projeto: mengtest/fs
    public bool Load(string strPath, Encoding encoding)
    {
        if (string.IsNullOrEmpty(strPath))
        {
            return(false);
        }

        LusuoStream lf = null;

        try
        {
            lf = new LusuoStream(new FileStream(strPath, FileMode.Open));
        }
        catch (System.Exception)
        {
            return(false);
        }
        bool bRef = Load(lf, encoding);

        lf.Close();
        return(bRef);
    }
Exemplo n.º 4
0
Arquivo: Csvex.cs Projeto: mengtest/fs
    public void Save(string strPath, Encoding encoding, bool bNewCreate)
    {
        if (string.IsNullOrEmpty(strPath))
        {
            return;
        }
        LusuoStream lf = null;

        try
        {
            if (bNewCreate)
            {
                if (File.Exists(strPath))
                {
                    File.Delete(strPath);
                }

                string strFullPath = Path.GetDirectoryName(strPath);

                if (!Directory.Exists(strFullPath))
                {
                    Directory.CreateDirectory(strFullPath);
                }
            }

            lf = new LusuoStream(new FileStream(strPath, bNewCreate ? FileMode.CreateNew : FileMode.Truncate, FileAccess.Write));
        }
        catch (System.Exception ex)
        {
            //Debug.LogError("Cann't Open csv  errinfo=" + ex.Message);
            return;
        }
        Save(lf, encoding);

        lf.Close();
    }
Exemplo n.º 5
0
    private static void ProcessResBytes()
    {
        m_resInfoCsv     = new AllResInfoCsv();
        m_mapNameResInfo = new Dictionary <string, ResInfo>(); // 下面批处理文件时,处理一个加一个,会审核是否有重复资源
        m_lstResinfo     = new List <ResInfo>();               // 保持时使用的数据
        m_setUseList     = new HashSet <int>();                // 存资源id
        m_curResID       = 0;

        bool b = m_resInfoCsv.Load(m_resCsvPath, Encoding.Default);

        if (!b)
        {
            Debug.LogError("注意: 资源总表,打开csv失败。");
            return;
        }

        foreach (ResInfo key in m_resInfoCsv.m_lstResinfo)
        {
            m_setUseList.Add(key.nResID);
        }

        string strFull = Path.GetDirectoryName(m_resPath);

        Directory.CreateDirectory(strFull);

        // 然后处理该文件夹中所有的文件
        ProcessResFile(new DirectoryInfo(m_resPath));

        // 然后遍历原始资源表列表,将无资源的预留id也写入到资源列表
        foreach (ResInfo oldItem in m_resInfoCsv.m_lstResinfo)
        {
            bool bHave = false;
            foreach (ResInfo newItem in m_lstResinfo)
            {
                if (oldItem.nResID == newItem.nResID)
                {
                    bHave = true;
                }
            }
            // 如果新的不包含,就加到新的
            if (!bHave)
            {
                oldItem.iType  = ResType.None;
                oldItem.strUrl = "";
                if (m_mapNameResInfo.ContainsKey(oldItem.strName))
                {
                    Debug.LogError("总资源表含有重复的资源:" + oldItem.strName);
                    continue;
                }
                m_mapNameResInfo.Add(oldItem.strName, oldItem);
                m_lstResinfo.Add(oldItem);
            }
        }

        m_resInfoCsv.Clear();
        m_resInfoCsv.m_mapNameResInfo = m_mapNameResInfo;
        m_resInfoCsv.m_lstResinfo     = m_lstResinfo;

        // 保存资源总配置文件
        m_resInfoCsv.Save("", Encoding.Default, true);

        // 生成二进制文件
        FileStream stream =
            new FileStream(m_resBytesPath, FileMode.Create);
        LusuoStream ls    = new LusuoStream(stream);
        int         iNums = m_lstResinfo.Count;

        ls.WriteInt(iNums);                     // 将真的资源个数写入到流的开始位置
        Debug.Log("成功写入资源个数:" + iNums);
        foreach (KeyValuePair <string, ResInfo> item in m_mapNameResInfo)
        {
            item.Value.Save(ref ls);
        }
        ls.Close();
    }