Ejemplo n.º 1
0
        /**
         * Returns the EditFlags registry value for the specified document type.
         */

        public static int GetEditFlags(string documentClass)
        {
            RegistryKey rk = OpenDocumentKey(documentClass, false);

            if (rk == null)
            {
                return(-1);
            }

            object editFlagsObj = rk.GetValue("EditFlags");

            rk.Close();
            if (editFlagsObj == null)
            {
                return(-1);
            }

            if (editFlagsObj is Array)
            {
                JetMemoryStream ms = new JetMemoryStream((byte[] )editFlagsObj, true);
                BinaryReader    br = new BinaryReader(ms);
                return(br.ReadInt32());
            }

            return((int)editFlagsObj);
        }
Ejemplo n.º 2
0
        private static bool IsDefaultProxyAutoconfigured()
        {
            RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections");

            if (regKey == null)
            {
                return(false);
            }

            byte[] defaultConnectionSettings = (byte[])regKey.GetValue("DefaultConnectionSettings");
            regKey.Close();

            if (defaultConnectionSettings == null || defaultConnectionSettings.Length < 12)
            {
                return(false);
            }

            JetMemoryStream settingStream = new JetMemoryStream(defaultConnectionSettings, true);
            BinaryReader    reader        = new BinaryReader(settingStream, Encoding.UTF8);
            int             length        = reader.ReadInt32();

            bool isAutoProxy = false;

            if (length >= 60)
            {
                reader.ReadInt32();  // settings version
                int flags = reader.ReadInt32();
                if ((flags & PROXY_TYPE_AUTO_PROXY_URL) != 0)
                {
                    isAutoProxy = true;
                }
            }
            return(isAutoProxy);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads the user sort order from the given resource, in the <b>reverse</b> order.
        /// </summary>
        /// <returns>A list of the resource IDs, in the <b>reverse</b> order.</returns>
        public IntArrayList ReadOrder()
        {
            _resPropertyHolder.Lock();
            try
            {
                // Foolproof checks
                if (_resPropertyHolder.IsDeleted)
                {
                    return(new IntArrayList());
                }
                if (!_resPropertyHolder.HasProp(Core.Props.UserResourceOrder))
                {
                    return(new IntArrayList());
                }

                // Get the byte stream from the saved property
                string          sOrder = _resPropertyHolder.GetStringProp(Core.Props.UserResourceOrder);
                JetMemoryStream ms     = new JetMemoryStream(Convert.FromBase64String(sOrder), true);
                BinaryReader    br     = new BinaryReader(ms);

                // Deserialize the integer IDs
                int          nCount = (int)(br.BaseStream.Length / 4);
                IntArrayList ar     = new IntArrayList(nCount);
                for (int a = 0; a < nCount; a++)
                {
                    ar.Add(br.ReadInt32());
                }
                return(ar);
            }
            finally
            {
                _resPropertyHolder.UnLock();
            }
        }
Ejemplo n.º 4
0
        /**
         * copies one stream to another
         * opening/closing stream is user task
         */
        public static void CopyStream(Stream source, Stream target)
        {
            MemoryStream memStream = source as MemoryStream;

            if (memStream != null)
            {
                memStream.WriteTo(target);
            }
            else
            {
                JetMemoryStream jmStream = source as JetMemoryStream;
                if (jmStream != null)
                {
                    jmStream.WriteTo(target);
                }
                else
                {
                    byte[] buf = new byte[4096];
                    while (true)
                    {
                        int bytesRead = source.Read(buf, 0, 4096);
                        if (bytesRead == 0)
                        {
                            break;
                        }

                        target.Write(buf, 0, bytesRead);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private static void CheckForUpdates(bool manualCheck)
        {
            int    newBuild;
            string newVersion;
            string versionUrl = null;

            WebClient client = new WebClient();

            try
            {
                client.Headers.Add("User-Agent", HttpReader.UserAgent);

                byte[] data;
                string url;

#if READER
                url = "http://www.jetbrains.com/omea/reader-update";
#else
                url = "http://www.jetbrains.com/omea/pro-update";
#endif
                url += ".xml";

                data = client.DownloadData(url);
                JetMemoryStream dataStream = new JetMemoryStream(data, true);
                XmlDocument     doc        = new XmlDocument();
                doc.Load(dataStream);
                XmlNode buildNode = doc.SelectSingleNode("//omea-update/build");
                newBuild = Int32.Parse(buildNode.InnerText);
                XmlNode versionNode = doc.SelectSingleNode("//omea-update/version");
                newVersion = versionNode.InnerText;
                XmlNode urlNode = doc.SelectSingleNode("//omea-update/url");
                if (urlNode != null)
                {
                    versionUrl = urlNode.InnerText;
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Error checking for updates: " + ex.Message);
                Core.NetworkAP.QueueJobAt(DateTime.Now.AddHours(1),
                                          new CheckForUpdatesDelegate(CheckForUpdates), false);
                return;
            }

            Core.SettingStore.WriteDate("UpdateManager", "LastCheckTime", DateTime.Now);
            if (!manualCheck)
            {
                QueueUpdateCheck();
            }
            if (newBuild > Assembly.GetExecutingAssembly().GetName().Version.Build)
            {
                Core.UIManager.QueueUIJob(new NotifyNewVersionDelegate(UpdateNotifyDialog.NotifyNewVersion), newVersion, versionUrl);
            }
            else if (manualCheck)
            {
                Core.UIManager.QueueUIJob(new MethodInvoker(NotifyNoUpdates));
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Requests an URL sending specified request stream using the POST method.
 /// </summary>
 /// <param name="url">URL to web resource.</param>
 /// <param name="requestStream">Stream to send with request.</param>
 public HttpReader(string url, JetMemoryStream requestStream, string requestContentType)
     : this( url )
 {
     if (_urlType != URLType.Web)
     {
         throw new InvalidOperationException("Only web URL can be requested using POST method");
     }
     _requestStream      = requestStream;
     _requestContentType = requestContentType;
 }
Ejemplo n.º 7
0
        private static void  AddSpecificParams(IResource rule, string name, Icon icon)
        {
            rule.BeginUpdate();
            rule.SetProp("IsTrayIconFilter", true);
            rule.SetProp("DeepName", name);
            rule.SetProp("IsLiveMode", true);
            JetMemoryStream mstrm = new JetMemoryStream(2048);

            icon.Save(mstrm);
            rule.SetProp("IconBlob", mstrm);
            rule.DeleteProp(Core.Props.LastError);
            rule.EndUpdate();
        }
Ejemplo n.º 8
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            JetMemoryStream mstrm = new JetMemoryStream(2048);

            if (_icon != null)
            {
                _icon.Save(mstrm);
                new ResourceProxy(_category).SetProp("IconBlob", mstrm);
            }
            else
            {
                new ResourceProxy(_category).DeleteProp("IconBlob");
            }

            DialogResult = DialogResult.OK;
        }
Ejemplo n.º 9
0
 public AsyncTcpClient(string server, int port, int receiveBufferSize, int timeout, ClientMode mode)
     : base()
 {
     _tracer             = new Tracer("TcpClient[" + server + ':' + port.ToString() + ']');
     _server             = server;
     _port               = port;
     _receiveBufferSize  = receiveBufferSize;
     _readStream         = new JetMemoryStream(_defaultReceiveBufferSize);
     _currentLineBuilder = new StringBuilder();
     State               = ClientState.NotStarted;
     _mode               = mode;
     Timeout             = timeout;
     OnTimeout          += new MethodInvoker(OnOperationFailed);
     _sendMethod         = new MethodInvoker(BeginSend);
     _receiveMethod      = new MethodInvoker(BeginReceive);
     _endSendMethod      = new MethodInvoker(EndSend);
     _endReceiveMethod   = new MethodInvoker(EndReceive);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Reads the user sort order from the given resource.
        /// </summary>
        /// <param name="cache">Hashset to which the order is written: the resource IDs get added in the <b>reverse</b> order, so that the bucket-comparer of the hash set allows to sort the resources against the reverse sorting order (thus naturally putting missing items to the end as they have zero bucket values).</param>
        public void ReadOrder(ref IntHashSet cache)
        {
            // TODO: is it possible to preallocate cache to the known size?
            _resPropertyHolder.Lock();
            try
            {
                // Foolproof checks
                if (_resPropertyHolder.IsDeleted)
                {
                    return;
                }
                if (!_resPropertyHolder.HasProp(Core.Props.UserResourceOrder))
                {
                    return;
                }

                // Get the byte stream from the saved property
                string          sOrder = _resPropertyHolder.GetStringProp(Core.Props.UserResourceOrder);
                JetMemoryStream ms     = new JetMemoryStream(Convert.FromBase64String(sOrder), true);
                BinaryReader    br     = new BinaryReader(ms);
                int             nCount = (int)(br.BaseStream.Length / 4);

                // Create a new cache, or reset an existing one to reuse it
                if (cache == null)
                {
                    cache = new IntHashSet();
                }
                else
                {
                    cache.Clear();
                }

                // Deserialize the integer IDs
                for (int a = 0; a < nCount; a++)
                {
                    cache.Add(br.ReadInt32());
                }
            }
            finally
            {
                _resPropertyHolder.UnLock();
            }
        }
Ejemplo n.º 11
0
        private void DecodeReadStream(string encoding)
        {
            try
            {
                _readStream.Position = 0;
                Stream encodedStream;
                if (encoding == "gzip")
                {
                    encodedStream = new GZipInputStream(_readStream);
                }
                else if (encoding == "deflate")
                {
                    encodedStream = new InflaterInputStream(_readStream);
                }
                else
                {
                    return;
                }

                JetMemoryStream decodedStream = new JetMemoryStream(BufferSize);
                while (true)
                {
                    int bytesRead = encodedStream.Read(_responseBytes, 0, BufferSize);
                    if (bytesRead == 0)
                    {
                        break;
                    }

                    decodedStream.Write(_responseBytes, 0, bytesRead);
                }

                encodedStream.Close();
                _readStream.Close();

                _readStream = decodedStream;
            }
            catch (Exception ex)
            {
                throw new HttpDecompressException("Decompression failed", ex);
            }
        }
Ejemplo n.º 12
0
Archivo: Column.cs Proyecto: mo5h/omeo
 private void SetStream(Stream source, Stream target)
 {
     try
     {
         MemoryStream memStream = source as MemoryStream;
         if (memStream != null)
         {
             memStream.WriteTo(target);
         }
         else
         {
             JetMemoryStream jmStream = source as JetMemoryStream;
             if (jmStream != null)
             {
                 jmStream.WriteTo(target);
             }
             else
             {
                 try
                 {
                     if (source.CanSeek)
                     {
                         source.Position = 0;
                     }
                     CopyStream(target, source, _bfs.GetRawBytes());
                 }
                 finally
                 {
                     source.Close();
                 }
             }
         }
     }
     finally
     {
         target.Close();
     }
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Import subscription
        /// </summary>
        public void DoImport(IResource importRoot, bool addToWorkspace)
        {
            if (null == FileNames)
            {
                return;
            }

            int totalFeeds     = Math.Max(FileNames.Length, 1);
            int processedFeeds = 0;

            ImportUtils.UpdateProgress(processedFeeds / totalFeeds, _progressMessage);
            IResource currentRoot = null;

            foreach (string fileName in FileNames)
            {
                string defaultName = null;
                Stream opml        = null;

                if (!File.Exists(fileName))
                {
                    defaultName = fileName;
                    // Try to load as URL
                    try
                    {
                        opml = new JetMemoryStream(new WebClient().DownloadData(fileName), true);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine("OPML file '" + fileName + "' can not be load: '" + ex.Message + "'");
                        opml = null;
                    }
                }
                else
                {
                    defaultName = Path.GetFileName(fileName);
                    // Try to load title from this file
                    try
                    {
                        opml = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine("OPML file '" + fileName + "' can not be load: '" + ex.Message + "'");
                        opml = null;
                    }
                }

                if (null == opml)
                {
                    continue;
                }

                // Try to get name
                string name = null;
                try
                {
                    XmlDocument xml = new XmlDocument();
                    xml.Load(opml);
                    XmlElement title = xml.SelectSingleNode("/opml/head/title") as XmlElement;
                    name = title.InnerText;
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("OPML file '" + fileName + "' doesn't have title: '" + ex.Message + "'");
                }
                if (name == null || name.Length == 0)
                {
                    name = defaultName;
                }

                try
                {
                    opml.Seek(0, SeekOrigin.Begin);
                    if (_manager == null || FileNames.Length > 1)
                    {
                        currentRoot = RSSPlugin.GetInstance().FindOrCreateGroup("Subscription from " + name, importRoot);
                    }
                    else
                    {
                        currentRoot = importRoot;
                    }
                    OPMLProcessor.Import(new StreamReader(opml), currentRoot, addToWorkspace);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("OPML file '" + fileName + "' can not be load: '" + ex.Message + "'");
                    RemoveFeedsAndGroupsAction.DeleteFeedGroup(currentRoot);
                    ImportUtils.ReportError("OPML File Import", "Import of OPML file '" + fileName + "' failed:\n" + ex.Message);
                }

                processedFeeds += 100;
                ImportUtils.UpdateProgress(processedFeeds / totalFeeds, _progressMessage);
            }
            return;
        }
Ejemplo n.º 14
0
        void _btnPicture_Click(object sender, EventArgs e)
        {
            bool ctrlPressed = (ModifierKeys == Keys.Control);

            if (!ctrlPressed)
            {
                using (OpenFileDialog dlg = new OpenFileDialog())
                {
                    dlg.CheckFileExists = true;
                    dlg.Multiselect     = false;
                    dlg.Title           = "Select Image File";
                    dlg.Filter          = "Image files|*.ico;*.png;*.bmp;*jpg|All files|*.*";

                    if (dlg.ShowDialog(this) == DialogResult.OK)
                    {
                        String          file = dlg.FileName;
                        JetMemoryStream origStream = null, thumbStream = null;
                        try
                        {
                            Image image = Image.FromFile(file);
                            origStream = new JetMemoryStream();
                            image.Save(origStream, ImageFormat.Png);

                            Image thumb = GraphicalUtils.GenerateImageThumbnail(image, _cThumbnailDim, _cThumbnailDim);
                            thumbStream = new JetMemoryStream();
                            ImageCodecInfo[]  iciInfo   = ImageCodecInfo.GetImageEncoders();
                            EncoderParameters encParams = new EncoderParameters(1);
                            encParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
                            thumb.Save(thumbStream, iciInfo[1], encParams);

                            Core.ResourceAP.RunJob(new SetPropDelegate(SetStreamProp), Core.ContactManager.Props.PictureOriginal, origStream);
                            Core.ResourceAP.RunJob(new SetPropDelegate(SetStreamProp), Core.ContactManager.Props.Picture, thumbStream);

                            InitializeContactPicture(_resource);
                            Invalidate(true);
                        }
                        catch (Exception ex)
                        {
                            Core.UIManager.ShowSimpleMessageBox("Error Format", ex.Message);

                            Core.ResourceAP.RunJob(new SetPropDelegate(SetStreamProp), Core.ContactManager.Props.PictureOriginal, null);
                            Core.ResourceAP.RunJob(new SetPropDelegate(SetStreamProp), Core.ContactManager.Props.Picture, null);
                        }
                        finally
                        {
                            if (origStream != null)
                            {
                                origStream.Dispose();
                            }
                            if (thumbStream != null)
                            {
                                thumbStream.Dispose();
                            }
                        }
                    }
                }
            }
            else
            {
                //  If there is a reference to a full-scaled picture, show it
                //  in the associated application.
                Stream stream = _resource.GetBlobProp(Core.ContactManager.Props.PictureOriginal);
                if (stream != null)
                {
                    string fileName = Path.GetTempFileName() + ".png";
                    using (Image image = Image.FromStream(stream))
                    {
                        image.Save(fileName, ImageFormat.Png);
                        Utils.RunAssociatedApplicationOnFile(fileName);
                    }
                }
            }
        }
Ejemplo n.º 15
0
        /**
         * User should manually close returned stream
         */
        public static Stream Serialize(IResource resource)
        {
            JetMemoryStream result = new JetMemoryStream();
            BinaryWriter    writer = new BinaryWriter(result);

            writer.Write(resource.Type);
            writer.Write(resource.Properties.Count);
            foreach (IResourceProperty prop in resource.Properties)
            {
                writer.Write((int)prop.DataType);
                int propId = prop.PropId;
                writer.Write(propId);
                switch (prop.DataType)
                {
                case PropDataType.Link:
                {
                    IResourceList links;
                    if (Core.ResourceStore.PropTypes[propId].HasFlag(PropTypeFlags.DirectedLink))
                    {
                        links = (propId < 0) ? resource.GetLinksTo(null, -propId) : resource.GetLinksFrom(null, propId);
                    }
                    else
                    {
                        links = resource.GetLinksOfType(null, propId);
                    }
                    writer.Write(links.Count);
                    foreach (IResource linked in links)
                    {
                        writer.Write(linked.Id);
                    }
                    break;
                }

                case PropDataType.String:
                case PropDataType.LongString:
                {
                    writer.Write(resource.GetPropText(propId));
                    break;
                }

                case PropDataType.StringList:
                {
                    IStringList strList = resource.GetStringListProp(propId);
                    int         count   = strList.Count;
                    writer.Write(count);
                    for (int i = 0; i < count; ++i)
                    {
                        writer.Write(strList[i]);
                    }
                    break;
                }

                case PropDataType.Int:
                {
                    writer.Write(resource.GetIntProp(propId));
                    break;
                }

                case PropDataType.Date:
                {
                    writer.Write(resource.GetDateProp(propId).Ticks);
                    break;
                }

                case PropDataType.Bool:
                {
                    /**
                     * if a resource has bool prop, then it's equal to 'true'
                     * there is no need always to write 'true' to stream :-)
                     */
                    break;
                }

                case PropDataType.Double:
                {
                    writer.Write(resource.GetDoubleProp(propId));
                    break;
                }

                case PropDataType.Blob:
                {
                    Stream stream = resource.GetBlobProp(propId);
                    writer.Write((int)stream.Length);
                    FileResourceManager.CopyStream(stream, result);
                    break;
                }

                default:
                {
                    throw new Exception("Serialized resource has properties of unknown type");
                }
                }
            }
            return(result);
        }
Ejemplo n.º 16
0
 internal MessagePart(byte[] bytes, int count, string name)
 {
     _type    = MessagePartTypes.Attachment;
     _name    = name;
     _content = new JetMemoryStream(bytes, 0, count);
 }