Esempio n. 1
0
        /// <summary>
        /// 解压一个文件
        /// </summary>
        /// <param name="zipedFileName">压缩文件中的文件名</param>
        /// <param name="encryptKey">加密密码(优先检查), NULL表示不加密</param>
        /// <param name="licenseKeyType">授权密码类型,0表示不加密</param>
        /// <returns>解压缩的文件内容</returns>
        public byte[] ReadBytes(string zipedFileName, string encryptKey, int licenseKeyType)
        {
            if (zipObject == null)
            {
                ErrorString = "Open function must called first";
                return(null);
            }

            try
            {
                //查找指定的文件
                Ionic.Zip.ZipEntry foundEntry = zipObject[zipedFileName];
                if (foundEntry == null || foundEntry.IsDirectory)
                {
                    throw new Exception("Cannot find file");
                }

                //创建MemoryStream,用于解压文件
                byte[]       srcBytes = new byte[foundEntry.UncompressedSize];
                MemoryStream stream   = new MemoryStream(srcBytes, 0, srcBytes.Length);
                foundEntry.Extract(stream);
                stream.Close();

                //添加到压缩文件中
                byte[] decodeBytes = null;
                if (!string.IsNullOrWhiteSpace(encryptKey) || licenseKeyType > 0)
                {
                    if (!string.IsNullOrWhiteSpace(encryptKey))
                    {
                        decodeBytes = Security.DecryptData(srcBytes, encryptKey, null);
                    }
                    else
                    {
                        decodeBytes = Security.DecryptDataByLicenseKey(srcBytes, licenseKeyType);
                    }

                    if (decodeBytes == null)
                    {
                        ErrorString = Security.ErrorString;
                        return(null);
                    }
                }
                else
                {
                    decodeBytes = srcBytes;
                }

                return(srcBytes);
            }
            catch (Exception ex)
            {
                ErrorString = ex.Message;
                return(null);
            }
        }
Esempio n. 2
0
        private void ExtractFileToPath(Ionic.Zip.ZipFile z, string OutputPath, string FileName)
        {
            z.UseZip64WhenSaving = Ionic.Zip.Zip64Option.Always;
            StatusFloater.Invoke(new System.Action(() => StatusFloater.lblSubStatus.Text = FileName));
            FileStream fs;

            if (!File.Exists(OutputPath + "\\" + FileName) && z.Count(ze => ze.FileName.Contains(FileName)) > 0)
            {
                fs = new FileStream(OutputPath + "\\" + FileName, FileMode.Create);
                Ionic.Zip.ZipEntry ze = z.Entries.Where(f => f.FileName.Contains(FileName)).First();
                ze.Extract(fs);
                fs.Flush(true);
                fs.Close();
            }
        }
Esempio n. 3
0
        private System.Xml.XmlDocument GetContentXmlFile(Ionic.Zip.ZipFile zipFile)
        {
            // Get file(in zip archive) that contains data ("content.xml").
            Ionic.Zip.ZipEntry contentZipEntry = zipFile["content.xml"];

            // Extract that file to MemoryStream.
            System.IO.Stream contentStream = new System.IO.MemoryStream();
            contentZipEntry.Extract(contentStream);
            contentStream.Seek(0, System.IO.SeekOrigin.Begin);

            // Create XmlDocument from MemoryStream (MemoryStream contains content.xml).
            System.Xml.XmlDocument contentXml = new System.Xml.XmlDocument();
            contentXml.Load(contentStream);

            return(contentXml);
        }
Esempio n. 4
0
        /// #NAME#: #DESCRIPTION#
        public void f_17250dd1_6cd2_4b1b_a7cd_58ec52297bb8()
        {
            //INI CODE PRCGUID: 17250dd1-6cd2-4b1b-a7cd-58ec52297bb8

            String fichero_de_salida = Input_str("Fichero de salida");

            if (fichero_de_salida != "")
            {
                // current program
                ARQODE_UI.GestorProgramas.CVentanaProgramas CVentanaProgramas = new ARQODE_UI.GestorProgramas.CVentanaProgramas(vm);
                String ns_programa = CVentanaProgramas.Namespace_programa_activo.ToString();

                // program stack for recursive exploration
                Stack <KeyValuePair <int, CProgram> > s_prog = new Stack <KeyValuePair <int, CProgram> >();

                // Progs and procs dictionarys
                Dictionary <String, JToken> exp_programs  = new Dictionary <string, JToken>();
                Dictionary <String, JToken> exp_processes = new Dictionary <String, JToken>();

                CProgram cprog = new CProgram(sys, App_globals, ns_programa);
                while ((ns_programa != "") || (s_prog.Count > 0))
                {
                    int i = 0;

                    // Restore program from stack
                    if (cprog == null)
                    {
                        KeyValuePair <int, CProgram> k_prog = s_prog.Pop();
                        i     = k_prog.Key;
                        cprog = k_prog.Value;
                    }
                    int  n_prcs     = ((JArray)cprog.Logic).Count;
                    bool force_exit = false;

                    // Save program and inner processes
                    while ((!force_exit) && (i < n_prcs))
                    {
                        TProcess proc = new TProcess(sys, App_globals, (JObject)((JArray)cprog.Logic).ElementAt(i));
                        if (!exp_programs.ContainsKey(cprog.Program_namespace))
                        {
                            // add program only once
                            exp_programs.Add(cprog.Program_namespace, cprog.get_json.DeepClone());
                        }

                        i++;
                        if (proc.Guid == "Call")
                        {
                            // Add current program to stack and atach the new one for explore recursively
                            s_prog.Push(new KeyValuePair <int, CProgram>(i, cprog));
                            cprog       = new CProgram(sys, App_globals, proc.Configuration["program"].ToString());
                            ns_programa = cprog.Program_namespace;
                            force_exit  = true;
                        }
                        else if (!exp_processes.ContainsKey(proc.Guid))
                        {
                            // add process only once
                            exp_processes.Add(proc.Guid, proc.get_json.DeepClone());
                        }
                    }
                    if ((i == n_prcs) && (!force_exit))
                    {
                        // set null program only if previous bucle ends
                        cprog       = null;
                        ns_programa = "";
                    }
                }

                #region Create zip

                Ionic.Zip.ZipFile exp_file = null;
                if (File.Exists(fichero_de_salida))
                {
                    exp_file = Ionic.Zip.ZipFile.Read(fichero_de_salida);
                }
                else
                {
                    exp_file = new Ionic.Zip.ZipFile(fichero_de_salida);
                }

                #region add programs & ns conversions to zip file

                String entry_path     = "";
                String base_file_path = "";
                JArray jConversion    = new JArray();

                if (exp_file.ContainsEntry(dEXPORTCODE.STR_IMPORT_CONVS))
                {
                    Ionic.Zip.ZipEntry ze = exp_file.Entries.Where(entry => entry.FileName == dEXPORTCODE.STR_IMPORT_CONVS).FirstOrDefault();

                    MemoryStream ms = new MemoryStream();
                    ze.Extract(ms);
                    byte[] entry_data   = ms.ToArray();
                    String file_content = System.Text.Encoding.Default.GetString(entry_data);
                    ms.Close();
                    jConversion = JArray.Parse(file_content);
                }
                foreach (String sprog in exp_programs.Keys)
                {
                    base_file_path = escape_sc(sprog);

                    // Conversions
                    String  new_ns = dPROGRAM.FOLDER + "\\Imports\\" + base_file_path;
                    JObject jconv  = new JObject(new JProperty(sprog, new_ns));
                    jConversion.Add(jconv);

                    // Add program
                    entry_path = dPROGRAM.FOLDER + "\\Imports\\" + base_file_path + ".json";
                    if (!exp_file.ContainsEntry(entry_path))
                    {
                        exp_file.AddEntry(entry_path, System.Text.UTF8Encoding.UTF8.GetBytes(exp_programs[sprog].ToString()));
                    }
                }
                if (exp_file.ContainsEntry(dEXPORTCODE.STR_IMPORT_CONVS))
                {
                    exp_file.UpdateEntry(dEXPORTCODE.STR_IMPORT_CONVS, jConversion.ToString());
                }
                else
                {
                    exp_file.AddEntry(dEXPORTCODE.STR_IMPORT_CONVS, jConversion.ToString());
                }
                #endregion

                #region Create processes file

                JSonFile jfTemplate = new JSonFile(Globals.AppDataSection(dPATH.PROCESSES), dGLOBALS.PROCESS_TEMPLATE.Replace(".json", ""));
                foreach (JToken jproc in exp_processes.Values)
                {
                    ((JArray)jfTemplate.get(dPROCESS.PROCESSES)).Add(jproc);
                }
                #endregion

                #region add processes file

                base_file_path = escape_sc(CVentanaProgramas.Namespace_programa_activo.ToString());
                entry_path     = dPROCESS.FOLDER + "\\Imports\\" + base_file_path + ".json";
                if (!exp_file.ContainsEntry(entry_path))
                {
                    exp_file.AddEntry(entry_path, System.Text.UTF8Encoding.UTF8.GetBytes(jfTemplate.jActiveObj.ToString()));
                }
                #endregion

                exp_file.Save();

                #endregion

                MessageBox.Show(String.Format("Program exported {0}", CVentanaProgramas.Namespace_programa_activo.ToString()));
            }

            //END CODE PRCGUID: 17250dd1-6cd2-4b1b-a7cd-58ec52297bb8
        }