Example #1
0
 public PackageBuilder(PackageBody body, PackageContentType contentType)
 {
     body.ContentType = contentType;
     _content = PackageContent.PackageContent.Create(contentType);
     Errors = new List<PackageErrorInfo>();
     _body = body;
 }
        protected static bool LoadManifest(string PackageFolder, PackageContentType contentType, out PackageManifest manifest)
        {
            manifest = new PackageManifest(contentType);
            if (!Directory.Exists(PackageFolder))
            {
                return(false);
            }

            string[] files = Directory.GetFiles(PackageFolder, PackageManifestName);
            if (files.Length == 0)
            {
                ReportProgress("LoadManifest() did not find " + PackageManifestName + " for package at: " + PackageFolder, LogLevel.Debug);
                return(false);
            }

            manifest.ReadXml(files[0]);
            if (!manifest.IsValid())
            {
                ReportProgress(string.Format("{0}::LoadManifest() {1} not valid.", contentType.ToString(), PackageManifestName), LogLevel.Debug);
                return(false);
            }

            manifest.Path = PackageFolder;
            ReportProgress(string.Format("{0}::LoadManifest() {1} recognized.", contentType.ToString(), PackageManifestName), LogLevel.Debug);

            return(true);
        }
Example #3
0
 public PackageBuilder(PackageBody body, PackageContentType contentType)
 {
     body.ContentType = contentType;
     _content         = PackageContent.PackageContent.Create(contentType);
     Errors           = new List <PackageErrorInfo>();
     _body            = body;
 }
Example #4
0
        public ClientPackage(string ps, string pc, PackageType pt, PackageContentType pct, string pr, string pcn)
        {
            _ps = ps;
            _pc = pc;
            _pr = pr;
            _pct = pct;
            _pt = pt;
            _pcn = pcn;

            _byte_content = new List<byte>();
            _byte_header = new List<byte>();
        }
Example #5
0
        public ipp_Package(string ps, string pc, PackageType pt, PackageContentType pct, string pr, string pcn, string ippv)
        {
            PS   = ps;
            PC   = _defEncoding.GetBytes(pc);
            PCL  = PC.Length;
            PR   = pr;
            PCT  = (int)pct;
            PT   = (int)pt;
            PCN  = pcn;
            IPPV = ippv;

            UID = Guid.NewGuid();
            PD  = DateTime.Now;
        }
Example #6
0
 public static PackageContent Create(PackageContentType type)
 {
     switch (type)
     {
         case PackageContentType.Packed:
             return new PackageContentPacked();
         case PackageContentType.Empty:
             return new PackageContentEmpty();
         case PackageContentType.Direct:
             return new PackageContentDirect();
         default:
             return new PackageContentDirect();
     }
 }
Example #7
0
        private void LoadPackageBody(string filePath)
        {
            string             contentDirectoryPath = GetContentPath();
            PackageContentType contentType          = PackageContent.PackageContent.GetContentType(filePath);

            if (contentType == PackageContentType.Wrong)
            {
                throw new Exception("Неверный тип файла");
            }
            _content = PackageContent.PackageContent.Create(contentType);
            _context.Log.AddLogInformation("Создали экземпляр PackageContent");
            _content.LoadBody(contentDirectoryPath, filePath);
            InternalLoadPackageBody();
        }
Example #8
0
        private void SavePackage(string filePath, PackageContentType type)
        {
            bool   isDevelopment = ConfigurationManager.AppSettings.AllKeys.Contains("DEVELOPER") && ConfigurationManager.AppSettings["DEVELOPER"] == "true";
            string templatesPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), FOLDER_TEMPLATES);
            bool   isTemplate    = filePath.StartsWith(templatesPath);
            string newFilePath   = CorrectPackageFilePath(filePath);

            bool saveFile = true;

            if (!isDevelopment && isTemplate)
            {
                if (MessageBox.Show("Нельзя сохранять пакет в папку с шаблонами. Хотите вместо этого сохранить пакет а папку <" + newFilePath + ">?", "Недопустимое расположение файла", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
                {
                    filePath = newFilePath;
                    CreateNewPackageDirectory(filePath);
                    saveFile = true;
                }
                else
                {
                    MessageBox.Show("Пакет не сохранен", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    saveFile = false;
                }
            }

            if (saveFile)
            {
                _packageFilePath = filePath;
                SetFilePathStatus(_packageFilePath);
                PackageBody body = _tree.Body;
                body.ContentType = type;
                PackageBuilder builder     = new PackageBuilder(body, type);
                bool           saveSuccess = false;
                ExecuteAsyncWithWait((() =>
                {
                    saveSuccess = builder.Save(_packageFilePath, true);
                }), null, "Сохранение пакета");
                if (!saveSuccess)
                {
                    string message = "";
                    foreach (PackageErrorInfo error in builder.Errors)
                    {
                        message += error.Description + "\r\n";
                    }
                    MessageBox.Show(this, "Пакет не сохранен. Обнаружены ошибки: \r\n" + message, "Пакет не сохранен", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #9
0
        public static PackageContent Create(PackageContentType type)
        {
            switch (type)
            {
            case PackageContentType.Packed:
                return(new PackageContentPacked());

            case PackageContentType.Empty:
                return(new PackageContentEmpty());

            case PackageContentType.Direct:
                return(new PackageContentDirect());

            default:
                return(new PackageContentDirect());
            }
        }
Example #10
0
        private void LoadPackageContent(string filePath)
        {
            string contentDirectoryPath = GetContentPath();

            PackageContentType contentType = PackageContent.PackageContent.GetContentType(filePath);

            if (contentType == PackageContentType.Wrong)
            {
                throw new Exception("Неверный тип файла");
            }
            _content = PackageContent.PackageContent.Create(contentType);
            _context.Log.AddLogInformation("Создали экземпляр PackageContent");
            _content.OnProgress           += _context.Log.SendProgress;
            _content.OnQueryCancel        += _context.Log.GetPendingCancel;
            _context.Log.CurrentProgress   = 0;
            _context.Log.ProgressTotalCost = 100;
            _content.Load(contentDirectoryPath, filePath);
            CheckPendingCancel();
            _context.Log.AddLogInformation("Загрузили контент из '" + filePath + "', тип контента " + contentType);
        }
Example #11
0
 private IPackage Send(string pc, PackageType pt, PackageContentType pct, string ps, string pr, string pcn = "")
 {
     IPackage package = new ipp_Package(ps, pc, pt, pct, pr, pcn, "1.0.0.0");
     var bytes = package.ToServerBytes();
     string s = Convert.ToBase64String(bytes);
     if (socket.State == WebSocketState.Open)
     {
         socket.Send(bytes, 0, bytes.Length);
         return package;
     }
     else { return null; }
 }
Example #12
0
 public PackageManifest(PackageContentType contentType)
 {
     m_required_content_type = contentType;
 }
 public PackageInstallerPlatformSpecific(PackageContentType contentType, string installFolder, PackageInstallRoot installRoot)
 {
     m_content_type = contentType;
       m_install_folder = installFolder;
       m_install_root = installRoot;
 }
        protected static bool LoadManifest(string PackageFolder, PackageContentType contentType, out PackageManifest manifest)
        {
            manifest = new PackageManifest(contentType);
              if (!Directory.Exists(PackageFolder))
            return false;

              string[] files = Directory.GetFiles(PackageFolder, PackageManifestName);
              if (files.Length == 0)
              {
            ReportProgress("LoadManifest() did not find " + PackageManifestName + " for package at: " + PackageFolder, LogLevel.Debug);
            return false;
              }

              manifest.ReadXml(files[0]);
              if (!manifest.IsValid())
              {
            ReportProgress(string.Format("{0}::LoadManifest() {1} not valid.", contentType.ToString(), PackageManifestName), LogLevel.Debug);
            return false;
              }

              manifest.Path = PackageFolder;
              ReportProgress(string.Format("{0}::LoadManifest() {1} recognized.", contentType.ToString(), PackageManifestName), LogLevel.Debug);

              return true;
        }
 public PackageInstallerPlatformSpecific(PackageContentType contentType, string installFolder, PackageInstallRoot installRoot)
 {
     m_content_type   = contentType;
     m_install_folder = installFolder;
     m_install_root   = installRoot;
 }
Example #16
0
        private void ReadXml101(XmlDocument doc)
        {
            XmlNode package = doc.SelectSingleNode("/RhinoInstaller/Package");
              if (package == null)
            return;

              this.VersionNumber = new Version(XmlHelper.SelectSingleNodeInnerText(package, "Version"));
              this.Title = XmlHelper.SelectSingleNodeInnerText(package, "Title");

              // GUID
              string sGuid = XmlHelper.SelectSingleNodeInnerText(package, "ID");
              try
              {
            this.ID = new Guid(sGuid);
              }
              catch
              {
            throw new PackageAuthoringException(string.Format("GUID malformed: '{0}'", sGuid));
              }

              this.UpdateUrl = XmlHelper.SelectSingleNodeInnerText(package, "UpdateUrl");
              string os = XmlHelper.SelectSingleNodeInnerText(package, "OS");
              try
              {
            OS = (OSPlatform)Enum.Parse(OS.GetType(), os);
              }
              catch
              {
            throw new InvalidOperatingSystemException(os);
              }

              XmlNode contentType = package.SelectSingleNode("ContentType");
              if (contentType != null)
              {
            this.ContentType = PackageContentType.Unknown;
            PackageContentType t;
            if (Enum.TryParse(contentType.InnerText, out t))
            {
              this.ContentType = t;
            }
              }

              // Platform, if it exists
              XmlNodeList platforms = package.SelectNodes("RhinoPlatform");
              if (platforms != null)
              {
            foreach (XmlNode platform in platforms)
            {
              RhinoPlatform p = RhinoPlatform.Unknown;
              p = (RhinoPlatform) Enum.Parse(p.GetType(), platform.InnerText);
              if (p != RhinoPlatform.Unknown)
            SupportedPlatforms.Add(p);
            }
              }

              // Culture, if it exists
              XmlNode culture = package.SelectSingleNode("Locale");
              if (null != culture)
              {
            if ( 0 != System.String.CompareOrdinal(culture.InnerText.ToUpperInvariant(), "LOCALEINVARIANT")
              && 0 != System.String.CompareOrdinal(culture.InnerText.ToUpperInvariant(), "UNKNOWN") )
            {
              Locale = new CultureInfo(culture.InnerText);
            }
              }

              ReadFromDocument(package);
        }
Example #17
0
 public PackageManifest(PackageContentType contentType)
 {
     m_required_content_type = contentType;
 }
Example #18
0
        private void ReadXml101(XmlDocument doc)
        {
            XmlNode package = doc.SelectSingleNode("/RhinoInstaller/Package");

            if (package == null)
            {
                return;
            }

            this.VersionNumber = new Version(XmlHelper.SelectSingleNodeInnerText(package, "Version"));
            this.Title         = XmlHelper.SelectSingleNodeInnerText(package, "Title");

            // GUID
            string sGuid = XmlHelper.SelectSingleNodeInnerText(package, "ID");

            try
            {
                this.ID = new Guid(sGuid);
            }
            catch
            {
                throw new PackageAuthoringException(string.Format("GUID malformed: '{0}'", sGuid));
            }

            this.UpdateUrl = XmlHelper.SelectSingleNodeInnerText(package, "UpdateUrl");
            string os = XmlHelper.SelectSingleNodeInnerText(package, "OS");

            try
            {
                OS = (OSPlatform)Enum.Parse(OS.GetType(), os);
            }
            catch
            {
                throw new InvalidOperatingSystemException(os);
            }

            XmlNode contentType = package.SelectSingleNode("ContentType");

            if (contentType != null)
            {
                this.ContentType = PackageContentType.Unknown;
                PackageContentType t;
                if (Enum.TryParse(contentType.InnerText, out t))
                {
                    this.ContentType = t;
                }
            }

            // Platform, if it exists
            XmlNodeList platforms = package.SelectNodes("RhinoPlatform");

            if (platforms != null)
            {
                foreach (XmlNode platform in platforms)
                {
                    RhinoPlatform p = RhinoPlatform.Unknown;
                    p = (RhinoPlatform)Enum.Parse(p.GetType(), platform.InnerText);
                    if (p != RhinoPlatform.Unknown)
                    {
                        SupportedPlatforms.Add(p);
                    }
                }
            }

            // Culture, if it exists
            XmlNode culture = package.SelectSingleNode("Locale");

            if (null != culture)
            {
                if (0 != System.String.CompareOrdinal(culture.InnerText.ToUpperInvariant(), "LOCALEINVARIANT") &&
                    0 != System.String.CompareOrdinal(culture.InnerText.ToUpperInvariant(), "UNKNOWN"))
                {
                    Locale = new CultureInfo(culture.InnerText);
                }
            }

            ReadFromDocument(package);
        }
Example #19
0
        private void SavePackage(string filePath, PackageContentType type)
        {
            bool isDevelopment = ConfigurationManager.AppSettings.AllKeys.Contains("DEVELOPER") && ConfigurationManager.AppSettings["DEVELOPER"] == "true";
            string templatesPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), FOLDER_TEMPLATES);
            bool isTemplate = filePath.StartsWith(templatesPath);
            string newFilePath = CorrectPackageFilePath(filePath);

            bool saveFile = true;

            if (!isDevelopment && isTemplate)
            {
                if (MessageBox.Show("Нельзя сохранять пакет в папку с шаблонами. Хотите вместо этого сохранить пакет а папку <" + newFilePath + ">?", "Недопустимое расположение файла", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
                {
                    filePath = newFilePath;
                    CreateNewPackageDirectory(filePath);
                    saveFile = true;
                }
                else
                {
                    MessageBox.Show("Пакет не сохранен", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    saveFile = false;
                }
            }

            if (saveFile)
            {
                _packageFilePath = filePath;
                SetFilePathStatus(_packageFilePath);
                PackageBody body = _tree.Body;
                body.ContentType = type;
                PackageBuilder builder = new PackageBuilder(body, type);
                bool saveSuccess = false;
                ExecuteAsyncWithWait((() =>
                {
                    saveSuccess = builder.Save(_packageFilePath, true);
                }), null, "Сохранение пакета");
                if (!saveSuccess)
                {
                    string message = "";
                    foreach (PackageErrorInfo error in builder.Errors)
                    {
                        message += error.Description + "\r\n";
                    }
                    MessageBox.Show(this, "Пакет не сохранен. Обнаружены ошибки: \r\n" + message, "Пакет не сохранен", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }
        }
Example #20
0
        public ipp_Package(Guid uid, DateTime pd, string ps, string pc, PackageType pt, PackageContentType pct, string pr, string pcn, string ippv)
        {
            PS   = ps;
            PC   = _defEncoding.GetBytes(pc);
            PCL  = PC.Length;
            PR   = pr;
            PCT  = (int)pct;
            PT   = (int)pt;
            PCN  = pcn;
            IPPV = ippv;

            UID = uid;
            PD  = pd;
        }