Пример #1
0
        public static bool OpenPackage(AMTPackage Package, string FileName)
        {
            AMTPackage ClonedPackage;

            try
            {
                ClonedPackage = (AMTPackage)JsonConvert.DeserializeObject <AMTPackage>(File.ReadAllText(FileName)).Clone();
            }
            catch
            {
                return(false);
            }
            if (!ClonedPackage.Animation.Manifest.Version.Equals(AMTConfig.Version))
            {
                MessageBox.Show("AMT file version does not match!", "Error!",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            //Setting Variables
            Package.Animation    = ClonedPackage.Animation;
            Package.Resources    = ClonedPackage.Resources;
            Package.Name         = ClonedPackage.Name;
            Package.WorkingDir   = Path.GetDirectoryName(FileName);
            Package.PackageState = AMTUtil.State.READY;
            foreach (KeyValuePair <string, string> s in Package.Resources)
            {
                if (!File.Exists(AMTUtil.GetAbsPath(Package.WorkingDir, s + AMTConfig.ResourceExtension)))
                {
                    MessageBox.Show("Resource [" + s.Value + "] is not found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }
            return(true);
        }
Пример #2
0
        public static AMTResource GetResourceFromName(AMTPackage Package, string ResourceName)
        {
            string AbsResourceName = AMTUtil.GetAbsPath(Package.WorkingDir, ResourceName + AMTConfig.ResourceExtension);

            if (Package.Resources.Exists(delegate(KeyValuePair <string, string> match)
            {
                return(match.Value == ResourceName);
            }))
            {
                return((AMTResource)JsonConvert.DeserializeObject <AMTResource>(File.ReadAllText(AbsResourceName)));
            }
            else
            {
                return(null);
            }
        }