コード例 #1
0
ファイル: ModuleData.cs プロジェクト: ItzAtomikHD/old
    public static bool LoadDataFromFile()
    {
        ModuleInformation[] modInfo;
        string path = Path.Combine(Application.persistentDataPath, usersSavePath);

        try
        {
            DebugHelper.Log($"ModuleData: Loading Module information data from file: {path}");
            modInfo = SettingsConverter.Deserialize <ModuleInformation[]>(File.ReadAllText(path));           //JsonConvert.DeserializeObject<ModuleInformation[]>(File.ReadAllText(path));
        }
        catch (FileNotFoundException)
        {
            DebugHelper.LogWarning($"ModuleData: File {path} was not found.");
            return(false);
        }
        catch (Exception ex)
        {
            DebugHelper.LogException(ex);
            return(false);
        }

        foreach (ModuleInformation info in modInfo)
        {
            ComponentSolverFactory.AddModuleInformation(info);
        }
        return(true);
    }
コード例 #2
0
	public static bool LoadDataFromFile()
	{
		FileModuleInformation[] modInfo;
		string path = Path.Combine(Application.persistentDataPath, usersSavePath);
		try
		{
			DebugHelper.Log($"Loading Module information data from file: {path}");
			modInfo = SettingsConverter.Deserialize<FileModuleInformation[]>(File.ReadAllText(path));
			lastRead = modInfo;
		}
		catch (FileNotFoundException)
		{
			DebugHelper.LogWarning($"File {path} was not found.");
			return false;
		}
		catch (Exception ex)
		{
			DebugHelper.LogException(ex);
			return false;
		}

		foreach (var fileInfo in modInfo)
		{
			ModuleInformation defaultInfo = null;
			if (fileInfo.moduleID != null)
			{
				defaultInfo = ComponentSolverFactory.GetDefaultInformation(fileInfo.moduleID);
			}

			var info = new ModuleInformation();
			foreach (FieldInfo fileFieldInfo in fileInfoFields)
			{
				if (fileFieldInfo.DeclaringType == typeof(ModuleInformation)) {
					if (fileInfoFields.Any(field => field.DeclaringType == typeof(FileModuleInformation) && field.Name == fileFieldInfo.Name))
						continue;

					fileFieldInfo.SetValue(info, fileFieldInfo.GetValue(fileInfo));
				}
				else
				{
					var baseFieldInfo = Array.Find(infoFields, field => field.Name == fileFieldInfo.Name);
					if (baseFieldInfo == null)
						throw new NotSupportedException("Superclass isn't overriding only base fields.");

					var value = fileFieldInfo.GetValue(fileInfo);
					if (value == null && defaultInfo != null)
					{
						value = baseFieldInfo.GetValue(defaultInfo);
					}

					baseFieldInfo.SetValue(info, value);
				}
			}

			ComponentSolverFactory.AddModuleInformation(info);
		}
		return true;
	}