コード例 #1
0
ファイル: WindowItemBase.cs プロジェクト: BillTheBest/IronAHK
 /// <summary>
 /// Sends MouseEvent to the current Window/Child/Control
 /// </summary>
 /// <param name="mouseevent">MouseEvent to send (for now we take also on abstract layer the windows enum, this might be mapped for other OS.)</param>
 /// <param name="location"></param>
 public abstract void SendMouseEvent(WindowsAPI.MOUSEEVENTF mouseevent, Point? location = null);
コード例 #2
0
        /// <summary>
        /// Writes a value to a standard format .ini file.
        /// </summary>
        /// <param name="value">The string or number that will be written to the right of <paramref name="key"/>'s equal sign (=).</param>
        /// <param name="file">The name of the file.</param>
        /// <param name="section">The section name.</param>
        /// <param name="key">The key name.</param>
        /// <remarks><see cref="ErrorLevel"/> is set to <c>1</c> if there was a problem or <c>0</c> otherwise.</remarks>
        public static void IniWrite(string value, string file, string section, string key)
        {
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                ErrorLevel = WindowsAPI.WritePrivateProfileString(section, key, value, file) ? 0 : 1;
                return;
            }

            if (!File.Exists(file))
            {
                ErrorLevel = 1;
                return;
            }

            var within  = string.IsNullOrEmpty(section); // already within blank section
            var written = false;

            section = string.Format(Keyword_IniSectionOpen + "{0}]", section ?? string.Empty);
            var sec = string.IsNullOrEmpty(key);

            var    reader = new StreamReader(file);
            var    writer = new StringWriter();
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                var trimmed = line.Trim();

                if (trimmed.StartsWith(section, StringComparison.OrdinalIgnoreCase))
                {
                    within = true;
                }
                else if (trimmed.StartsWith(Keyword_IniSectionOpen))
                {
                    if (within && !written)
                    {
                        if (value != null)
                        {
                            writer.WriteLine("{0} {1} {2}", key, Keyword_IniKeyAssign.ToString(), value);
                        }
                        written = true;
                    }
                    within = false;
                }

                if (sec && within)
                {
                    continue;
                }

                if (!sec && trimmed.StartsWith(key, StringComparison.OrdinalIgnoreCase))
                {
                    var post = trimmed.Substring(key.Length).Trim();

                    if (post.Length != 0 && post[0] == Keyword_IniKeyAssign)
                    {
                        if (value != null)
                        {
                            writer.WriteLine("{0} {1} {2}", key, Keyword_IniKeyAssign.ToString(), value);
                        }
                        written = true;
                        continue;
                    }
                }

                writer.WriteLine(line);
            }

            reader.Close();
            writer.Flush();
            var text = writer.ToString();

            try
            {
                File.Delete(file);
                File.WriteAllText(file, text);
                ErrorLevel = 0;
            }
            catch (IOException)
            {
                ErrorLevel = 1;
            }
        }