Ejemplo n.º 1
0
        public static ArrayList GetDates()
        {
            ArrayList dates = new ArrayList();

            if (xdoc != null)
            {
                XmlNodeList xdates = xdoc.SelectNodes(SCREENSHOT_XPATH + "/" + SCREENSHOT_DATE);

                foreach (XmlNode xdate in xdates)
                {
                    XmlNodeReader xreader = new XmlNodeReader(xdate);

                    while (xreader.Read())
                    {
                        if (xreader.IsStartElement() && xreader.Name.Equals(SCREENSHOT_DATE))
                        {
                            xreader.Read();

                            if (!string.IsNullOrEmpty(xreader.Value))
                            {
                                dates.Add(xreader.Value);
                            }
                        }
                    }

                    xreader.Close();
                }
            }

            return(dates);
        }
Ejemplo n.º 2
0
        public static Screenshot GetBySlidename(string slidename, int screenNumber)
        {
            Screenshot screenshot = null;

            if (xdoc != null)
            {
                xdoc.LoadXml(Properties.Settings.Default.Screenshots);

                XmlNodeList xscreenshots = xdoc.SelectNodes(SCREENSHOT_XPATH + "[" + SCREENSHOT_SLIDENAME + " = '" + slidename + "' and " + SCREENSHOT_SCREEN + " = '" + screenNumber + "']");

                foreach (XmlNode xscreenshot in xscreenshots)
                {
                    XmlNodeReader xreader = new XmlNodeReader(xscreenshot);

                    while (xreader.Read())
                    {
                        if (xreader.IsStartElement() && xreader.Name.Equals(SCREENSHOT_INDEX))
                        {
                            xreader.Read();

                            if (!string.IsNullOrEmpty(xreader.Value))
                            {
                                screenshot = GetByIndex(Convert.ToInt32(xreader.Value));
                            }
                        }
                    }

                    xreader.Close();
                }
            }

            return(screenshot);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the image editors.
        /// </summary>
        public void Load()
        {
            if (Directory.Exists(FileSystem.ApplicationFolder) &&
                File.Exists(FileSystem.ApplicationFolder + FileSystem.EditorsFile))
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(FileSystem.ApplicationFolder + FileSystem.EditorsFile);

                AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                XmlNodeList xEditors = xDoc.SelectNodes(EDITOR_XPATH);

                foreach (XmlNode xEditor in xEditors)
                {
                    Editor        editor  = new Editor();
                    XmlNodeReader xReader = new XmlNodeReader(xEditor);

                    while (xReader.Read())
                    {
                        if (xReader.IsStartElement())
                        {
                            switch (xReader.Name)
                            {
                            case EDITOR_NAME:
                                xReader.Read();
                                editor.Name = xReader.Value;
                                break;

                            case EDITOR_APPLICATION:
                                xReader.Read();
                                editor.Application = xReader.Value;
                                break;

                            case EDITOR_ARGUMENTS:
                                xReader.Read();
                                editor.Arguments = xReader.Value;
                                break;
                            }
                        }
                    }

                    xReader.Close();

                    if (!string.IsNullOrEmpty(editor.Name) &&
                        !string.IsNullOrEmpty(editor.Application))
                    {
                        Add(editor);
                    }
                }

                if (Settings.VersionManager.IsOldAppVersion(AppVersion, AppCodename))
                {
                    Save();
                }
            }
        }
Ejemplo n.º 4
0
        private SyndicationFeed MakeSyndicationFeed(Feed feed)
        {
            var xmlSerializer = new XmlSerializer(typeof(List <Item>));
            var xmlns         = new XmlSerializerNamespaces();

            xmlns.Add("g", "http://base.google.com/ns/1.0");

            SyndicationFeed syndicationFeed = new SyndicationFeed();

            using (StringWriter writer = new StringWriter())
            {
                try
                {
                    xmlSerializer.Serialize(writer, feed.Items, xmlns);
                } catch (InvalidOperationException e)
                {
                    Debug.WriteLine(e.ToString());
                }

                XmlDocument xmlDocument = new XmlDocument();

                try
                {
                    xmlDocument.LoadXml(writer.ToString());
                } catch (XmlException e)
                {
                    Debug.WriteLine(e.ToString());
                }

                using (XmlReader xmlReader = new XmlNodeReader(xmlDocument.DocumentElement))
                {
                    bool canRead = xmlReader.Read();
                    while (canRead)
                    {
                        if ((xmlReader.Name == "item") && xmlReader.IsStartElement())
                        {
                            string outerxml = xmlReader.ReadOuterXml();
                            canRead = (outerxml != string.Empty);

                            syndicationFeed.ElementExtensions.Add(xmlReader);
                        }
                        else
                        {
                            canRead = xmlReader.Read();
                        }
                    }
                }
            }

            //Add basic feed information
            syndicationFeed.Title           = new TextSyndicationContent(feed.Title);
            syndicationFeed.Description     = new TextSyndicationContent("Google Merchant Centre Feed, Generated by EasywebshopProductFeedAdapter");
            syndicationFeed.Generator       = "EasywebshopProductFeedAdapter";
            syndicationFeed.LastUpdatedTime = feed.Updated;

            return(syndicationFeed);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads the settings.
        /// </summary>
        public void Load()
        {
            if (Directory.Exists(FileSystem.SettingsFolder) && File.Exists(Filepath))
            {
                FileInfo fileInfo = new FileInfo(Filepath);

                // Check the size of the settings file.
                // Delete the file if it's too big so we don't hang.
                if (fileInfo.Length > MAX_FILE_SIZE)
                {
                    File.Delete(Filepath);
                    return;
                }

                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(Filepath);

                AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                XmlNodeList xSettings = xDoc.SelectNodes(SETTING_XPATH);

                foreach (XmlNode xSetting in xSettings)
                {
                    Setting       setting = new Setting();
                    XmlNodeReader xReader = new XmlNodeReader(xSetting);

                    while (xReader.Read())
                    {
                        if (xReader.IsStartElement())
                        {
                            switch (xReader.Name)
                            {
                            case SETTING_KEY:
                                xReader.Read();
                                setting.Key = xReader.Value;
                                break;

                            case SETTING_VALUE:
                                xReader.Read();
                                setting.Value = xReader.Value;
                                break;
                            }
                        }
                    }

                    xReader.Close();

                    if (!string.IsNullOrEmpty(setting.Key))
                    {
                        Add(setting);
                    }
                }
            }
        }
  public static void Main()
  {
    XmlNodeReader reader = null;

    try
    {
       //Create and load the XML document.
       XmlDocument doc = new XmlDocument();
       doc.LoadXml("<book>" +
                   "<title>Pride And Prejudice</title>" +
                   "<price>19.95</price>" +
                   "<misc/>" +
                   "</book>"); 

       //Load the XmlNodeReader 
       reader = new XmlNodeReader(doc);
  
       //Parse the XML and display the text content of each of the elements.
       while (reader.Read()){
         if (reader.IsStartElement()){
           if (reader.IsEmptyElement)
              Console.WriteLine("<{0}/>", reader.Name);
           else{
               Console.Write("<{0}> ", reader.Name);
               reader.Read(); //Read the start tag.
               if (reader.IsStartElement())  //Handle nested elements.
                   Console.Write("\r\n<{0}>", reader.Name);
               Console.WriteLine(reader.ReadString());  //Read the text content of the element.
           }
         }
       } 
       
     } 

     finally 
     {
        if (reader != null)
          reader.Close();
      }
  }
Ejemplo n.º 7
0
        /// <summary>
        /// Loads the settings.
        /// </summary>
        public void Load()
        {
            if (File.Exists(Filepath))
            {
                FileInfo fileInfo = new FileInfo(Filepath);

                // Check the size of the settings file.
                // Delete the file if it's too big so we don't hang.
                if (fileInfo.Length > MAX_FILE_SIZE)
                {
                    File.Delete(Filepath);
                    return;
                }

                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(Filepath);

                XmlNodeList xSettings = xDoc.SelectNodes(SETTING_XPATH);

                foreach (XmlNode xSetting in xSettings)
                {
                    Setting       setting = new Setting();
                    XmlNodeReader xReader = new XmlNodeReader(xSetting);

                    while (xReader.Read())
                    {
                        if (xReader.IsStartElement())
                        {
                            switch (xReader.Name)
                            {
                            case SETTING_KEY:
                                xReader.Read();
                                setting.Key = xReader.Value;
                                break;

                            case SETTING_VALUE:
                                xReader.Read();
                                setting.Value = xReader.Value;
                                break;
                            }
                        }
                    }

                    xReader.Close();

                    if (!string.IsNullOrEmpty(setting.Key))
                    {
                        Add(setting);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Loads the image editors into the application from the editors.xml file.
        /// </summary>
        public static void Load()
        {
            if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + XML_FILE))
            {
                XmlDocument xdoc = new XmlDocument();
                xdoc.Load(AppDomain.CurrentDomain.BaseDirectory + XML_FILE);

                XmlNodeList xeditors = xdoc.SelectNodes(EDITOR_XPATH);

                foreach (XmlNode xeditor in xeditors)
                {
                    Editor        editor  = new Editor();
                    XmlNodeReader xreader = new XmlNodeReader(xeditor);

                    while (xreader.Read())
                    {
                        if (xreader.IsStartElement())
                        {
                            switch (xreader.Name)
                            {
                            case EDITOR_NAME:
                                xreader.Read();
                                editor.Name = xreader.Value;
                                break;

                            case EDITOR_APPLICATION:
                                xreader.Read();
                                editor.Application = xreader.Value;
                                break;

                            case EDITOR_ARGUMENTS:
                                xreader.Read();
                                editor.Arguments = xreader.Value;
                                break;
                            }
                        }
                    }

                    xreader.Close();

                    if (!string.IsNullOrEmpty(editor.Name) &&
                        !string.IsNullOrEmpty(editor.Application) &&
                        !string.IsNullOrEmpty(editor.Arguments))
                    {
                        EditorCollection.Add(editor);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        private void GenerateExtra()
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Filter           = "FL XML file (*.xml)|*.xml";
            fileDialog.FilterIndex      = 1;
            fileDialog.RestoreDirectory = true;
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(fileDialog.FileName);
                XmlNodeReader nodeReader = new XmlNodeReader(doc);
                while (nodeReader.Read())
                {
                    int nodes = nodeReader.AttributeCount;
                    if (nodeReader.IsStartElement() && nodeReader.Name.Equals("include"))
                    {
                        string            messageInclude = $"There's include file {nodeReader.ReadInnerXml()}\nDownload it and hit Yes to load it.\nTo skip - hit No.";
                        string            captionInclude = "Message!";
                        MessageBoxButtons buttonsInclude = MessageBoxButtons.YesNo;
                        DialogResult      resultInclude;
                        resultInclude = MessageBox.Show(messageInclude, captionInclude, buttonsInclude);
                        if (resultInclude == System.Windows.Forms.DialogResult.Yes)
                        {
                            GenerateExtra();
                        }
                    }
                    if (nodeReader.IsStartElement() && nodeReader.Name.Equals("testset"))
                    {
                        TestPlan.WriteLine($"  RUN({nodeReader.GetAttribute(0).ToUpper()}, \"{nodeReader.GetAttribute(1)} <{nodeReader.GetAttribute(0).ToUpper()}>\", mTestBox, DUT1:TESTBOX_RCS:{nodeReader.GetAttribute(0).ToUpper()},{new Func<string>(() => { if (String.IsNullOrEmpty(textBox1.Text)) return ""; else return $" CONNECTION_NAME_S:{textBox1.Text};".ToUpper(); }).Invoke()},)");
                        Criteria.WriteLine($"<MP:I> {nodeReader.GetAttribute(0).ToUpper()},\"{nodeReader.GetAttribute(1)} {new Func<string>(() => { if (nodes >= 4) return $"({ nodeReader.GetAttribute(3)})"; else return ""; }).Invoke()}\",,,EQU,1");
                        Criteria.WriteLine($"<DATA> TBCOMMAND_S,\"{nodeReader.GetAttribute(0)}\"{new Func<string>(() => { if (nodeReader.GetAttribute(0) == "cpm_0011") return $",,SEARCH_AS,cores:{textBox2.Text.ToString()}"; else if (nodeReader.GetAttribute(0) == "early_init") return $",,SEARCH_AS,{textBox3.Text.ToString()}"; else return ""; }).Invoke()}");
                    }
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Loads the image editors.
        /// </summary>
        public void Load()
        {
            if (File.Exists(FileSystem.ApplicationFolder + FileSystem.EditorsFile))
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(FileSystem.ApplicationFolder + FileSystem.EditorsFile);

                XmlNodeList xEditors = xDoc.SelectNodes(EDITOR_XPATH);

                foreach (XmlNode xEditor in xEditors)
                {
                    Editor        editor  = new Editor();
                    XmlNodeReader xReader = new XmlNodeReader(xEditor);

                    while (xReader.Read())
                    {
                        if (xReader.IsStartElement())
                        {
                            switch (xReader.Name)
                            {
                            case EDITOR_NAME:
                                xReader.Read();
                                editor.Name = xReader.Value;
                                break;

                            case EDITOR_APPLICATION:
                                xReader.Read();
                                editor.Application = xReader.Value;
                                break;

                            case EDITOR_ARGUMENTS:
                                xReader.Read();
                                editor.Arguments = xReader.Value;
                                break;
                            }
                        }
                    }

                    xReader.Close();

                    if (!string.IsNullOrEmpty(editor.Name) &&
                        !string.IsNullOrEmpty(editor.Application))
                    {
                        Add(editor);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Loads the image editors.
        /// </summary>
        public static void Load()
        {
            XmlDocument xdoc = new XmlDocument();

            xdoc.LoadXml(Properties.Settings.Default.Editors);

            XmlNodeList xeditors = xdoc.SelectNodes(EDITOR_XPATH);

            foreach (XmlNode xeditor in xeditors)
            {
                Editor        editor  = new Editor();
                XmlNodeReader xreader = new XmlNodeReader(xeditor);

                while (xreader.Read())
                {
                    if (xreader.IsStartElement())
                    {
                        switch (xreader.Name)
                        {
                        case EDITOR_NAME:
                            xreader.Read();
                            editor.Name = xreader.Value;
                            break;

                        case EDITOR_APPLICATION:
                            xreader.Read();
                            editor.Application = xreader.Value;
                            break;

                        case EDITOR_ARGUMENTS:
                            xreader.Read();
                            editor.Arguments = xreader.Value;
                            break;
                        }
                    }
                }

                xreader.Close();

                if (!string.IsNullOrEmpty(editor.Name) &&
                    !string.IsNullOrEmpty(editor.Application) &&
                    !string.IsNullOrEmpty(editor.Arguments))
                {
                    Add(editor);
                }
            }
        }
Ejemplo n.º 12
0
        internal static void ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext)
        {
            XmlElement node = PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(), "SslTransportSecurity", "http://schemas.microsoft.com/ws/2006/05/framing/policy", true);

            if (node != null)
            {
                SslStreamSecurityBindingElement item = new SslStreamSecurityBindingElement();
                XmlReader reader = new XmlNodeReader(node);
                reader.ReadStartElement();
                item.RequireClientCertificate = reader.IsStartElement("RequireClientCertificate", "http://schemas.microsoft.com/ws/2006/05/framing/policy");
                if (item.RequireClientCertificate)
                {
                    reader.ReadElementString();
                }
                policyContext.BindingElements.Add(item);
            }
        }
Ejemplo n.º 13
0
    public static void Main()
    {
        XmlNodeReader reader = null;

        try
        {
            //Create and load the XML document.
            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<book xmlns:bk='urn:samples'> " +
                        "<title>Pride And Prejudice</title>" +
                        "<bk:genre>novel</bk:genre>" +
                        "</book>");

            //Load the XmlNodeReader
            reader = new XmlNodeReader(doc);

            //Parse the XML.  If they exist, display the prefix and
            //namespace URI of each node.
            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    if (reader.Prefix == String.Empty)
                    {
                        Console.WriteLine("<{0}>", reader.LocalName);
                    }
                    else
                    {
                        Console.Write("<{0}:{1}>", reader.Prefix, reader.LocalName);
                        Console.WriteLine(" The namespace URI is " + reader.NamespaceURI);
                    }
                }
            }
        }
        finally
        {
            if (reader != null)
            {
                reader.Close();
            }
        }
    }
        internal static void ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext)
        {
            XmlElement assertion = PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(),
                                                                         TransportPolicyConstants.SslTransportSecurityName, TransportPolicyConstants.DotNetFramingNamespace, true);

            if (assertion != null)
            {
                SslStreamSecurityBindingElement sslBindingElement = new SslStreamSecurityBindingElement();

                XmlReader reader = new XmlNodeReader(assertion);
                reader.ReadStartElement();
                sslBindingElement.RequireClientCertificate = reader.IsStartElement(
                    TransportPolicyConstants.RequireClientCertificateName,
                    TransportPolicyConstants.DotNetFramingNamespace);
                if (sslBindingElement.RequireClientCertificate)
                {
                    reader.ReadElementString();
                }

                policyContext.BindingElements.Add(sslBindingElement);
            }
        }
        internal static void ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext)
        {
            XmlElement node = PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(), "WindowsTransportSecurity", "http://schemas.microsoft.com/ws/2006/05/framing/policy", true);

            if (node != null)
            {
                WindowsStreamSecurityBindingElement item = new WindowsStreamSecurityBindingElement();
                XmlReader reader = new XmlNodeReader(node);
                reader.ReadStartElement();
                string str = null;
                if (reader.IsStartElement("ProtectionLevel", "http://schemas.microsoft.com/ws/2006/05/framing/policy") && !reader.IsEmptyElement)
                {
                    str = reader.ReadElementContentAsString();
                }
                if (string.IsNullOrEmpty(str))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("ExpectedElementMissing", new object[] { "ProtectionLevel", "http://schemas.microsoft.com/ws/2006/05/framing/policy" })));
                }
                item.ProtectionLevel = (System.Net.Security.ProtectionLevel)Enum.Parse(typeof(System.Net.Security.ProtectionLevel), str);
                policyContext.BindingElements.Add(item);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Loads the regions.
        /// </summary>
        public void Load(ImageFormatCollection imageFormatCollection)
        {
            if (File.Exists(FileSystem.ApplicationFolder + FileSystem.RegionsFile))
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(FileSystem.ApplicationFolder + FileSystem.RegionsFile);

                XmlNodeList xRegions = xDoc.SelectNodes(REGION_XPATH);

                foreach (XmlNode xRegion in xRegions)
                {
                    Region        region  = new Region();
                    XmlNodeReader xReader = new XmlNodeReader(xRegion);

                    while (xReader.Read())
                    {
                        if (xReader.IsStartElement())
                        {
                            switch (xReader.Name)
                            {
                            case REGION_NAME:
                                xReader.Read();
                                region.Name = xReader.Value;
                                break;

                            case REGION_FOLDER:
                                xReader.Read();
                                region.Folder = xReader.Value;
                                break;

                            case REGION_MACRO:
                                xReader.Read();
                                region.Macro = xReader.Value;
                                break;

                            case REGION_FORMAT:
                                xReader.Read();
                                region.Format = imageFormatCollection.GetByName(xReader.Value);
                                break;

                            case REGION_JPEG_QUALITY:
                                xReader.Read();
                                region.JpegQuality = Convert.ToInt32(xReader.Value);
                                break;

                            case REGION_RESOLUTION_RATIO:
                                xReader.Read();
                                region.ResolutionRatio = Convert.ToInt32(xReader.Value);
                                break;

                            case REGION_MOUSE:
                                xReader.Read();
                                region.Mouse = Convert.ToBoolean(xReader.Value);
                                break;

                            case REGION_X:
                                xReader.Read();
                                region.X = Convert.ToInt32(xReader.Value);
                                break;

                            case REGION_Y:
                                xReader.Read();
                                region.Y = Convert.ToInt32(xReader.Value);
                                break;

                            case REGION_WIDTH:
                                xReader.Read();
                                region.Width = Convert.ToInt32(xReader.Value);
                                break;

                            case REGION_HEIGHT:
                                xReader.Read();
                                region.Height = Convert.ToInt32(xReader.Value);
                                break;
                            }
                        }
                    }

                    xReader.Close();

                    if (!string.IsNullOrEmpty(region.Name))
                    {
                        Add(region);
                    }
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Loads the settings.
        /// </summary>
        public void Load()
        {
            try
            {
                if (Directory.Exists(FileSystem.SettingsFolder) && File.Exists(Filepath))
                {
                    FileInfo fileInfo = new FileInfo(Filepath);

                    // Check the size of the settings file.
                    // Delete the file if it's too big so we don't hang.
                    if (fileInfo.Length > MAX_FILE_SIZE)
                    {
                        File.Delete(Filepath);

                        Log.Write("WARNING: User settings file was too big and needed to be deleted");
                        return;
                    }

                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(Filepath);

                    AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                    AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                    XmlNodeList xSettings = xDoc.SelectNodes(SETTING_XPATH);

                    foreach (XmlNode xSetting in xSettings)
                    {
                        Setting       setting = new Setting();
                        XmlNodeReader xReader = new XmlNodeReader(xSetting);

                        while (xReader.Read())
                        {
                            if (xReader.IsStartElement())
                            {
                                switch (xReader.Name)
                                {
                                case SETTING_KEY:
                                    xReader.Read();
                                    setting.Key = xReader.Value;
                                    break;

                                case SETTING_VALUE:
                                    xReader.Read();
                                    setting.Value = xReader.Value;
                                    break;
                                }
                            }
                        }

                        xReader.Close();

                        if (!string.IsNullOrEmpty(setting.Key))
                        {
                            Add(setting);
                        }
                    }
                }
                else
                {
                    Log.Write($"WARNING: {FileSystem.SettingsFolder} and \"{Filepath}\" not found. Unable to load settings");
                }
            }
            catch (Exception ex)
            {
                Log.Write("SettingCollection::Load", ex);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Loads the settings.
        /// </summary>
        public void Load()
        {
            try
            {
                if (string.IsNullOrEmpty(Filepath))
                {
                    return;
                }

                if (FileSystem.FileExists(Filepath))
                {
                    // Check the size of the settings file.
                    // Delete the file if it's too big so we don't hang.
                    if (FileSystem.FileContentLength(Filepath) > MAX_FILE_SIZE)
                    {
                        FileSystem.DeleteFile(Filepath);

                        Log.WriteDebugMessage("WARNING: User settings file was too big and needed to be deleted");

                        return;
                    }

                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(Filepath);

                    AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                    AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                    XmlNodeList xSettings = xDoc.SelectNodes(SETTING_XPATH);

                    foreach (XmlNode xSetting in xSettings)
                    {
                        Setting       setting = new Setting();
                        XmlNodeReader xReader = new XmlNodeReader(xSetting);

                        while (xReader.Read())
                        {
                            if (xReader.IsStartElement())
                            {
                                switch (xReader.Name)
                                {
                                case SETTING_KEY:
                                    xReader.Read();
                                    setting.Key = xReader.Value;
                                    break;

                                case SETTING_VALUE:
                                    xReader.Read();
                                    setting.Value = xReader.Value;
                                    break;
                                }
                            }
                        }

                        xReader.Close();

                        if (!string.IsNullOrEmpty(setting.Key))
                        {
                            Add(setting);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteExceptionMessage("SettingCollection::Load", ex);
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Loads the screenshots.
        /// </summary>
        public static void Load(ImageFormatCollection imageFormatCollection, ScreenCollection screenCollection, RegionCollection regionCollection)
        {
            if (Directory.Exists(FileSystem.ApplicationFolder) &&
                File.Exists(FileSystem.ApplicationFolder + FileSystem.ScreenshotsFile))
            {
                xDoc = new XmlDocument();
                xDoc.Load(FileSystem.ApplicationFolder + FileSystem.ScreenshotsFile);

                AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                XmlNodeList xScreeshots = xDoc.SelectNodes(SCREENSHOT_XPATH);

                foreach (XmlNode xScreenshot in xScreeshots)
                {
                    Screenshot screenshot = new Screenshot();
                    screenshot.Slide = new Slide();

                    XmlNodeReader xReader = new XmlNodeReader(xScreenshot);

                    while (xReader.Read())
                    {
                        if (xReader.IsStartElement())
                        {
                            switch (xReader.Name)
                            {
                            case SCREENSHOT_VIEWID:
                                xReader.Read();
                                screenshot.ViewId = Guid.Parse(xReader.Value);
                                break;

                            case SCREENSHOT_DATE:
                                xReader.Read();
                                screenshot.Date = xReader.Value;
                                break;

                            case SCREENSHOT_TIME:
                                xReader.Read();
                                screenshot.Time = xReader.Value;
                                break;

                            case SCREENSHOT_PATH:
                                xReader.Read();
                                screenshot.Path = xReader.Value;
                                break;

                            case SCREENSHOT_FORMAT:
                                xReader.Read();
                                screenshot.Format = imageFormatCollection.GetByName(xReader.Value);
                                break;

                            // 2.1 used "screen" for its definition of each display/monitor whereas 2.2 uses "component".
                            // Active Window is now represented by 0 rather than 5.
                            case SCREENSHOT_SCREEN:
                                if (Settings.VersionManager.IsOldAppVersion(AppVersion, AppCodename) &&
                                    Settings.VersionManager.Versions.Get("Clara", "2.1.8.2") != null)
                                {
                                    xReader.Read();

                                    screenshot.Screen = Convert.ToInt32(xReader.Value);

                                    screenshot.Component = screenshot.Screen == 5 ? 0 : screenshot.Screen;
                                }
                                break;

                            // We still want to support "component" since this was introduced in version 2.2 as the new representation for "screen".
                            case SCREENSHOT_COMPONENT:
                                xReader.Read();
                                screenshot.Component = Convert.ToInt32(xReader.Value);

                                if (screenshot.Component == -1)
                                {
                                    screenshot.ScreenshotType = ScreenshotType.Region;
                                }
                                else if (screenshot.Component == 0)
                                {
                                    screenshot.ScreenshotType = ScreenshotType.ActiveWindow;
                                }
                                else
                                {
                                    screenshot.ScreenshotType = ScreenshotType.Screen;
                                }
                                break;

                            case SCREENSHOT_SLIDENAME:
                                xReader.Read();
                                screenshot.Slide.Name = xReader.Value;
                                break;

                            case SCREENSHOT_SLIDEVALUE:
                                xReader.Read();
                                screenshot.Slide.Value = xReader.Value;
                                break;

                            case SCREENSHOT_WINDOW_TITLE:
                                xReader.Read();
                                screenshot.WindowTitle = xReader.Value;
                                break;

                            case SCREENSHOT_LABEL:
                                xReader.Read();
                                screenshot.Label = xReader.Value;
                                break;
                            }
                        }
                    }

                    xReader.Close();

                    if (Settings.VersionManager.IsOldAppVersion(AppVersion, AppCodename))
                    {
                        if (Settings.VersionManager.Versions.Get("Clara", "2.1.8.2") != null)
                        {
                            // We need to associate the screenshot's view ID with the component's view ID
                            // because this special ID value is used for figuring out what screenshot image to display.
                            screenshot.ViewId = screenCollection.GetByComponent(screenshot.Component).ViewId;

                            string windowTitle = "*Screenshot imported from an old version of Auto Screen Capture*";

                            Regex rgxOldSlidename =
                                new Regex(
                                    @"^(?<Date>\d{4}-\d{2}-\d{2}) (?<Time>(?<Hour>\d{2})-(?<Minute>\d{2})-(?<Second>\d{2})-(?<Millisecond>\d{3}))");

                            string hour        = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Hour"].Value;
                            string minute      = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Minute"].Value;
                            string second      = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Second"].Value;
                            string millisecond = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Millisecond"]
                                                 .Value;

                            screenshot.Date = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Date"].Value;
                            screenshot.Time = hour + ":" + minute + ":" + second + "." + millisecond;

                            screenshot.Slide.Name  = "{date=" + screenshot.Date + "}{time=" + screenshot.Time + "}";
                            screenshot.Slide.Value = screenshot.Time + " [" + windowTitle + "]";

                            screenshot.WindowTitle = windowTitle;
                        }
                    }

                    if (!string.IsNullOrEmpty(screenshot.Date) &&
                        !string.IsNullOrEmpty(screenshot.Time) &&
                        !string.IsNullOrEmpty(screenshot.Path) &&
                        screenshot.Format != null &&
                        !string.IsNullOrEmpty(screenshot.Slide.Name) &&
                        !string.IsNullOrEmpty(screenshot.Slide.Value))
                    {
                        Add(screenshot, screenCollection, regionCollection);
                    }
                }

                // Write out the upgraded screenshots (if any were found).
                if (Settings.VersionManager.IsOldAppVersion(AppVersion, AppCodename))
                {
                    Save();
                }
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Loads the regions.
        /// </summary>
        public void Load(ImageFormatCollection imageFormatCollection)
        {
            try
            {
                if (Directory.Exists(FileSystem.ApplicationFolder) && File.Exists(FileSystem.ApplicationFolder + FileSystem.RegionsFile))
                {
                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(FileSystem.ApplicationFolder + FileSystem.RegionsFile);

                    AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                    AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                    XmlNodeList xRegions = xDoc.SelectNodes(REGION_XPATH);

                    foreach (XmlNode xRegion in xRegions)
                    {
                        Region        region  = new Region();
                        XmlNodeReader xReader = new XmlNodeReader(xRegion);

                        while (xReader.Read())
                        {
                            if (xReader.IsStartElement())
                            {
                                switch (xReader.Name)
                                {
                                case REGION_VIEWID:
                                    xReader.Read();
                                    region.ViewId = Guid.Parse(xReader.Value);
                                    break;

                                case REGION_NAME:
                                    xReader.Read();
                                    region.Name = xReader.Value;
                                    break;

                                case REGION_FOLDER:
                                    xReader.Read();
                                    region.Folder = xReader.Value;
                                    break;

                                case REGION_MACRO:
                                    xReader.Read();
                                    region.Macro = xReader.Value;
                                    break;

                                case REGION_FORMAT:
                                    xReader.Read();
                                    region.Format = imageFormatCollection.GetByName(xReader.Value);
                                    break;

                                case REGION_JPEG_QUALITY:
                                    xReader.Read();
                                    region.JpegQuality = Convert.ToInt32(xReader.Value);
                                    break;

                                case REGION_RESOLUTION_RATIO:
                                    xReader.Read();
                                    region.ResolutionRatio = Convert.ToInt32(xReader.Value);
                                    break;

                                case REGION_MOUSE:
                                    xReader.Read();
                                    region.Mouse = Convert.ToBoolean(xReader.Value);
                                    break;

                                case REGION_X:
                                    xReader.Read();
                                    region.X = Convert.ToInt32(xReader.Value);
                                    break;

                                case REGION_Y:
                                    xReader.Read();
                                    region.Y = Convert.ToInt32(xReader.Value);
                                    break;

                                case REGION_WIDTH:
                                    xReader.Read();
                                    region.Width = Convert.ToInt32(xReader.Value);
                                    break;

                                case REGION_HEIGHT:
                                    xReader.Read();
                                    region.Height = Convert.ToInt32(xReader.Value);
                                    break;
                                }
                            }
                        }

                        xReader.Close();

                        // Change the data for each region that's being loaded if we've detected that
                        // the XML file is from an older version of the application.
                        if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                        {
                            if (Settings.VersionManager.Versions.Get("Clara", "2.1.8.2") != null && string.IsNullOrEmpty(AppCodename) && string.IsNullOrEmpty(AppVersion))
                            {
                                Log.Write("An old version of the regions file was detected. Attempting upgrade to new region format");

                                region.ViewId = Guid.NewGuid();

                                // Get the screenshots folder path from the old user settings to be used for the region's folder property.
                                region.Folder = Settings.VersionManager.OldUserSettings.GetByKey("ScreenshotsDirectory", FileSystem.ScreenshotsFolder).Value.ToString();

                                region.Folder = FileSystem.CorrectDirectoryPath(region.Folder);

                                // 2.1 used "%region%", but 2.2 uses "%name%" for a region's Macro value.
                                region.Macro = region.Macro.Replace("%region%", "%name%");

                                region.Format          = imageFormatCollection.GetByName(ImageFormatSpec.NAME_JPEG);
                                region.JpegQuality     = 100;
                                region.ResolutionRatio = 100;
                                region.Mouse           = false;
                            }
                        }

                        if (!string.IsNullOrEmpty(region.Name))
                        {
                            Add(region);
                        }
                    }

                    // Write out the regions to the XML file now that we've updated the region objects
                    // with their appropriate property values if it was an old version of the application.
                    if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                    {
                        Save();
                    }
                }
                else
                {
                    Log.Write($"WARNING: {FileSystem.RegionsFile} not found. Unable to load regions");
                }
            }
            catch (Exception ex)
            {
                Log.Write("RegionCollection::Load", ex);
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Loads the triggers.
        /// </summary>
        public void LoadXmlFileAndAddTriggers()
        {
            try
            {
                if (FileSystem.FileExists(FileSystem.TriggersFile))
                {
                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(FileSystem.TriggersFile);

                    AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                    AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                    XmlNodeList xTriggers = xDoc.SelectNodes(TRIGGER_XPATH);

                    foreach (XmlNode xTrigger in xTriggers)
                    {
                        Trigger       trigger = new Trigger();
                        XmlNodeReader xReader = new XmlNodeReader(xTrigger);

                        while (xReader.Read())
                        {
                            if (xReader.IsStartElement() && !xReader.IsEmptyElement)
                            {
                                switch (xReader.Name)
                                {
                                case TRIGGER_NAME:
                                    xReader.Read();
                                    trigger.Name = xReader.Value;
                                    break;

                                case TRIGGER_CONDITION:
                                    xReader.Read();
                                    trigger.ConditionType =
                                        (TriggerConditionType)Enum.Parse(typeof(TriggerConditionType), xReader.Value);
                                    break;

                                case TRIGGER_ACTION:
                                    xReader.Read();
                                    trigger.ActionType =
                                        (TriggerActionType)Enum.Parse(typeof(TriggerActionType), xReader.Value);
                                    break;

                                case TRIGGER_EDITOR:
                                    xReader.Read();
                                    trigger.Editor = xReader.Value;
                                    break;

                                case TRIGGER_ACTIVE:
                                    xReader.Read();
                                    trigger.Active = Convert.ToBoolean(xReader.Value);
                                    break;

                                case TRIGGER_DATE:
                                    xReader.Read();
                                    trigger.Date = Convert.ToDateTime(xReader.Value);
                                    break;

                                case TRIGGER_TIME:
                                    xReader.Read();
                                    trigger.Time = Convert.ToDateTime(xReader.Value);
                                    break;
                                }
                            }
                        }

                        xReader.Close();

                        // Change the data for each Trigger that's being loaded if we've detected that
                        // the XML document is from an older version of the application.
                        if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                        {
                            Log.WriteDebugMessage("An old version of the triggers.xml file was detected. Attempting upgrade to new schema.");

                            Version v2300         = Settings.VersionManager.Versions.Get("Boombayah", "2.3.0.0");
                            Version configVersion = Settings.VersionManager.Versions.Get(AppCodename, AppVersion);

                            if (v2300 != null && configVersion != null && configVersion.VersionNumber < v2300.VersionNumber)
                            {
                                Log.WriteDebugMessage("Dalek 2.2.4.6 or older detected");

                                // This is a new property for Trigger that was introduced in 2.3.0.0
                                // so any version before 2.3.0.0 needs to have it during an upgrade.
                                trigger.Active = true;
                            }
                        }

                        if (!string.IsNullOrEmpty(trigger.Name))
                        {
                            Add(trigger);
                        }
                    }

                    if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                    {
                        SaveToXmlFile();
                    }
                }
                else
                {
                    Log.WriteDebugMessage($"WARNING: {FileSystem.TriggersFile} not found. Creating default triggers");

                    Trigger triggerApplicationStartShowInterface = new Trigger()
                    {
                        Active        = true,
                        Name          = "Application Startup -> Show",
                        ConditionType = TriggerConditionType.ApplicationStartup,
                        ActionType    = TriggerActionType.ShowInterface
                    };

                    Trigger triggerScreenCaptureStartedHideInterface = new Trigger()
                    {
                        Active        = true,
                        Name          = "Capture Started -> Hide",
                        ConditionType = TriggerConditionType.ScreenCaptureStarted,
                        ActionType    = TriggerActionType.HideInterface
                    };

                    Trigger triggerScreenCaptureStoppedShowInterface = new Trigger()
                    {
                        Active        = true,
                        Name          = "Capture Stopped -> Show",
                        ConditionType = TriggerConditionType.ScreenCaptureStopped,
                        ActionType    = TriggerActionType.ShowInterface
                    };

                    Trigger triggerInterfaceClosingHideInterface = new Trigger()
                    {
                        Active        = true,
                        Name          = "Interface Closing -> Hide",
                        ConditionType = TriggerConditionType.InterfaceClosing,
                        ActionType    = TriggerActionType.HideInterface
                    };

                    Trigger triggerLimitReachedStopScreenCapture = new Trigger()
                    {
                        Active        = true,
                        Name          = "Limit Reached -> Stop",
                        ConditionType = TriggerConditionType.LimitReached,
                        ActionType    = TriggerActionType.StopScreenCapture
                    };

                    // Setup a few "built in" triggers by default.
                    Add(triggerApplicationStartShowInterface);
                    Add(triggerScreenCaptureStartedHideInterface);
                    Add(triggerScreenCaptureStoppedShowInterface);
                    Add(triggerInterfaceClosingHideInterface);
                    Add(triggerLimitReachedStopScreenCapture);

                    SaveToXmlFile();
                }
            }
            catch (Exception ex)
            {
                Log.WriteExceptionMessage("TriggerCollection::LoadXmlFileAndAddTriggers", ex);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Loads the image schedules from the schedules.xml file.
        /// </summary>
        public bool LoadXmlFileAndAddSchedules(Config config, FileSystem fileSystem, Log log)
        {
            try
            {
                if (fileSystem.FileExists(fileSystem.SchedulesFile))
                {
                    log.WriteDebugMessage("Schedules file \"" + fileSystem.SchedulesFile + "\" found. Attempting to load XML document");

                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(fileSystem.SchedulesFile);

                    log.WriteDebugMessage("XML document loaded");

                    AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                    AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                    XmlNodeList xSchedules = xDoc.SelectNodes(SCHEDULE_XPATH);

                    foreach (XmlNode xSchedule in xSchedules)
                    {
                        Schedule      schedule = new Schedule();
                        XmlNodeReader xReader  = new XmlNodeReader(xSchedule);

                        while (xReader.Read())
                        {
                            if (xReader.IsStartElement() && !xReader.IsEmptyElement)
                            {
                                switch (xReader.Name)
                                {
                                case SCHEDULE_NAME:
                                    xReader.Read();
                                    schedule.Name = xReader.Value;
                                    break;

                                case SCHEDULE_ENABLE:
                                case "active":     // Any version older than 2.4.0.0 used "active" instead of "enable".
                                    xReader.Read();
                                    schedule.Enable = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_MODE_ONETIME:
                                    xReader.Read();
                                    schedule.ModeOneTime = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_MODE_PERIOD:
                                    xReader.Read();
                                    schedule.ModePeriod = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_CAPTUREAT:
                                    xReader.Read();
                                    schedule.CaptureAt = Convert.ToDateTime(xReader.Value);
                                    break;

                                case SCHEDULE_STARTAT:
                                    xReader.Read();
                                    schedule.StartAt = Convert.ToDateTime(xReader.Value);
                                    break;

                                case SCHEDULE_STOPAT:
                                    xReader.Read();
                                    schedule.StopAt = Convert.ToDateTime(xReader.Value);
                                    break;

                                case SCHEDULE_SCREEN_CAPTURE_INTERVAL:
                                    xReader.Read();
                                    schedule.ScreenCaptureInterval = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCHEDULE_MONDAY:
                                    xReader.Read();
                                    schedule.Monday = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_TUESDAY:
                                    xReader.Read();
                                    schedule.Tuesday = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_WEDNESDAY:
                                    xReader.Read();
                                    schedule.Wednesday = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_THURSDAY:
                                    xReader.Read();
                                    schedule.Thursday = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_FRIDAY:
                                    xReader.Read();
                                    schedule.Friday = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_SATURDAY:
                                    xReader.Read();
                                    schedule.Saturday = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_SUNDAY:
                                    xReader.Read();
                                    schedule.Sunday = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_NOTES:
                                    xReader.Read();
                                    schedule.Notes = xReader.Value;
                                    break;

                                case SCHEDULE_LOGIC:
                                    xReader.Read();
                                    schedule.Logic = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCHEDULE_SCOPE:
                                    xReader.Read();
                                    schedule.Scope = xReader.Value;
                                    break;
                                }
                            }
                        }

                        xReader.Close();

                        // Change the data for each Schedule that's being loaded if we've detected that
                        // the XML document is from an older version of the application.
                        if (config.Settings.VersionManager.IsOldAppVersion(config.Settings, AppCodename, AppVersion))
                        {
                            log.WriteDebugMessage("An old version of the schedules.xml file was detected. Attempting upgrade to new schema.");

                            Version v2300         = config.Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, Settings.CODEVERSION_BOOMBAYAH);
                            Version v2319         = config.Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, "2.3.1.9");
                            Version configVersion = config.Settings.VersionManager.Versions.Get(AppCodename, AppVersion);

                            if (v2300 != null && configVersion != null && configVersion.VersionNumber < v2300.VersionNumber)
                            {
                                log.WriteDebugMessage("Dalek 2.2.4.6 or older detected");

                                // This is a new property for Schedule that was introduced in 2.3.0.0
                                // so any version before 2.3.0.0 needs to have it during an upgrade.
                                schedule.Enable = true;
                            }

                            if (v2319 != null && configVersion != null && configVersion.VersionNumber < v2319.VersionNumber)
                            {
                                log.WriteDebugMessage("Boombayah 2.3.1.8 or older detected");

                                // A new property for Schedule introduced in 2.3.1.9
                                schedule.ScreenCaptureInterval = Convert.ToInt32(config.Settings.User.GetByKey("ScreenCaptureInterval", config.Settings.DefaultSettings.ScreenCaptureInterval).Value);
                            }

                            // 2.4 removes "Special Schedule" that was used in previous versions because 2.4 uses an internal special schedule going forward.
                            if (schedule.Name.Equals("Special Schedule"))
                            {
                                schedule.Name = string.Empty;
                            }
                        }

                        if (!string.IsNullOrEmpty(schedule.Name))
                        {
                            Add(schedule);
                        }
                    }

                    if (config.Settings.VersionManager.IsOldAppVersion(config.Settings, AppCodename, AppVersion))
                    {
                        log.WriteDebugMessage("Schedules file detected as an old version");
                        SaveToXmlFile(config.Settings, fileSystem, log);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                if (fileSystem.FileExists(fileSystem.SchedulesFile))
                {
                    fileSystem.DeleteFile(fileSystem.SchedulesFile);

                    log.WriteErrorMessage("The file \"" + fileSystem.SchedulesFile + "\" had to be deleted because an error was encountered. You may need to force quit the application and run it again.");
                }

                log.WriteExceptionMessage("ScheduleCollection::LoadXmlFileAndAddSchedules", ex);

                return(false);
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Loads the image schedules from the schedules.xml file.
        /// </summary>
        public bool LoadXmlFileAndAddSchedules()
        {
            try
            {
                if (FileSystem.FileExists(FileSystem.SchedulesFile))
                {
                    Log.WriteDebugMessage("Schedules file \"" + FileSystem.SchedulesFile + "\" found. Attempting to load XML document");

                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(FileSystem.SchedulesFile);

                    Log.WriteDebugMessage("XML document loaded");

                    AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                    AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                    XmlNodeList xSchedules = xDoc.SelectNodes(SCHEDULE_XPATH);

                    foreach (XmlNode xSchedule in xSchedules)
                    {
                        Schedule      schedule = new Schedule();
                        XmlNodeReader xReader  = new XmlNodeReader(xSchedule);

                        while (xReader.Read())
                        {
                            if (xReader.IsStartElement() && !xReader.IsEmptyElement)
                            {
                                switch (xReader.Name)
                                {
                                case SCHEDULE_NAME:
                                    xReader.Read();
                                    schedule.Name = xReader.Value;
                                    break;

                                case SCHEDULE_ACTIVE:
                                    xReader.Read();
                                    schedule.Active = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_MODE_ONETIME:
                                    xReader.Read();
                                    schedule.ModeOneTime = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_MODE_PERIOD:
                                    xReader.Read();
                                    schedule.ModePeriod = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_CAPTUREAT:
                                    xReader.Read();
                                    schedule.CaptureAt = Convert.ToDateTime(xReader.Value);
                                    break;

                                case SCHEDULE_STARTAT:
                                    xReader.Read();
                                    schedule.StartAt = Convert.ToDateTime(xReader.Value);
                                    break;

                                case SCHEDULE_STOPAT:
                                    xReader.Read();
                                    schedule.StopAt = Convert.ToDateTime(xReader.Value);
                                    break;

                                case SCHEDULE_SCREEN_CAPTURE_INTERVAL:
                                    xReader.Read();
                                    schedule.ScreenCaptureInterval = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCHEDULE_MONDAY:
                                    xReader.Read();
                                    schedule.Monday = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_TUESDAY:
                                    xReader.Read();
                                    schedule.Tuesday = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_WEDNESDAY:
                                    xReader.Read();
                                    schedule.Wednesday = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_THURSDAY:
                                    xReader.Read();
                                    schedule.Thursday = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_FRIDAY:
                                    xReader.Read();
                                    schedule.Friday = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_SATURDAY:
                                    xReader.Read();
                                    schedule.Saturday = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_SUNDAY:
                                    xReader.Read();
                                    schedule.Sunday = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCHEDULE_NOTES:
                                    xReader.Read();
                                    schedule.Notes = xReader.Value;
                                    break;
                                }
                            }
                        }

                        xReader.Close();

                        // Change the data for each Schedule that's being loaded if we've detected that
                        // the XML document is from an older version of the application.
                        if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                        {
                            Log.WriteDebugMessage("An old version of the schedules.xml file was detected. Attempting upgrade to new schema.");

                            Version v2300         = Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, Settings.CODEVERSION_BOOMBAYAH);
                            Version v2319         = Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, "2.3.1.9");
                            Version configVersion = Settings.VersionManager.Versions.Get(AppCodename, AppVersion);

                            if (v2300 != null && configVersion != null && configVersion.VersionNumber < v2300.VersionNumber)
                            {
                                Log.WriteDebugMessage("Dalek 2.2.4.6 or older detected");

                                // This is a new property for Schedule that was introduced in 2.3.0.0
                                // so any version before 2.3.0.0 needs to have it during an upgrade.
                                schedule.Active = true;
                            }

                            if (v2319 != null && configVersion != null && configVersion.VersionNumber < v2319.VersionNumber)
                            {
                                Log.WriteDebugMessage("Boombayah 2.3.1.8 or older detected");

                                // A new property for Schedule introduced in 2.3.1.9
                                schedule.ScreenCaptureInterval = Convert.ToInt32(Settings.User.GetByKey("ScreenCaptureInterval", DefaultSettings.ScreenCaptureInterval).Value);
                            }
                        }

                        if (!string.IsNullOrEmpty(schedule.Name))
                        {
                            Add(schedule);
                        }
                    }

                    if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                    {
                        Log.WriteDebugMessage("Schedules file detected as an old version");
                        SaveToXmlFile();
                    }
                }
                else
                {
                    Log.WriteDebugMessage("WARNING: Unable to load schedules");

                    // If we can't find the schedules.xml file we'll need to have a "Special Schedule" schedule created to be compatible with old commands like -startat and -stopat.
                    Log.WriteDebugMessage("Creating default Special Schedule for use with command line arguments such as -startat and -stopat");

                    DateTime dtNow = DateTime.Now;

                    Schedule specialSchedule = new Schedule()
                    {
                        Name                  = SpecialScheduleName,
                        Active                = false,
                        ModeOneTime           = true,
                        ModePeriod            = false,
                        CaptureAt             = dtNow,
                        StartAt               = dtNow,
                        StopAt                = dtNow,
                        ScreenCaptureInterval = DefaultSettings.ScreenCaptureInterval,
                        Notes                 = "This schedule is used for the command line arguments -captureat, -startat, and -stopat."
                    };

                    if (Settings.VersionManager != null && Settings.VersionManager.OldUserSettings != null)
                    {
                        // If we're importing the schedule settings from a previous version of Auto Screen Capture we'll need to update the "Special Schedule" and enable it.
                        SettingCollection oldUserSettings = Settings.VersionManager.OldUserSettings;

                        bool captureStartAt = Convert.ToBoolean(oldUserSettings.GetByKey("BoolCaptureStartAt", DefaultSettings.BoolCaptureStartAt).Value);
                        bool captureStopAt  = Convert.ToBoolean(oldUserSettings.GetByKey("BoolCaptureStopAt", DefaultSettings.BoolCaptureStopAt).Value);

                        DateTime dtStartAt = Convert.ToDateTime(oldUserSettings.GetByKey("DateTimeCaptureStartAt", DefaultSettings.DateTimeCaptureStartAt).Value);
                        DateTime dtStopAt  = Convert.ToDateTime(oldUserSettings.GetByKey("DateTimeCaptureStopAt", DefaultSettings.DateTimeCaptureStopAt).Value);

                        // Days
                        bool captureOnTheseDays = Convert.ToBoolean(oldUserSettings.GetByKey("BoolCaptureOnTheseDays", DefaultSettings.BoolCaptureOnTheseDays).Value);
                        bool sunday             = Convert.ToBoolean(oldUserSettings.GetByKey("BoolCaptureOnSunday", DefaultSettings.BoolCaptureOnSunday).Value);
                        bool monday             = Convert.ToBoolean(oldUserSettings.GetByKey("BoolCaptureOnMonday", DefaultSettings.BoolCaptureOnMonday).Value);
                        bool tuesday            = Convert.ToBoolean(oldUserSettings.GetByKey("BoolCaptureOnTuesday", DefaultSettings.BoolCaptureOnTuesday).Value);
                        bool wednesday          = Convert.ToBoolean(oldUserSettings.GetByKey("BoolCaptureOnWednesday", DefaultSettings.BoolCaptureOnWednesday).Value);
                        bool thursday           = Convert.ToBoolean(oldUserSettings.GetByKey("BoolCaptureOnThursday", DefaultSettings.BoolCaptureOnThursday).Value);
                        bool friday             = Convert.ToBoolean(oldUserSettings.GetByKey("BoolCaptureOnFriday", DefaultSettings.BoolCaptureOnFriday).Value);
                        bool saturday           = Convert.ToBoolean(oldUserSettings.GetByKey("BoolCaptureOnSaturday", DefaultSettings.BoolCaptureOnSaturday).Value);

                        specialSchedule.ModeOneTime = false;
                        specialSchedule.ModePeriod  = true;

                        if (captureStartAt)
                        {
                            specialSchedule.Active  = true;
                            specialSchedule.StartAt = dtStartAt;
                        }

                        if (captureStopAt)
                        {
                            specialSchedule.Active = true;
                            specialSchedule.StopAt = dtStopAt;
                        }

                        if (captureOnTheseDays)
                        {
                            specialSchedule.Sunday    = sunday;
                            specialSchedule.Monday    = monday;
                            specialSchedule.Tuesday   = tuesday;
                            specialSchedule.Wednesday = wednesday;
                            specialSchedule.Thursday  = thursday;
                            specialSchedule.Friday    = friday;
                            specialSchedule.Saturday  = saturday;
                        }
                    }

                    Add(specialSchedule);

                    SaveToXmlFile();
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.WriteExceptionMessage("ScheduleCollection::LoadXmlFileAndAddSchedules", ex);

                return(false);
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Loads the screens.
        /// </summary>
        public void Load(ImageFormatCollection imageFormatCollection)
        {
            if (File.Exists(FileSystem.ApplicationFolder + FileSystem.ScreensFile))
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(FileSystem.ApplicationFolder + FileSystem.ScreensFile);

                XmlNodeList xScreens = xDoc.SelectNodes(SCREEN_XPATH);

                foreach (XmlNode xScreen in xScreens)
                {
                    Screen        screen  = new Screen();
                    XmlNodeReader xReader = new XmlNodeReader(xScreen);

                    while (xReader.Read())
                    {
                        if (xReader.IsStartElement())
                        {
                            switch (xReader.Name)
                            {
                            case SCREEN_NAME:
                                xReader.Read();
                                screen.Name = xReader.Value;
                                break;

                            case SCREEN_FOLDER:
                                xReader.Read();
                                screen.Folder = xReader.Value;
                                break;

                            case SCREEN_MACRO:
                                xReader.Read();
                                screen.Macro = xReader.Value;
                                break;

                            case SCREEN_COMPONENT:
                                xReader.Read();
                                screen.Component = Convert.ToInt32(xReader.Value);
                                break;

                            case SCREEN_FORMAT:
                                xReader.Read();
                                screen.Format = imageFormatCollection.GetByName(xReader.Value);
                                break;

                            case SCREEN_JPEG_QUALITY:
                                xReader.Read();
                                screen.JpegQuality = Convert.ToInt32(xReader.Value);
                                break;

                            case SCREEN_RESOLUTION_RATIO:
                                xReader.Read();
                                screen.ResolutionRatio = Convert.ToInt32(xReader.Value);
                                break;

                            case SCREEN_MOUSE:
                                xReader.Read();
                                screen.Mouse = Convert.ToBoolean(xReader.Value);
                                break;
                            }
                        }
                    }

                    xReader.Close();

                    if (!string.IsNullOrEmpty(screen.Name))
                    {
                        Add(screen);
                    }
                }
            }
            else
            {
                // Setup some screens based on what we can find.
                for (int screenNumber = 1; screenNumber <= System.Windows.Forms.Screen.AllScreens.Length; screenNumber++)
                {
                    Add(new Screen($"Screen {screenNumber}", FileSystem.ScreenshotsFolder, MacroParser.DefaultMacro, screenNumber,
                                   imageFormatCollection.GetByName(ScreenCapture.DefaultImageFormat), 100, 100, true));
                }

                Save();
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Loads the triggers.
        /// </summary>
        public void Load()
        {
            try
            {
                if (File.Exists(FileSystem.TriggersFile))
                {
                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(FileSystem.TriggersFile);

                    AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                    AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                    XmlNodeList xTriggers = xDoc.SelectNodes(TRIGGER_XPATH);

                    foreach (XmlNode xTrigger in xTriggers)
                    {
                        Trigger       trigger = new Trigger();
                        XmlNodeReader xReader = new XmlNodeReader(xTrigger);

                        while (xReader.Read())
                        {
                            if (xReader.IsStartElement())
                            {
                                switch (xReader.Name)
                                {
                                case TRIGGER_NAME:
                                    xReader.Read();
                                    trigger.Name = xReader.Value;
                                    break;

                                case TRIGGER_CONDITION:
                                    xReader.Read();
                                    trigger.ConditionType =
                                        (TriggerConditionType)Enum.Parse(typeof(TriggerConditionType), xReader.Value);
                                    break;

                                case TRIGGER_ACTION:
                                    xReader.Read();
                                    trigger.ActionType =
                                        (TriggerActionType)Enum.Parse(typeof(TriggerActionType), xReader.Value);
                                    break;

                                case TRIGGER_EDITOR:
                                    xReader.Read();
                                    trigger.Editor = xReader.Value;
                                    break;
                                }
                            }
                        }

                        xReader.Close();

                        if (!string.IsNullOrEmpty(trigger.Name))
                        {
                            Add(trigger);
                        }
                    }

                    if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                    {
                        Save();
                    }
                }
                else
                {
                    Log.Write($"WARNING: {FileSystem.TriggersFile} not found. Creating default triggers");

                    // Setup a few "built in" triggers by default.
                    Add(new Trigger("Application Startup -> Show", TriggerConditionType.ApplicationStartup,
                                    TriggerActionType.ShowInterface, string.Empty));
                    Add(new Trigger("Capture Started -> Hide", TriggerConditionType.ScreenCaptureStarted,
                                    TriggerActionType.HideInterface, string.Empty));
                    Add(new Trigger("Capture Stopped -> Show", TriggerConditionType.ScreenCaptureStopped,
                                    TriggerActionType.ShowInterface, string.Empty));
                    Add(new Trigger("Interface Closing -> Exit", TriggerConditionType.InterfaceClosing,
                                    TriggerActionType.ExitApplication, string.Empty));
                    Add(new Trigger("Limit Reached -> Stop", TriggerConditionType.LimitReached,
                                    TriggerActionType.StopScreenCapture, string.Empty));

                    Save();
                }
            }
            catch (Exception ex)
            {
                Log.Write("TriggerCollection::Load", ex);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Loads the screens.
        /// </summary>
        public bool LoadXmlFileAndAddScreens(ImageFormatCollection imageFormatCollection)
        {
            try
            {
                if (FileSystem.FileExists(FileSystem.ScreensFile))
                {
                    Log.WriteDebugMessage("Screens file \"" + FileSystem.ScreensFile + "\" found. Attempting to load XML document");

                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(FileSystem.ScreensFile);

                    Log.WriteDebugMessage("XML document loaded");

                    AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                    AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                    XmlNodeList xScreens = xDoc.SelectNodes(SCREEN_XPATH);

                    foreach (XmlNode xScreen in xScreens)
                    {
                        Screen        screen  = new Screen();
                        XmlNodeReader xReader = new XmlNodeReader(xScreen);

                        while (xReader.Read())
                        {
                            if (xReader.IsStartElement() && !xReader.IsEmptyElement)
                            {
                                switch (xReader.Name)
                                {
                                case SCREEN_VIEWID:
                                    xReader.Read();
                                    screen.ViewId = Guid.Parse(xReader.Value);
                                    break;

                                case SCREEN_NAME:
                                    xReader.Read();
                                    screen.Name = xReader.Value;
                                    break;

                                case SCREEN_FOLDER:
                                    xReader.Read();
                                    screen.Folder = xReader.Value;
                                    break;

                                case SCREEN_MACRO:
                                    xReader.Read();
                                    screen.Macro = xReader.Value;
                                    break;

                                case SCREEN_COMPONENT:
                                    xReader.Read();
                                    screen.Component = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_FORMAT:
                                    xReader.Read();
                                    screen.Format = imageFormatCollection.GetByName(xReader.Value);
                                    break;

                                case SCREEN_JPEG_QUALITY:
                                    xReader.Read();
                                    screen.JpegQuality = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_RESOLUTION_RATIO:
                                    xReader.Read();
                                    screen.ResolutionRatio = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_MOUSE:
                                    xReader.Read();
                                    screen.Mouse = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCREEN_ACTIVE:
                                    xReader.Read();
                                    screen.Active = Convert.ToBoolean(xReader.Value);
                                    break;
                                }
                            }
                        }

                        xReader.Close();

                        // Change the data for each Screen that's being loaded if we've detected that
                        // the XML document is from an older version of the application.
                        if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                        {
                            Log.WriteDebugMessage("An old version of the screens.xml file was detected. Attempting upgrade to new schema.");

                            Version v2300         = Settings.VersionManager.Versions.Get("Boombayah", "2.3.0.0");
                            Version configVersion = Settings.VersionManager.Versions.Get(AppCodename, AppVersion);

                            if (v2300 != null && configVersion != null && configVersion.VersionNumber < v2300.VersionNumber)
                            {
                                Log.WriteDebugMessage("Dalek 2.2.4.6 or older detected");

                                // This is a new property for Screen that was introduced in 2.3.0.0
                                // so any version before 2.3.0.0 needs to have it during an upgrade.
                                screen.Active = true;
                            }
                        }

                        if (!string.IsNullOrEmpty(screen.Name))
                        {
                            Add(screen);
                        }
                    }

                    if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                    {
                        Log.WriteDebugMessage("Screens file detected as an old version");
                        SaveToXmlFile();
                    }
                }
                else
                {
                    Log.WriteDebugMessage("WARNING: Unable to load screens");

                    // Setup some screens based on what we can find.
                    for (int screenNumber = 1; screenNumber <= System.Windows.Forms.Screen.AllScreens.Length; screenNumber++)
                    {
                        Screen screen = new Screen()
                        {
                            Name            = $"Screen {screenNumber}",
                            Folder          = FileSystem.ScreenshotsFolder,
                            Macro           = MacroParser.DefaultMacro,
                            Component       = screenNumber,
                            Format          = imageFormatCollection.GetByName(ScreenCapture.DefaultImageFormat),
                            JpegQuality     = 100,
                            ResolutionRatio = 100,
                            Mouse           = true,
                            Active          = true
                        };

                        Add(screen);

                        Log.WriteDebugMessage($"Screen {screenNumber} created using \"{FileSystem.ScreenshotsFolder}\" for folder path and \"{MacroParser.DefaultMacro}\" for macro.");
                    }

                    SaveToXmlFile();
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.WriteExceptionMessage("ScreenCollection::LoadXmlFileAndAddScreens", ex);

                return(false);
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Loads the image editors from the editors.xml file.
        /// </summary>
        public bool LoadXmlFileAndAddEditors()
        {
            try
            {
                if (FileSystem.FileExists(FileSystem.EditorsFile))
                {
                    Log.WriteDebugMessage("Editors file \"" + FileSystem.EditorsFile + "\" found. Attempting to load XML document");

                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(FileSystem.EditorsFile);

                    Log.WriteDebugMessage("XML document loaded");

                    AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                    AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                    XmlNodeList xEditors = xDoc.SelectNodes(EDITOR_XPATH);

                    foreach (XmlNode xEditor in xEditors)
                    {
                        Editor        editor  = new Editor();
                        XmlNodeReader xReader = new XmlNodeReader(xEditor);

                        while (xReader.Read())
                        {
                            if (xReader.IsStartElement() && !xReader.IsEmptyElement)
                            {
                                switch (xReader.Name)
                                {
                                case EDITOR_NAME:
                                    xReader.Read();
                                    editor.Name = xReader.Value;
                                    break;

                                case EDITOR_APPLICATION:
                                    xReader.Read();
                                    editor.Application = xReader.Value;
                                    break;

                                case EDITOR_ARGUMENTS:
                                    xReader.Read();

                                    string value = xReader.Value;

                                    // Change the data for each Tag that's being loaded if we've detected that
                                    // the XML document is from an older version of the application.
                                    if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                                    {
                                        Log.WriteDebugMessage("An old version of the editors.xml file was detected. Attempting upgrade to new schema.");

                                        Version v2300         = Settings.VersionManager.Versions.Get("Boombayah", "2.3.0.0");
                                        Version configVersion = Settings.VersionManager.Versions.Get(AppCodename, AppVersion);

                                        if (v2300 != null && configVersion != null && configVersion.VersionNumber < v2300.VersionNumber)
                                        {
                                            Log.WriteDebugMessage("Dalek 2.2.4.6 or older detected");

                                            // Starting with 2.3.0.0 the %screenshot% argument tag became the %filepath% argument tag.
                                            value = value.Replace("%screenshot%", "%filepath%");

                                            // Set this editor as the default editor. Version 2.3 requires at least one editor to be the default editor.
                                            Settings.User.SetValueByKey("StringDefaultEditor", editor.Name);
                                        }
                                    }

                                    editor.Arguments = value;
                                    break;

                                case EDITOR_NOTES:
                                    xReader.Read();
                                    editor.Notes = xReader.Value;
                                    break;
                                }
                            }
                        }

                        xReader.Close();

                        if (!string.IsNullOrEmpty(editor.Name) &&
                            !string.IsNullOrEmpty(editor.Application))
                        {
                            Add(editor);
                        }
                    }

                    if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                    {
                        Log.WriteDebugMessage("Editors file detected as an old version");
                        SaveToXmlFile();
                    }
                }
                else
                {
                    Log.WriteDebugMessage("WARNING: Unable to load editors");

                    // Setup default image editors.
                    // This is going to get maintenance heavy. I just know it.

                    // Microsoft Paint
                    if (FileSystem.FileExists(@"C:\Windows\System32\mspaint.exe"))
                    {
                        Add(new Editor("Microsoft Paint", @"C:\Windows\System32\mspaint.exe", "%filepath%"));

                        // We'll make Microsoft Paint the default image editor because usually everyone has it already.
                        Settings.User.SetValueByKey("StringDefaultEditor", "Microsoft Paint");
                    }

                    // Snagit Editor
                    if (FileSystem.FileExists(@"C:\Program Files\TechSmith\Snagit 2020\SnagitEditor.exe"))
                    {
                        Add(new Editor("Snagit Editor", @"C:\Program Files\TechSmith\Snagit 2020\SnagitEditor.exe", "%filepath%"));

                        // If the user has Snagit installed then make the Snagit Editor the default editor.
                        Settings.User.SetValueByKey("StringDefaultEditor", "Snagit Editor");
                    }

                    // Microsoft Outlook
                    if (FileSystem.FileExists(@"C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE"))
                    {
                        Add(new Editor("Microsoft Outlook", @"C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE", "/c ipm.note /a %filepath%"));
                    }

                    // Chrome
                    if (FileSystem.FileExists(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"))
                    {
                        Add(new Editor("Chrome", @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "%filepath%"));
                    }

                    // Firefox
                    if (FileSystem.FileExists(@"C:\Program Files\Mozilla Firefox\firefox.exe"))
                    {
                        Add(new Editor("Firefox", @"C:\Program Files\Mozilla Firefox\firefox.exe", "%filepath%"));
                    }

                    // GIMP
                    // We assume GIMP will be in the default location available for all users on 64-bit systems.
                    if (FileSystem.FileExists(@"C:\Program Files\GIMP 2\bin\gimp-2.10.exe"))
                    {
                        Add(new Editor("GIMP", @"C:\Program Files\GIMP 2\bin\gimp-2.10.exe", "%filepath%"));
                    }

                    // Glimpse
                    if (FileSystem.FileExists(@"C:\Program Files (x86)\Glimpse Image Editor\Glimpse 0.1.2\bin\Glimpse.exe"))
                    {
                        Add(new Editor("Glimpse", @"C:\Program Files (x86)\Glimpse Image Editor\Glimpse 0.1.2\bin\Glimpse.exe", "%filepath%"));
                    }

                    // Clip Studio Paint
                    if (FileSystem.FileExists(@"C:\Program Files\CELSYS\CLIP STUDIO 1.5\CLIP STUDIO PAINT\CLIPStudioPaint.exe"))
                    {
                        Add(new Editor("Clip Studio Paint", @"C:\Program Files\CELSYS\CLIP STUDIO 1.5\CLIP STUDIO PAINT\CLIPStudioPaint.exe", "%filepath%"));
                    }

                    SaveToXmlFile();
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.WriteExceptionMessage("EditorCollection::LoadXmlFileAndAddEditors", ex);

                return(false);
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Loads the screenshots.
        /// </summary>
        public void Load(ImageFormatCollection imageFormatCollection, ScreenCollection screenCollection, RegionCollection regionCollection)
        {
            try
            {
                _mutexWriteFile.WaitOne();

                Log.Write("Loading screenshots from screenshots.xml");

                Stopwatch stopwatch = new Stopwatch();

                stopwatch.Start();

                if (_screenshotList == null)
                {
                    _screenshotList = new List <Screenshot>();
                    Log.Write("Initialized screenshot list");
                }

                if (_slideList == null)
                {
                    _slideList = new List <Slide>();
                    Log.Write("Initialized slide list");
                }

                if (_slideNameList == null)
                {
                    _slideNameList = new List <string>();
                    Log.Write("Initialized slide name list");
                }

                if (_screenshotList != null && Directory.Exists(FileSystem.ApplicationFolder) && !File.Exists(FileSystem.ApplicationFolder + FileSystem.ScreenshotsFile))
                {
                    Log.Write("Could not find \"" + FileSystem.ApplicationFolder + FileSystem.ScreenshotsFile + "\" so creating it");

                    XmlWriterSettings xSettings = new XmlWriterSettings
                    {
                        Indent           = true,
                        CloseOutput      = true,
                        CheckCharacters  = true,
                        Encoding         = Encoding.UTF8,
                        NewLineChars     = Environment.NewLine,
                        IndentChars      = XML_FILE_INDENT_CHARS,
                        NewLineHandling  = NewLineHandling.Entitize,
                        ConformanceLevel = ConformanceLevel.Document
                    };

                    using (XmlWriter xWriter = XmlWriter.Create(FileSystem.ApplicationFolder + FileSystem.ScreenshotsFile, xSettings))
                    {
                        xWriter.WriteStartDocument();
                        xWriter.WriteStartElement(XML_FILE_ROOT_NODE);
                        xWriter.WriteAttributeString("app", "version", XML_FILE_ROOT_NODE, Settings.ApplicationVersion);
                        xWriter.WriteAttributeString("app", "codename", XML_FILE_ROOT_NODE, Settings.ApplicationCodename);
                        xWriter.WriteStartElement(XML_FILE_SCREENSHOTS_NODE);

                        xWriter.WriteEndElement();
                        xWriter.WriteEndElement();
                        xWriter.WriteEndDocument();

                        xWriter.Flush();
                        xWriter.Close();
                    }

                    Log.Write("Created \"" + FileSystem.ApplicationFolder + FileSystem.ScreenshotsFile + "\"");
                }

                if (_screenshotList != null && Directory.Exists(FileSystem.ApplicationFolder) && File.Exists(FileSystem.ApplicationFolder + FileSystem.ScreenshotsFile))
                {
                    xDoc = new XmlDocument();

                    lock (xDoc)
                    {
                        xDoc.Load(FileSystem.ApplicationFolder + FileSystem.ScreenshotsFile);

                        AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                        AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                        Log.Write("Getting screenshots from screenshots.xml using XPath query \"" + SCREENSHOT_XPATH + "\"");

                        XmlNodeList xScreeshots = xDoc.SelectNodes(SCREENSHOT_XPATH);

                        if (xScreeshots != null)
                        {
                            Log.Write("Loading each screenshot from screenshots.xml");

                            foreach (XmlNode xScreenshot in xScreeshots)
                            {
                                Screenshot screenshot = new Screenshot();
                                screenshot.Slide = new Slide();

                                XmlNodeReader xReader = new XmlNodeReader(xScreenshot);

                                while (xReader.Read())
                                {
                                    if (xReader.IsStartElement())
                                    {
                                        switch (xReader.Name)
                                        {
                                        case SCREENSHOT_VIEWID:
                                            xReader.Read();
                                            screenshot.ViewId = Guid.Parse(xReader.Value);
                                            break;

                                        case SCREENSHOT_DATE:
                                            xReader.Read();
                                            screenshot.Date       = xReader.Value;
                                            screenshot.Slide.Date = xReader.Value;
                                            break;

                                        case SCREENSHOT_TIME:
                                            xReader.Read();
                                            screenshot.Time = xReader.Value;
                                            break;

                                        case SCREENSHOT_PATH:
                                            xReader.Read();
                                            screenshot.Path = xReader.Value;
                                            break;

                                        case SCREENSHOT_FORMAT:
                                            xReader.Read();
                                            screenshot.Format = imageFormatCollection.GetByName(xReader.Value);
                                            break;

                                        // 2.1 used "screen" for its definition of each display/monitor whereas 2.2 uses "component".
                                        // Active Window is now represented by 0 rather than 5.
                                        case SCREENSHOT_SCREEN:
                                            if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion) &&
                                                Settings.VersionManager.Versions.Get("Clara", "2.1.8.2") != null && string.IsNullOrEmpty(AppCodename) && string.IsNullOrEmpty(AppVersion))
                                            {
                                                xReader.Read();

                                                screenshot.Screen = Convert.ToInt32(xReader.Value);

                                                screenshot.Component = screenshot.Screen == 5 ? 0 : screenshot.Screen;
                                            }

                                            break;

                                        // We still want to support "component" since this was introduced in version 2.2 as the new representation for "screen".
                                        case SCREENSHOT_COMPONENT:
                                            xReader.Read();
                                            screenshot.Component = Convert.ToInt32(xReader.Value);

                                            if (screenshot.Component == -1)
                                            {
                                                screenshot.ScreenshotType = ScreenshotType.Region;
                                            }
                                            else if (screenshot.Component == 0)
                                            {
                                                screenshot.ScreenshotType = ScreenshotType.ActiveWindow;
                                            }
                                            else
                                            {
                                                screenshot.ScreenshotType = ScreenshotType.Screen;
                                            }

                                            break;

                                        case SCREENSHOT_SLIDENAME:
                                            xReader.Read();
                                            screenshot.Slide.Name = xReader.Value;
                                            break;

                                        case SCREENSHOT_SLIDEVALUE:
                                            xReader.Read();
                                            screenshot.Slide.Value = xReader.Value;
                                            break;

                                        case SCREENSHOT_WINDOW_TITLE:
                                            xReader.Read();
                                            screenshot.WindowTitle = xReader.Value;
                                            break;

                                        case SCREENSHOT_PROCESS_NAME:
                                            xReader.Read();
                                            screenshot.ProcessName = xReader.Value;
                                            break;

                                        case SCREENSHOT_LABEL:
                                            xReader.Read();
                                            screenshot.Label = xReader.Value;
                                            break;
                                        }
                                    }
                                }

                                xReader.Close();

                                if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                                {
                                    if (Settings.VersionManager.Versions.Get("Clara", "2.1.8.2") != null && string.IsNullOrEmpty(AppCodename) && string.IsNullOrEmpty(AppVersion))
                                    {
                                        // We need to associate the screenshot's view ID with the component's view ID
                                        // because this special ID value is used for figuring out what screenshot image to display.
                                        screenshot.ViewId = screenCollection.GetByComponent(screenshot.Component).ViewId;

                                        string windowTitle = "*Screenshot imported from an old version of Auto Screen Capture*";

                                        Regex rgxOldSlidename = new Regex(@"^(?<Date>\d{4}-\d{2}-\d{2}) (?<Time>(?<Hour>\d{2})-(?<Minute>\d{2})-(?<Second>\d{2})-(?<Millisecond>\d{3}))");

                                        string hour        = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Hour"].Value;
                                        string minute      = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Minute"].Value;
                                        string second      = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Second"].Value;
                                        string millisecond = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Millisecond"].Value;

                                        screenshot.Date = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Date"].Value;
                                        screenshot.Time = hour + ":" + minute + ":" + second + "." + millisecond;

                                        screenshot.Slide.Name  = "{date=" + screenshot.Date + "}{time=" + screenshot.Time + "}";
                                        screenshot.Slide.Value = screenshot.Time + " [" + windowTitle + "]";

                                        screenshot.WindowTitle = windowTitle;
                                    }

                                    // Remove all the existing XML child nodes from the old XML screenshot.
                                    xScreenshot.RemoveAll();

                                    // Prepare the new XML child nodes for the old XML screenshot ...

                                    XmlElement xViewId = xDoc.CreateElement(SCREENSHOT_VIEWID);
                                    xViewId.InnerText = screenshot.ViewId.ToString();

                                    XmlElement xDate = xDoc.CreateElement(SCREENSHOT_DATE);
                                    xDate.InnerText = screenshot.Date;

                                    XmlElement xTime = xDoc.CreateElement(SCREENSHOT_TIME);
                                    xTime.InnerText = screenshot.Time;

                                    XmlElement xPath = xDoc.CreateElement(SCREENSHOT_PATH);
                                    xPath.InnerText = screenshot.Path;

                                    XmlElement xFormat = xDoc.CreateElement(SCREENSHOT_FORMAT);
                                    xFormat.InnerText = screenshot.Format.Name;

                                    XmlElement xComponent = xDoc.CreateElement(SCREENSHOT_COMPONENT);
                                    xComponent.InnerText = screenshot.Component.ToString();

                                    XmlElement xSlidename = xDoc.CreateElement(SCREENSHOT_SLIDENAME);
                                    xSlidename.InnerText = screenshot.Slide.Name;

                                    XmlElement xSlidevalue = xDoc.CreateElement(SCREENSHOT_SLIDEVALUE);
                                    xSlidevalue.InnerText = screenshot.Slide.Value;

                                    XmlElement xWindowTitle = xDoc.CreateElement(SCREENSHOT_WINDOW_TITLE);
                                    xWindowTitle.InnerText = screenshot.WindowTitle;

                                    XmlElement xProcessName = xDoc.CreateElement(SCREENSHOT_PROCESS_NAME);
                                    xProcessName.InnerText = screenshot.ProcessName;

                                    XmlElement xLabel = xDoc.CreateElement(SCREENSHOT_LABEL);
                                    xLabel.InnerText = screenshot.Label;

                                    // Create the new XML child nodes for the old XML screenshot so that it's now in the format of the new XML screenshot.
                                    xScreenshot.AppendChild(xViewId);
                                    xScreenshot.AppendChild(xDate);
                                    xScreenshot.AppendChild(xTime);
                                    xScreenshot.AppendChild(xPath);
                                    xScreenshot.AppendChild(xFormat);
                                    xScreenshot.AppendChild(xComponent);
                                    xScreenshot.AppendChild(xSlidename);
                                    xScreenshot.AppendChild(xSlidevalue);
                                    xScreenshot.AppendChild(xWindowTitle);
                                    xScreenshot.AppendChild(xProcessName);
                                    xScreenshot.AppendChild(xLabel);
                                }

                                if (!string.IsNullOrEmpty(screenshot.Date) &&
                                    !string.IsNullOrEmpty(screenshot.Time) &&
                                    !string.IsNullOrEmpty(screenshot.Path) &&
                                    screenshot.Format != null &&
                                    !string.IsNullOrEmpty(screenshot.Slide.Name) &&
                                    !string.IsNullOrEmpty(screenshot.Slide.Value) &&
                                    !string.IsNullOrEmpty(screenshot.WindowTitle))
                                {
                                    screenshot.Saved = true;
                                    Add(screenshot);
                                }
                            }
                        }
                        else
                        {
                            Log.Write("WARNING: Unable to load screenshots from screenshots.xml");
                        }

                        if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                        {
                            Log.Write("Old application version discovered when loading screenshots.xml");

                            // We'll have to create the app:version and app:codename attributes for screenshots.xml if we're upgrading from "Clara".
                            if (Settings.VersionManager.Versions.Get("Clara", "2.1.8.2") != null && string.IsNullOrEmpty(AppCodename) && string.IsNullOrEmpty(AppVersion))
                            {
                                XmlAttribute attributeVersion  = xDoc.CreateAttribute("app", "version", "autoscreen");
                                XmlAttribute attributeCodename = xDoc.CreateAttribute("app", "codename", "autoscreen");

                                attributeVersion.Value  = Settings.ApplicationVersion;
                                attributeCodename.Value = Settings.ApplicationCodename;

                                xDoc.SelectSingleNode("/" + XML_FILE_ROOT_NODE).Attributes.Append(attributeVersion);
                                xDoc.SelectSingleNode("/" + XML_FILE_ROOT_NODE).Attributes.Append(attributeCodename);
                            }

                            // Apply the latest version and codename if the version of Auto Screen Capture is older than this version.
                            xDoc.SelectSingleNode("/" + XML_FILE_ROOT_NODE).Attributes["app:version"].Value  = Settings.ApplicationVersion;
                            xDoc.SelectSingleNode("/" + XML_FILE_ROOT_NODE).Attributes["app:codename"].Value = Settings.ApplicationCodename;

                            xDoc.Save(FileSystem.ApplicationFolder + FileSystem.ScreenshotsFile);

                            Log.Write("Upgraded screenshots.xml");
                        }
                    }
                }

                stopwatch.Stop();

                Log.Write("It took " + stopwatch.ElapsedMilliseconds + " milliseconds to load " + _screenshotList.Count + " screenshots");
            }
            catch (Exception ex)
            {
                Log.Write("ScreenshotCollection::Load", ex);
            }
            finally
            {
                _mutexWriteFile.ReleaseMutex();
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Loads the tags.
        /// </summary>
        public bool LoadXmlFileAndAddTags()
        {
            try
            {
                if (FileSystem.FileExists(FileSystem.TagsFile))
                {
                    Log.WriteDebugMessage("Tags file \"" + FileSystem.TagsFile + "\" found. Attempting to load XML document");

                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(FileSystem.TagsFile);

                    Log.WriteDebugMessage("XML document loaded");

                    AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                    AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                    XmlNodeList xTags = xDoc.SelectNodes(TAG_XPATH);

                    bool eveningExtendsToNextMorning = false;

                    foreach (XmlNode xTag in xTags)
                    {
                        MacroTag      tag     = new MacroTag();
                        XmlNodeReader xReader = new XmlNodeReader(xTag);

                        while (xReader.Read())
                        {
                            if (xReader.IsStartElement() && !xReader.IsEmptyElement)
                            {
                                switch (xReader.Name)
                                {
                                case TAG_NAME:
                                    xReader.Read();
                                    tag.Name = xReader.Value;

                                    if (!tag.Name.StartsWith("%"))
                                    {
                                        tag.Name = "%" + tag.Name;
                                    }

                                    if (!tag.Name.EndsWith("%"))
                                    {
                                        tag.Name += "%";
                                    }

                                    break;

                                case TAG_DESCRIPTION:
                                    xReader.Read();
                                    tag.Description = xReader.Value;
                                    break;

                                case TAG_NOTES:
                                    xReader.Read();
                                    tag.Notes = xReader.Value;
                                    break;

                                case TAG_TYPE:
                                    xReader.Read();

                                    string value = xReader.Value;

                                    // Change the data for each Tag that's being loaded if we've detected that
                                    // the XML document is from an older version of the application.
                                    if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                                    {
                                        Log.WriteDebugMessage("An old version of the tags.xml file was detected. Attempting upgrade to new schema.");

                                        Version v2300         = Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, Settings.CODEVERSION_BOOMBAYAH);
                                        Version v2326         = Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, "2.3.2.6");
                                        Version configVersion = Settings.VersionManager.Versions.Get(AppCodename, AppVersion);

                                        if (v2300 != null && configVersion != null && configVersion.VersionNumber < v2300.VersionNumber)
                                        {
                                            Log.WriteDebugMessage("Dalek 2.2.4.6 or older detected");

                                            // Starting with 2.3.0.0 the DateTimeFormatFunction type became the DateTimeFormatExpression type.
                                            value = value.Replace("DateTimeFormatFunction", "DateTimeFormatExpression");
                                        }

                                        if (v2326 != null && configVersion != null && configVersion.VersionNumber < v2326.VersionNumber)
                                        {
                                            Log.WriteDebugMessage("Boombayah 2.3.2.5 or older detected");

                                            // Starting with 2.3.2.6 the TimeOfDay type became the TimeRange type.
                                            value = value.Replace("TimeOfDay", "TimeRange");
                                        }
                                    }

                                    tag.Type = (MacroTagType)Enum.Parse(typeof(MacroTagType), value);
                                    break;

                                case TAG_DATETIME_FORMAT_VALUE:
                                    xReader.Read();
                                    tag.DateTimeFormatValue = xReader.Value;
                                    break;

                                case TAG_TIMERANGE_MACRO1_START:
                                case TAG_TIME_OF_DAY_MORNING_START:
                                    xReader.Read();
                                    tag.TimeRangeMacro1Start = Convert.ToDateTime(xReader.Value);
                                    break;

                                case TAG_TIMERANGE_MACRO1_END:
                                case TAG_TIME_OF_DAY_MORNING_END:
                                    xReader.Read();
                                    tag.TimeRangeMacro1End = Convert.ToDateTime(xReader.Value);
                                    break;

                                case TAG_TIMERANGE_MACRO2_START:
                                case TAG_TIME_OF_DAY_AFTERNOON_START:
                                    xReader.Read();
                                    tag.TimeRangeMacro2Start = Convert.ToDateTime(xReader.Value);
                                    break;

                                case TAG_TIMERANGE_MACRO2_END:
                                case TAG_TIME_OF_DAY_AFTERNOON_END:
                                    xReader.Read();
                                    tag.TimeRangeMacro2End = Convert.ToDateTime(xReader.Value);
                                    break;

                                case TAG_TIMERANGE_MACRO3_START:
                                case TAG_TIME_OF_DAY_EVENING_START:
                                    xReader.Read();
                                    tag.TimeRangeMacro3Start = Convert.ToDateTime(xReader.Value);
                                    break;

                                case TAG_TIMERANGE_MACRO3_END:
                                case TAG_TIME_OF_DAY_EVENING_END:
                                    xReader.Read();
                                    tag.TimeRangeMacro3End = Convert.ToDateTime(xReader.Value);
                                    break;

                                case TAG_TIMERANGE_MACRO4_START:
                                    xReader.Read();
                                    tag.TimeRangeMacro4Start = Convert.ToDateTime(xReader.Value);
                                    break;

                                case TAG_TIMERANGE_MACRO4_END:
                                    xReader.Read();
                                    tag.TimeRangeMacro4End = Convert.ToDateTime(xReader.Value);
                                    break;

                                case TAG_TIMERANGE_MACRO1_MACRO:
                                case TAG_TIME_OF_DAY_MORNING_VALUE:
                                    xReader.Read();
                                    tag.TimeRangeMacro1Macro = xReader.Value;
                                    break;

                                case TAG_TIMERANGE_MACRO2_MACRO:
                                case TAG_TIME_OF_DAY_AFTERNOON_VALUE:
                                    xReader.Read();
                                    tag.TimeRangeMacro2Macro = xReader.Value;
                                    break;

                                case TAG_TIMERANGE_MACRO3_MACRO:
                                case TAG_TIME_OF_DAY_EVENING_VALUE:
                                    xReader.Read();
                                    tag.TimeRangeMacro3Macro = xReader.Value;
                                    break;

                                case TAG_TIMERANGE_MACRO4_MACRO:
                                    xReader.Read();
                                    tag.TimeRangeMacro4Macro = xReader.Value;
                                    break;

                                case TAG_TIME_OF_DAY_EVENING_EXTENDS_TO_NEXT_MORNING:
                                    xReader.Read();
                                    eveningExtendsToNextMorning = Convert.ToBoolean(xReader.Value);
                                    break;

                                case TAG_ACTIVE:
                                    xReader.Read();
                                    tag.Active = Convert.ToBoolean(xReader.Value);
                                    break;
                                }
                            }
                        }

                        xReader.Close();

                        // Change the data for each Tag that's being loaded if we've detected that
                        // the XML document is from an older version of the application.
                        if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                        {
                            Log.WriteDebugMessage("An old version of the tags.xml file was detected. Attempting upgrade to new schema.");

                            Version v2300         = Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, Settings.CODEVERSION_BOOMBAYAH);
                            Version v2326         = Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, "2.3.2.6");
                            Version configVersion = Settings.VersionManager.Versions.Get(AppCodename, AppVersion);

                            if (v2300 != null && configVersion != null && configVersion.VersionNumber < v2300.VersionNumber)
                            {
                                Log.WriteDebugMessage("Dalek 2.2.4.6 or older detected");

                                // This is a new property for Tag that was introduced in 2.3.0.0
                                // so any version before 2.3.0.0 needs to have it during an upgrade.
                                tag.Active = true;

                                // "Description" is a new property for Tag that was introduced in 2.3.0.0
                                switch (tag.Type)
                                {
                                case MacroTagType.ActiveWindowTitle:
                                    tag.Description = "The title of the active window";
                                    break;

                                case MacroTagType.DateTimeFormat:
                                    tag.Description = "A value representing either a date, a time, or a combination of the date and time (" + tag.Name + ")";
                                    break;

                                case MacroTagType.ImageFormat:
                                    tag.Description = "The image format of the screenshot (such as jpeg or png)";
                                    break;

                                case MacroTagType.ScreenCaptureCycleCount:
                                    tag.Description = "The number of capture cycles during a screen capture session";
                                    break;

                                case MacroTagType.ScreenName:
                                    tag.Description = "The name of the screen or region";
                                    break;

                                case MacroTagType.ScreenNumber:
                                    tag.Description = "The screen number. For example, the first display is screen number 1";
                                    break;

                                case MacroTagType.User:
                                    tag.Description = "The name of the user (" + tag.Name + ")";
                                    break;

                                case MacroTagType.Machine:
                                    tag.Description = "The name of the computer (" + tag.Name + ")";
                                    break;

                                case MacroTagType.TimeRange:
                                    tag.Description = "The macro to use for a specific time range";
                                    break;

                                case MacroTagType.DateTimeFormatExpression:
                                    tag.Description = "An expression which represents a time that is either ahead or behind the current time (" + tag.Name + ")";
                                    break;
                                }
                            }

                            if (v2326 != null && configVersion != null && configVersion.VersionNumber < v2326.VersionNumber)
                            {
                                tag.TimeRangeMacro4Start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
                                tag.TimeRangeMacro4End   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
                                tag.TimeRangeMacro4Macro = string.Empty;

                                // This is an old property from before 2.3.2.6 when TimeOfDay macro tags were used.
                                // Since 2.3.2.6 we now use TimeRange tags so we need to split up the "evening" start and end times
                                // into their own "Macro 4" start and end times when this property is set to true.
                                if (eveningExtendsToNextMorning)
                                {
                                    tag.TimeRangeMacro4Start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
                                    tag.TimeRangeMacro4End   = tag.TimeRangeMacro3End;

                                    tag.TimeRangeMacro3End = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59);

                                    tag.TimeRangeMacro4Macro = tag.TimeRangeMacro3Macro;
                                }
                            }
                        }

                        if (!string.IsNullOrEmpty(tag.Name))
                        {
                            Add(tag);
                        }
                    }

                    if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                    {
                        Log.WriteDebugMessage("Tags file detected as an old version");
                        SaveToXmlFile();
                    }
                }
                else
                {
                    Log.WriteDebugMessage("WARNING: Unable to load tags");

                    // Setup a few "built in" tags by default.
                    Add(new MacroTag("name", "The name of the screen or region", MacroTagType.ScreenName, active: true));
                    Add(new MacroTag("screen", "The screen number. For example, the first display is screen 1 and the second display is screen 2", MacroTagType.ScreenNumber, active: true));
                    Add(new MacroTag("format", "The image format such as jpeg or png", MacroTagType.ImageFormat, active: true));
                    Add(new MacroTag("date", "The current date (%date%)", MacroTagType.DateTimeFormat, MacroParser.DateFormat, active: true));
                    Add(new MacroTag("time", "The current time (%time%)", MacroTagType.DateTimeFormat, MacroParser.TimeFormatForWindows, active: true));
                    Add(new MacroTag("year", "The current year (%year%)", MacroTagType.DateTimeFormat, MacroParser.YearFormat, active: true));
                    Add(new MacroTag("month", "The current month (%month%)", MacroTagType.DateTimeFormat, MacroParser.MonthFormat, active: true));
                    Add(new MacroTag("day", "The current day (%day%)", MacroTagType.DateTimeFormat, MacroParser.DayFormat, active: true));
                    Add(new MacroTag("hour", "The current hour (%hour%)", MacroTagType.DateTimeFormat, MacroParser.HourFormat, active: true));
                    Add(new MacroTag("minute", "The current minute (%minute%)", MacroTagType.DateTimeFormat, MacroParser.MinuteFormat, active: true));
                    Add(new MacroTag("second", "The current second (%second%)", MacroTagType.DateTimeFormat, MacroParser.SecondFormat, active: true));
                    Add(new MacroTag("millisecond", "The current millisecond (%millisecond%)", MacroTagType.DateTimeFormat, MacroParser.MillisecondFormat, active: true));
                    Add(new MacroTag("lastyear", "The previous year (%lastyear%)", MacroTagType.DateTimeFormatExpression, "{year-1}", active: true));
                    Add(new MacroTag("lastmonth", "The previous month (%lastmonth%)", MacroTagType.DateTimeFormatExpression, "{month-1}", active: true));
                    Add(new MacroTag("yesterday", "The previous day (%yesterday%)", MacroTagType.DateTimeFormatExpression, "{day-1}[yyyy-MM-dd]", active: true));
                    Add(new MacroTag("tomorrow", "The next day (%tomorrow%)", MacroTagType.DateTimeFormatExpression, "{day+1}[yyyy-MM-dd]", active: true));
                    Add(new MacroTag("6hoursbehind", "Six hours behind the current hour (%6hoursbehind%)", MacroTagType.DateTimeFormatExpression, "{hour-6}[yyyy-MM-dd_HH-mm-ss.fff]", active: true));
                    Add(new MacroTag("6hoursahead", "Six hours ahead the current hour (%6hoursahead%)", MacroTagType.DateTimeFormatExpression, "{hour+6}[yyyy-MM-dd_HH-mm-ss.fff]", active: true));
                    Add(new MacroTag("count", "The number of capture cycles during a running screen capture session. For example, the first round of screenshots taken is the first cycle count or count 1", MacroTagType.ScreenCaptureCycleCount, active: true));
                    Add(new MacroTag("user", "The user using this computer (%user%)", MacroTagType.User, active: true));
                    Add(new MacroTag("machine", "The name of the computer (%machine%)", MacroTagType.Machine, active: true));
                    Add(new MacroTag("title", "The title of the active window", MacroTagType.ActiveWindowTitle, active: true));
                    Add(new MacroTag("timerange", "The macro to use during a specific time range. At the moment it is %timerange%", MacroTagType.TimeRange, active: true));
                    Add(new MacroTag("quarteryear", "A number representing the current quarter of the current year (%quarteryear%)", MacroTagType.QuarterYear, active: true));

                    SaveToXmlFile();
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.WriteExceptionMessage("TagCollection::LoadXmlFileAndAddTags", ex);

                return(false);
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Loads the regions.
        /// </summary>
        public void LoadXmlFileAndAddRegions(ImageFormatCollection imageFormatCollection)
        {
            try
            {
                Log.WriteDebugMessage(":: LoadXmlFileAndAddRegions Start ::");

                if (FileSystem.FileExists(FileSystem.RegionsFile))
                {
                    Log.WriteDebugMessage("Regions file \"" + FileSystem.RegionsFile + "\" found. Attempting to load XML document");

                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(FileSystem.RegionsFile);

                    Log.WriteDebugMessage("XML document loaded");

                    AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                    AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                    XmlNodeList xRegions = xDoc.SelectNodes(REGION_XPATH);

                    foreach (XmlNode xRegion in xRegions)
                    {
                        Region        region  = new Region();
                        XmlNodeReader xReader = new XmlNodeReader(xRegion);

                        while (xReader.Read())
                        {
                            if (xReader.IsStartElement() && !xReader.IsEmptyElement)
                            {
                                switch (xReader.Name)
                                {
                                case REGION_VIEWID:
                                    xReader.Read();
                                    region.ViewId = Guid.Parse(xReader.Value);
                                    break;

                                case REGION_NAME:
                                    xReader.Read();
                                    region.Name = xReader.Value;
                                    break;

                                case REGION_FOLDER:
                                    xReader.Read();
                                    region.Folder = xReader.Value;
                                    break;

                                case REGION_MACRO:
                                    xReader.Read();
                                    region.Macro = xReader.Value;
                                    break;

                                case REGION_FORMAT:
                                    xReader.Read();
                                    region.Format = imageFormatCollection.GetByName(xReader.Value);
                                    break;

                                case REGION_JPEG_QUALITY:
                                    xReader.Read();
                                    region.JpegQuality = Convert.ToInt32(xReader.Value);
                                    break;

                                case REGION_RESOLUTION_RATIO:
                                    xReader.Read();
                                    region.ResolutionRatio = Convert.ToInt32(xReader.Value);
                                    break;

                                case REGION_MOUSE:
                                    xReader.Read();
                                    region.Mouse = Convert.ToBoolean(xReader.Value);
                                    break;

                                case REGION_X:
                                    xReader.Read();
                                    region.X = Convert.ToInt32(xReader.Value);
                                    break;

                                case REGION_Y:
                                    xReader.Read();
                                    region.Y = Convert.ToInt32(xReader.Value);
                                    break;

                                case REGION_WIDTH:
                                    xReader.Read();
                                    region.Width = Convert.ToInt32(xReader.Value);
                                    break;

                                case REGION_HEIGHT:
                                    xReader.Read();
                                    region.Height = Convert.ToInt32(xReader.Value);
                                    break;

                                case REGION_ACTIVE:
                                    xReader.Read();
                                    region.Active = Convert.ToBoolean(xReader.Value);
                                    break;

                                case REGION_ACTIVE_WINDOW_TITLE_CAPTURE_CHECK:
                                    xReader.Read();
                                    region.ActiveWindowTitleCaptureCheck = Convert.ToBoolean(xReader.Value);
                                    break;

                                case REGION_ACTIVE_WINDOW_TITLE_CAPTURE_TEXT:
                                    xReader.Read();
                                    region.ActiveWindowTitleCaptureText = xReader.Value;
                                    break;
                                }
                            }
                        }

                        xReader.Close();

                        // Change the data for each region that's being loaded if we've detected that
                        // the XML document is from an older version of the application.
                        if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                        {
                            Log.WriteDebugMessage("An old version of the regions file was detected. Attempting upgrade to new region schema");

                            Version v2182         = Settings.VersionManager.Versions.Get("Clara", "2.1.8.2");
                            Version v2300         = Settings.VersionManager.Versions.Get("Boombayah", "2.3.0.0");
                            Version configVersion = Settings.VersionManager.Versions.Get(AppCodename, AppVersion);

                            if (v2182 != null && string.IsNullOrEmpty(AppCodename) && string.IsNullOrEmpty(AppVersion))
                            {
                                Log.WriteDebugMessage("Clara 2.1.8.2 or older detected");

                                region.ViewId = Guid.NewGuid();

                                // Get the screenshots folder path from the old user settings to be used for the region's folder property.
                                region.Folder = Settings.VersionManager.OldUserSettings.GetByKey("ScreenshotsDirectory", FileSystem.ScreenshotsFolder).Value.ToString();

                                region.Folder = FileSystem.CorrectScreenshotsFolderPath(region.Folder);

                                // 2.1 used "%region%", but 2.2 uses "%name%" for a region's Macro value.
                                region.Macro = region.Macro.Replace("%region%", "%name%");

                                region.Format          = imageFormatCollection.GetByName(ImageFormatSpec.NAME_JPEG);
                                region.JpegQuality     = 100;
                                region.ResolutionRatio = 100;
                                region.Mouse           = true;
                                region.Active          = true;
                            }

                            if (v2300 != null && configVersion != null && configVersion.VersionNumber < v2300.VersionNumber)
                            {
                                Log.WriteDebugMessage("Dalek 2.2.4.6 or older detected");

                                // This is a new property for Screen that was introduced in 2.3.0.0
                                // so any version before 2.3.0.0 needs to have it during an upgrade.
                                region.Active = true;
                            }
                        }

                        if (!string.IsNullOrEmpty(region.Name))
                        {
                            Add(region);
                        }
                    }

                    // Write out the regions to the XML document now that we've updated the region objects
                    // with their appropriate property values if it was an old version of the application.
                    if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                    {
                        Log.WriteDebugMessage("Regions file detected as an old version");
                        SaveToXmlFile();
                    }
                }
                else
                {
                    Log.WriteDebugMessage($"WARNING: {FileSystem.RegionsFile} not found. Unable to load regions");

                    SaveToXmlFile();
                }

                Log.WriteDebugMessage(":: LoadXmlFileAndAddRegions End ::");
            }
            catch (Exception ex)
            {
                Log.WriteExceptionMessage("RegionCollection::Load", ex);
            }
        }