Exemple #1
0
    public override bool loadFromConfig()
    {
        string OldConfigPath = Path.Combine(DeviceInfo.PersistRootPath, "VerRes.bytes");

        localSource = ReadSourceFile(OldConfigPath);
        if (localSource != null)
        {
            foreach (SouceData data in localSource.Files)
            {
                LocalSouceData.Add(data.FileName, data);
            }
        }
        string NewConfigPath = Path.Combine(DeviceInfo.PersistRootPath, "Config/VerRes.bytes");

        newSource = ReadSourceFile(NewConfigPath);
        if (newSource != null && newSource.Files != null)
        {
            foreach (SouceData data in newSource.Files)
            {
                NewSouceData.Add(data.FileName, data);
            }
        }

        return(true);
    }
Exemple #2
0
    //读取资源表(与其他表格式不一样,单独处理)
    public GameSourceData ReadSourceFile(string path)
    {
        string         encrpytStr = null;
        GameSourceData data       = null;

        if (File.Exists(path))
        {
            try
            {
                // Create an instance of StreamReader to read from a file.
                // The using statement also closes the StreamReader.
                using (StreamReader sr = new StreamReader(path))
                {
                    // Read and display lines from the file until the end of the file is reached.
                    encrpytStr = sr.ReadToEnd();
                    data       = JSON.Instance.ToObject(encrpytStr, typeof(GameSourceData)) as GameSourceData;
                    sr.Close();
                }
            }
            catch (Exception e)
            {
                // Let the user know what went wrong.
                ConsoleEx.DebugLog(e.Message);
            }
        }
        return(data);
    }
Exemple #3
0
    //保存到本地磁盘
    //全部覆盖
    public void SaveToLocaldisk()
    {
        if (localSource == null)
        {
            localSource = new GameSourceData();
        }
        localSource.Game     = newSource.Game;
        localSource.Platform = newSource.Platform;
        localSource.Version  = newSource.Version;

        int count = LocalSouceData.Values.Count;

        localSource.Files = new SouceData[count];

        int i = 0;

        foreach (SouceData sd in LocalSouceData.Values)
        {
            localSource.Files[i++] = sd;
        }

        string jsonStr         = JSON.Instance.ToJSON(localSource);
        string localConfigPath = Path.Combine(DeviceInfo.PersistRootPath, "VerRes.bytes");

        try
        {
            using (StreamWriter sr = new StreamWriter(localConfigPath))
            {
                sr.Write(jsonStr);
                sr.Close();
            }
        } catch (Exception e) {
            ConsoleEx.DebugLog(e.Message);
        }
    }