Example #1
0
        private void InitializeCodeViewer()
        {
            // todo: correct below code to properly find samples inside zip
            string filename1 = _sample.TypeName.Replace('.', '/') + ".cs";
            string filename2 = _sample.TypeName.Replace('.', '/') + ".Designer.cs";

            // Code from WPF version:
            // var sourceArray = Source.Split('\\');
            // string xaml = String.Format("{0}/{1}", sourceArray.First(), sourceArray.Last());
            // string cs = String.Format("{0}/{1}.cs", sourceArray.First(), sourceArray.Last());

            Stream s = _exAsm.GetManifestResourceStream(SOURCE_NAME);

            if (s != null)
            {
                C1ZipFile z = new C1ZipFile();
                z.Open(s);
                if (z.Entries[filename1] != null)
                {
                    _code.Add(filename1, string.Empty);
                }
                if (z.Entries[filename2] != null)
                {
                    _code.Add(filename2, string.Empty);
                }
                z.Close();
            }
        }
Example #2
0
        // open an existing zip file
        async void _btnOpen_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var picker = new Windows.Storage.Pickers.FileOpenPicker();

                picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
                picker.FileTypeFilter.Add(".zip");
                StorageFile _zipfile = await picker.PickSingleFileAsync();

                if (_zipfile != null)
                {
                    Clear();
                    progressBar.Visibility = Visibility.Visible;

                    if (_zip == null)
                    {
                        _zip = new C1ZipFile(new System.IO.MemoryStream(), true);
                    }
                    var stream = await _zipfile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);

                    _zip.Open(stream.AsStream());

                    _btnExtract.IsEnabled = true;
                    RefreshView();
                }
            }
            catch (Exception x)
            {
                System.Diagnostics.Debug.WriteLine(x.Message);
            }
            progressBar.Visibility = Visibility.Collapsed;
        }
Example #3
0
        public static void ExtractC1NWind()
        {
            Assembly asm = Assembly.GetExecutingAssembly();

            using (Stream stream = asm.GetManifestResourceStream("FlexReportSamples.Resources.C1NWind.xml.zip"))
            {
                C1ZipFile zf = new C1ZipFile();
                zf.Open(stream);
                using (Stream src = zf.Entries[0].OpenReader())
                {
                    if (!File.Exists("C1NWind.xml") || new FileInfo("C1NWind.xml").Length != zf.Entries[0].SizeUncompressed)
                    {
                        using (Stream dst = new FileStream("C1NWind.xml", FileMode.Create))
                        {
                            byte[] buf = new byte[16 * 1024];
                            int    len;
                            while ((len = src.Read(buf, 0, buf.Length)) > 0)
                            {
                                dst.Write(buf, 0, len);
                            }
                        }
                    }
                }
            }
        }
        // open an existing zip file
        void _btnOpen_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Microsoft.Win32.OpenFileDialog op = new Microsoft.Win32.OpenFileDialog();

                op.RestoreDirectory = true;
                op.Filter           = "Zip(*.zip)|*.zip";

                var open = op.ShowDialog();

                if (open.HasValue && open.Value)
                {
                    Clear();
                    progressBar.Visibility = Visibility.Visible;

                    if (_zip == null)
                    {
                        _zip = new C1ZipFile();
                    }

                    _zip.Open(op.FileName);
                    _btnExtract.IsEnabled = true;
                    RefreshView();
                }
            }
            catch (Exception x)
            {
                progressBar.Visibility = Visibility.Collapsed;
                // snapped?
                System.Diagnostics.Debug.WriteLine(x.Message);
            }
            progressBar.Visibility = Visibility.Collapsed;
        }
Example #5
0
        private void LoadZip()
        {
            // locate zip file
            string strFile = Application.ExecutablePath;
            int    i       = strFile.IndexOf("\\bin");

            if (i > -1)
            {
                strFile = strFile.Substring(0, i);
            }
            strFile += "\\" + zipName;

            // open password-protected zip file
            C1ZipFile zip = new C1ZipFile();

            zip.Open(strFile);
            zip.Password = zipPwd;

            // load report definition XML document from compressed stream
            Stream stream = zip.Entries[0].OpenReader();

            _xmlDoc = new XmlDocument();
            _xmlDoc.PreserveWhitespace = true;
            _xmlDoc.Load(stream);
            stream.Close();
            //
            zip.Close();
            //
            _lbReports.Items.AddRange(C1FlexReport.GetReportList(_xmlDoc));
        }
Example #6
0
        void OpenZip(string fn)
        {
            // make sure this is a valid zip file
            if (!File.Exists(fn))
            {
                return;
            }
            if (!C1ZipFile.IsZipFile(fn))
            {
                return;
            }

            // open zip file
            try
            {
                _zipFile.Open(fn);
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message, "Open Zip File", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // update user interface
            UpdateUI();
        }
Example #7
0
        void LoadProjectStructure()
        {
            Assembly asm = Assembly.GetExecutingAssembly();

            Stream s = asm.GetManifestResourceStream("ControlExplorer.SourceCode.zip");

            C1ZipFile z = new C1ZipFile();

            z.Open(s);

            C1TreeNodeCollection targetNodeCollection = null;
            int previousLevel = -1;

            for (int i = 0; i < z.Entries.Count; i++)
            {
                string[] partsOfPath = z.Entries[i].FileName.Split('/');

                int level      = partsOfPath.Length - 2;
                int imageIndex = 0;

                if (!string.IsNullOrEmpty(partsOfPath[partsOfPath.Length - 1]))
                {
                    level      = partsOfPath.Length - 1;
                    imageIndex = 2;
                }

                string nodeName = partsOfPath[level];

                if (targetNodeCollection == null)
                {
                    targetNodeCollection = c1TreeView1.Nodes;
                }
                else
                {
                    if (previousLevel > level)
                    {
                        targetNodeCollection = targetNodeCollection.Parent.ParentCollection;
                    }
                    else if (previousLevel < level)
                    {
                        targetNodeCollection = targetNodeCollection.Last().Nodes;
                    }
                }

                C1TreeNode node = targetNodeCollection.Add(nodeName);
                node.Images.Add(imageIndex);
                previousLevel = level;
            }

            z.Close();
        }
Example #8
0
        private string GetCode(string filename)
        {
            Stream    s    = _exAsm.GetManifestResourceStream(SOURCE_NAME);
            string    code = string.Empty;
            C1ZipFile z    = new C1ZipFile();

            z.Open(s);
            if (z.Entries[filename] != null)
            {
                StreamReader reader = new StreamReader(z.Entries[filename].OpenReader());
                code = reader.ReadToEnd();
                reader.Close();
            }
            z.Close();
            return(code);
        }
 public void ExtractC1NWind()
 {
     using (Stream stream = Application.GetResourceStream(new Uri("/" + _asmName + ";component/FlexViewer/C1NWind.xml.zip", UriKind.Relative)).Stream)
     {
         C1ZipFile zf = new C1ZipFile();
         zf.Open(stream);
         using (Stream src = zf.Entries[0].OpenReader())
         {
             if (!File.Exists("C1NWind.xml") || new FileInfo("C1NWind.xml").Length != zf.Entries[0].SizeUncompressed)
             {
                 using (Stream dst = new FileStream("C1NWind.xml", FileMode.Create))
                 {
                     byte[] buf = new byte[16 * 1024];
                     int    len;
                     while ((len = src.Read(buf, 0, buf.Length)) > 0)
                     {
                         dst.Write(buf, 0, len);
                     }
                 }
             }
         }
     }
 }
        /// <summary>
        /// Opens a package from a web instance.
        /// </summary>
        /// <param name="fileName"> The package file name.</param>
        public void OpenPackageWeb(string fileName)
        {
            C1ZipFile zipFile = new C1ZipFile();
            //  package = new ScriptingApplicationPackage();

            try
            {
                zipFile.Open(fileName);

                // Application
                C1ZipEntry entry = zipFile.Entries[0];
                // Get entry name and convert to guid
                // if invalid GUID, throw exception
                string name = entry.FileName;
                string applicationXml = string.Empty;
                string applicationArgumentsXml = string.Empty;

                // Get Scripting Application Xml.
                Guid g = new Guid(name);
                StreamReader reader = new StreamReader(entry.OpenReader(),System.Text.Encoding.UTF8);
                applicationXml= reader.ReadToEnd();
                reader.Close();

                if ( zipFile.Entries.Count > 1 )
                {
                    // Arguments
                    entry = zipFile.Entries[1];
                    reader = new StreamReader(entry.OpenReader(),System.Text.Encoding.UTF8);
                    applicationArgumentsXml = reader.ReadToEnd();

                    if ( applicationArgumentsXml.ToLower() != "none" )
                    {
                        _arguments = ScriptingApplicationArgs.FromXml(applicationArgumentsXml);
                    }
                    else
                    {
                        _arguments = null;
                    }

                    reader.Close();
                }

                // Get Custom Transforms
                int start = 2;
                for ( int i=2;i<zipFile.Entries.Count;i++ )
                {
                    entry = zipFile.Entries[i];

                    if ( entry.FileName == "CustomTransformsSeparator" )
                    {
                        start = i+1;
                        break;
                    }

                    // Add File References to Application Startup
                    // string location = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + entry.FileName;
            //					if ( !File.Exists(location) )
            //					{
            //						zipFile.Entries.Extract(i, location);
            //					}
                    // Add WebTransform Entry in Configuration.
                    // if exists don't add.
                    // RegisterWebTransform(location);
                    // ScriptingApplicationSerializer.UpdateSerializer();
                }

                // Generate scripting application.
                XmlDocument document = new XmlDocument();
                document.LoadXml(applicationXml);
                _application = ScriptingApplication.Decrypt(document);
                //	_application = ScriptingApplication.FromXml(applicationXml);
            //
            //				for ( int i=start;i<zipFile.Entries.Count;i++ )
            //				{
            //					entry = zipFile.Entries[i];
            //
            //					// Add File References to Internet Cache
            //					string location = Utils.AppLocation.InternetTemp + Path.DirectorySeparatorChar + _application.Header.ApplicationID + Path.DirectorySeparatorChar + entry.FileName;
            //					if ( File.Exists(location) )
            //					{
            //						File.Delete(location);
            //					}
            //					zipFile.Entries.Extract(i, location);
            //				}
            }
            catch
            {
                throw;
            }
            finally
            {
                zipFile.Close();
            }
        }
        /// <summary>
        /// Reads the application id from the package.
        /// </summary>
        /// <param name="packageFile"> The package file.</param>
        /// <returns> An application id.</returns>
        public static string ReadApplicationID(string packageFile)
        {
            string result = string.Empty;
            C1ZipFile zipFile = new C1ZipFile();

            try
            {
                zipFile.Open(packageFile);

                // Application
                C1ZipEntry entry = zipFile.Entries[0];
                // Get entry name and convert to guid
                // if invalid GUID, throw exception
                string name = entry.FileName;

                Guid g = new Guid(name);
                result = name;
            }
            catch ( Exception ex )
            {
                System.Diagnostics.Debug.Write(ex.ToString());
            }
            finally
            {
                zipFile.Close();
            }

            return result;
        }
Example #12
0
        // extract zip resources to destination directory
        //
        // The files to be extracted must be zipped and the resulting zip file must
        // be added to this project as an embedded resource (the name of the resource
        // is not important, as long as it ends with a .zip extension).
        //
        // To do this, right-click the project name in Visual Studio, select the Add Item
        // menu option and select the zip file that will be extracted. Then select the
        // new item, go to the properties window and make sure the BuildAction property
        // is set to Embedded Resource.
        //
        private void SelfExtract(string dstPath)
        {
            // make sure destination path ends with \
            if (!dstPath.EndsWith(@"\"))
            {
                dstPath += @"\";
            }

            // make sure destination directory exists
            if (!Directory.Exists(dstPath))
            {
                string msg = string.Format(
                    "Destination directory doesn't exist. \r\n" +
                    "Would you like to create directory '{0}'?",
                    dstPath);
                DialogResult dr = MessageBox.Show(msg, "Confirm Directory Creation",
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr != DialogResult.Yes)
                {
                    return;
                }
                try
                {
                    Directory.CreateDirectory(dstPath);
                }
                catch
                {
                    MessageBox.Show("Failed to create destination directory.", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            // make list of zip resources in this application
            ArrayList zipRes = new ArrayList();
            Assembly  asm    = Assembly.GetExecutingAssembly();

            foreach (string f in asm.GetManifestResourceNames())
            {
                if (f.ToLower().EndsWith(".zip"))
                {
                    zipRes.Add(f);
                }
            }

            // process each zip resource
            byte[] buf = new byte[64 * 1024];
            foreach (string f in zipRes)
            {
                // copy resource to temp zip file
                string     tempName = Path.GetTempFileName();
                FileStream sOut     = new FileStream(tempName, FileMode.Create);
                Stream     sIn      = asm.GetManifestResourceStream(f);
                for (;;)
                {
                    int read = sIn.Read(buf, 0, buf.Length);
                    sOut.Write(buf, 0, read);
                    if (read < buf.Length)
                    {
                        break;
                    }
                }
                sOut.Close();

                // expand temp zip file into destination directory
                C1ZipFile zip = new C1ZipFile();
                zip.Open(tempName);
                int cur = 0;
                int cnt = zip.Entries.Count;
                foreach (C1ZipEntry ze in zip.Entries)
                {
                    // get source and destination file names
                    string src = ze.FileName;
                    string dst = dstPath + ze.FileName;

                    // create destination subdirectory if necessary
                    string dstFolder = Path.GetDirectoryName(dst);
                    if (!Directory.Exists(dstFolder))
                    {
                        try
                        {
                            Directory.CreateDirectory(dstFolder);
                        }
                        catch (Exception x)
                        {
                            string msg = string.Format("Failed to create directory {0}\r\n{1}", dstFolder, x.Message);
                            MessageBox.Show(msg, "Error Creating Directory",
                                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            continue;
                        }
                    }

                    // extract the entry
                    try
                    {
                        _status.Text = string.Format(" Extracting {0} of {1}: {2}", cur++, cnt, Path.GetFileName(ze.FileName));
                        zip.Entries.Extract(src, dst);
                    }
                    catch (Exception x)
                    {
                        string msg = string.Format("Failed to expand {0}\r\n{1}", ze.FileName, x.Message);
                        MessageBox.Show(msg, "Error Extracting File",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }

                // delete temp zip file
                File.Delete(tempName);

                // restore status
                _status.Text = " Ready";
            }
        }