123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using System;
- using System.IO;
- using System.Runtime.Serialization;
- using System.Runtime.Serialization.Formatters.Soap;
- namespace Microsoft.Samples.AppUpdater
- {
- [Serializable]
- public class AppManifest
- {
- [NonSerialized]
- private string _FilePath;
- private ResourceFiles _Resources;
- private AppVersionInfo _VersionInfo;
- private UpdateState _State;
- public string FilePath
- {
- get
- {
- return _FilePath;
- }
- set
- {
- _FilePath = value;
- }
- }
- public ResourceFiles Resources
- {
- get
- {
- return _Resources;
- }
- set
- {
- _Resources = value;
- }
- }
- public AppVersionInfo VersionInfo
- {
- get
- {
- return _VersionInfo;
- }
- set
- {
- _VersionInfo = value;
- }
- }
- public UpdateState State
- {
- get
- {
- return _State;
- }
- set
- {
- _State = value;
- }
- }
- public AppManifest(string manifestFilePath)
- {
- FilePath = manifestFilePath;
- Resources = new ResourceFiles();
- State = new UpdateState();
- VersionInfo = new AppVersionInfo();
- }
- public static AppManifest Load(string manifestFilePath)
- {
- Stream stream = null;
- try
- {
- if (!File.Exists(manifestFilePath))
- {
- return new AppManifest(manifestFilePath);
- }
- IFormatter formatter = new SoapFormatter();
- stream = new FileStream(manifestFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
- AppManifest appManifest = (AppManifest)formatter.Deserialize(stream);
- appManifest.FilePath = manifestFilePath;
- stream.Close();
- return appManifest;
- }
- catch (Exception)
- {
- stream?.Close();
- return new AppManifest(manifestFilePath);
- }
- }
- public void Update()
- {
- Stream stream = null;
- try
- {
- IFormatter formatter = new SoapFormatter();
- stream = new FileStream(FilePath, FileMode.Create, FileAccess.Write, FileShare.None);
- formatter.Serialize(stream, this);
- stream.Close();
- }
- catch (Exception ex)
- {
- stream?.Close();
- throw ex;
- }
- }
- }
- }
|