Ejemplo n.º 1
0
        /// <summary>
        /// This extracts a SolutionId from a .wsp solution package.
        /// It opens the CAB extracts the manifest.xml, and then reads the SolutionId
        /// </summary>
        /// <param name="packageName">the full path to the solution package</param>
        /// <returns>SolutionId (GUID) contained in solution</returns>
        public static Guid GetSolutionIdFromPackage(string packageName)
        {
            if (SolutionIdCache.ContainsKey(packageName))
            {
                return(SolutionIdCache[packageName]);
            }
            Guid solutionID;

            try
            {
                System.IO.FileInfo fi = new System.IO.FileInfo(packageName);
                packageName = fi.FullName;

                string temppath = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString().Replace("-", "");

                XmlDocument xdoc = new XmlDocument();
                try
                {
                    // make sure temp path is there
                    System.IO.Directory.CreateDirectory(temppath);

                    // extract the manifest.xml
                    CabLib.Extract cab = new CabLib.Extract();
                    cab.SetSingleFile("manifest.xml");
                    cab.ExtractFile(packageName, temppath);

                    // load it into the main xml doc
                    xdoc.Load(temppath + "\\" + "manifest.xml");
                }
                catch (Exception ee)
                {
                    throw new Exception("Unable to extract manifest.xml from: " + packageName, ee);
                }

                try
                {
                    solutionID = new Guid(xdoc.DocumentElement.Attributes["SolutionId"].Value);
                }
                catch
                {
                    throw new Exception("Unable to parse SolutionId from manifest.xml");
                }

                try
                {
                    // don't care if this fails, but we should try to cleanup anyways
                    System.IO.Directory.Delete(temppath, true);
                }
                catch { }
            }
            catch (Exception ex)
            {
                Log.Warning("Unable to get solution id from manifest: " + ex.Message);
                solutionID = Config.Current.SolutionId;
            }

            SolutionIdCache[packageName] = solutionID;
            return(solutionID);
        }
Ejemplo n.º 2
0
        public void Extract(string tmpDir, string language, string xsnPath)
        {
            var e = new CabLib.Extract();
            var extractedXsnPath = Path.Join(tmpDir, "form", language);

            e.ExtractFile(xsnPath, extractedXsnPath);
            e.CleanUp();
            _rootPath = extractedXsnPath;
        }
Ejemplo n.º 3
0
        private void btnGo_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                txtProgressLog.Text = "starting...\n";
                CabLib.Extract  extractor  = new CabLib.Extract();
                CabLib.Compress compressor = new CabLib.Compress();

                CabLib.Extract.kHeaderInfo cInfo = null;
                if (extractor.IsFileCabinet(txtFilePath.Text, out cInfo))
                {
                    Log("file is a valid cabinet");
                    //extract WSP to temp folder
                    Guid   jobGuid = Guid.NewGuid();
                    string jobid   = jobGuid.ToString("N");

                    Log("current job id is " + jobid);

                    var fi = new FileInfo(txtFilePath.Text);

                    var jobFolder = Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\" + jobid);
                    Log("job temp directory created");
                    extractor.ExtractFile(txtFilePath.Text, jobFolder.FullName);
                    Log("cabinet exatracted to job temp directory");

                    //Load manifest, change solution ID, remove assemblies, etc
                    XDocument xDoc = XDocument.Load(jobFolder.FullName + "\\manifest.xml");
                    Log("manifest loaded");
                    if (chkSetNewSolutionId.IsChecked.Value)
                    {
                        xDoc.Root.Attribute("SolutionId").Value = jobGuid.ToString("D");
                        Log("solution id set to " + jobGuid.ToString("D"));
                    }
                    if (chkRemoveAllDlls.IsChecked.Value)
                    {
                        var xAssemblies = xDoc.Root.Descendants(xDoc.Root.GetDefaultNamespace() + "Assemblies");
                        xAssemblies.Remove();
                        Log("assemblies element removed from manifest");
                        jobFolder.EnumerateFiles("*.dll").ToList().ForEach(dll => { File.SetAttributes(dll.FullName, FileAttributes.Normal); File.Delete(dll.FullName); });
                        Log("all dll files deleted");
                    }
                    xDoc.Save(jobFolder.FullName + "\\manifest.xml");
                    Log("updated manifest file saved");

                    //repackage as a new WSP or overwrite source file
                    string wspFileName = txtNewFileName.Text.Replace("{filename}", fi.Name.Remove(fi.Name.Length - 4)) + ".wsp";
                    Log("new wsp file name is " + wspFileName);
                    //Build Dictionary<string,string> for all cab files
                    DDFBuilder.Build(jobFolder.FullName, wspFileName);
                    Log("ddf file built");

                    compressor.SwitchCompression(CabLib.Compress.eCompress.MSZIP);
                    compressor.CompressFolder(jobFolder.FullName, fi.Directory.FullName + "\\" + wspFileName, null, true, true, int.MaxValue);
                    Log("cabinet file craeted");


                    jobFolder.EnumerateFiles("*.*", SearchOption.AllDirectories).ToList().ForEach(dll => { File.SetAttributes(dll.FullName, FileAttributes.Normal); });
                    System.IO.Directory.Delete(jobFolder.FullName, true);
                    Log("temp job folder deleted");
                    Log("i'm done. what's next?");
                }
            }
            catch (Exception ex)
            {
                Log("oops! something went wrong, " + ex.ToString());
            }
        }