internal static void DeleteNonExistentItems(TheImport theImport)
        {
            theImport.RelocatedFiles = new List<string>();
            theImport.DeletedFiles = 0;

            int oldItemCount
                = theImport.Importer
                .Section.ItemCount;

            for (int itemPos = oldItemCount - 1; itemPos >= 0; itemPos--)
            {

                IMLItem item
                    = theImport.Importer
                    .Section[itemPos];

                bool itemChanged = false;

                var locationTag
                    = new MLTag
                        ("Location",
                        item.Location);

                int percentage = (itemPos * 10) / oldItemCount;

                string logMessage1 =
                    "      Checking item: ID="
                    + item.ID
                    + " Location="
                    + locationTag.Value;

                if (!theImport.CheckProgress
                    (percentage, logMessage1))
                {
                    return;
                }

                theImport.Importer.LogMessages
                    .Enqueue(new LogMessage
                        ("Info", logMessage1));

                for (int filePos = locationTag.Values.Count - 1; filePos >= 0; filePos--)
                {

                    if (!theImport.CanDelete(locationTag.Values[filePos]))
                        continue;

                    if (!theImport.Relocate(locationTag, filePos))
                    {
                        string logMessage2 = "Removing " + locationTag.Values[filePos] + " from item's location";
                        theImport.Importer.LogMessages.Enqueue(new LogMessage("Info", logMessage2));
                        locationTag.Values.RemoveAt(filePos);
                    }

                    itemChanged = true;
                }

                if (locationTag.Values.Count == 0)
                {
                    theImport.Importer.Section.DeleteItem(item);
                    theImport.Importer.LogMessages.Enqueue(new LogMessage("Info", "Item deleted"));
                    theImport.DeletedFiles++;
                }
                else
                {
                    if (itemChanged)
                    {
                        item.Location = locationTag.Value;
                        item.ExternalID = locationTag.Value.ToLower();
                        item.SaveTags();
                    }

                }

            }
        }
        internal static void ScanExistingItems(TheImport theImport)
        {
            IMLItemList oldItems
                = theImport.Importer
                .Section.GetReadOnlyItems();

            int oldItemCount = oldItems.Count;

            const string logMessage1
                = "Prescanning existing items:";

            if (!theImport
                .CheckProgress
                (0, logMessage1))
            {
                return;
            }

            bool createItemsChainedByTagCache
                = (theImport.Importer
                .ChainingOption
                == ChainOption.ChainByTags)
                &&   (theImport.Importer
                .TagsToChainBy.Length > 0);

            for (int itemPos = 0; itemPos < oldItemCount; itemPos++)
            {
                IMLItem item = oldItems[itemPos];
                var locationTag = new MLTag("Location", item.Location);

                foreach (string location in locationTag.Values)
                {

                    if (theImport.Location2Id.Keys.Contains
                        (location.ToLowerInvariant()))
                        continue;

                    string logMessage2 = "Mapped the location " + location  + " to the itemid " + item.ID;
                    int percentage = (itemPos * 10) / oldItemCount;
                    if (!theImport.CheckProgress(percentage, logMessage2))
                    {
                        return;
                    }

                    theImport.Location2Id.Add(location.ToLowerInvariant(), item.ID);
                }

                if (!createItemsChainedByTagCache)
                    continue;

                IMLItem writableItem
                    = theImport.Importer.Section
                        .FindItemByID(item.ID);

                IMLItem cachedItem
                    = theImport.ItemsChainedByTagCache
                        .Query(writableItem);

                if (cachedItem == writableItem)
                    continue;

                string logMessage4
                    = "You are chaining by tags " +
                      "but the item (ID: " + item.ID
                      + " Location: "
                      + item.Location
                      + ") has the same values" +
                      " for the tags you're chaining" +
                      " by as the item (ID: "
                      +  cachedItem.ID
                      + " Location: "
                      + cachedItem.Location + ").";

                theImport.Importer.LogMessages.Enqueue
                    (new LogMessage
                         ("Warn", logMessage4));

            }
        }