Example #1
0
        private List<FileInfo> GetFiles(SyncFolder sf)
        {
            var files = new List<FileInfo>();

            try
            {
                DirectoryInfo dir = new DirectoryInfo(sf.FolderPath);
                if (!dir.Exists)
                {
                    if (FlickrSync.messages_level != FlickrSync.MessagesLevel.MessagesNone)
                    {
                        if (MessageBox.Show("Folder " + sf.FolderPath + " no longer exists. Remove from configuration?", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            FlickrSync.li.Remove(sf.FolderPath);
                            FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + " deleted from configuration");
                        }
                        else
                            FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + " does not exist");
                    }

                    return files;
                }

                int count = Properties.Settings.Default.Extensions.Count;

                foreach (string ext in Properties.Settings.Default.Extensions)
                {
                    FileInfo[] foundFiles = dir.GetFiles("*." + ext);

                    foreach (FileInfo file in foundFiles)
                    {
                        // Some apps generate hidden files that are not meant to be uploaded but has the
                        // same extension as the image (e.g. "._name.jpg" with size 4,096 bytes).
                        if ((file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                        {
                            continue;
                        }

                        // Make sure the file is valid, otherwise, is will cause failure later when attempting
                        // to upload to Flickr.
                        if (file.Length == 0)
                        {
                            continue;
                        }

                        files.Add(file);
                    }
                }
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Default;
                FlickrSync.Error("Error accessing path: " + sf.FolderPath, ex, FlickrSync.ErrorType.Normal);
                this.Close();
            }

            files.Sort(new SortLastWriteHelper());

            return files;
        }
Example #2
0
        private List<PhotoInfo> GetPhotos(SyncFolder sf)
        {
            var photosInSet = new List<PhotoInfo>();

            if (string.IsNullOrEmpty(sf.SetId))
            {
                return photosInSet;
            }

            int retryCount = 0;
            bool success = false;

            while (!success)
            {
                try
                {
                    photosInSet.Clear();

                    foreach (Photo p in FlickrSync.ri.SetPhotos(sf.SetId))
                    {
                        // workaround since media type and p.MachineTags is not working on FlickrNet 2.1.5
                        if (p.CleanTags != null)
                        {
                            if (p.CleanTags.IndexOf("flickrsync:type=video", StringComparison.OrdinalIgnoreCase) >= 0 ||
                                p.CleanTags.IndexOf("flickrsync:cmd=skip", StringComparison.OrdinalIgnoreCase) >= 0 ||
                                p.CleanTags.IndexOf("flickrsync:type:video", StringComparison.OrdinalIgnoreCase) >= 0 ||
                                p.CleanTags.IndexOf("flickrsync:cmd:skip", StringComparison.OrdinalIgnoreCase) >= 0)
                                continue;
                        }

                        PhotoInfo pi = new PhotoInfo();
                        pi.Title = p.Title;
                        pi.DateTaken = p.DateTaken;
                        pi.DateSync = sf.LastSync;
                        pi.DateUploaded = p.DateUploaded;
                        pi.PhotoId = p.PhotoId;
                        pi.Found = false;
                        photosInSet.Add(pi);
                    }

                    success = true;
                }
                catch (Exception)
                {
                    if (retryCount++ <= 5)
                    {
                        Thread.Sleep(TimeSpan.FromSeconds(1));
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return photosInSet;
        }
Example #3
0
        private void Sort(SyncFolder sf)
        {
            if (sf.OrderType==SyncFolder.OrderTypes.OrderDefault)
                return;

            try
            {
                Photo[] photolist = FlickrSync.ri.SetPhotos(sf.SetId);
                ArrayList photo_array=new ArrayList();
                foreach (Photo p in photolist)
                    photo_array.Add(p);

                switch (sf.OrderType)
                {
                    case SyncFolder.OrderTypes.OrderDateTaken:
                        photo_array.Sort(new PhotoSortDateTaken());
                        break;
                    case SyncFolder.OrderTypes.OrderTitle:
                        photo_array.Sort(new PhotoSortTitle());
                        break;
                    case SyncFolder.OrderTypes.OrderTag:
                        photo_array.Sort(new PhotoSortTag());
                        break;
                }

                string[] ids = new string[photo_array.Count];
                for (int i = 0; i < photo_array.Count; i++)
                    ids[i] = ((Photo)photo_array[i]).PhotoId;

                FlickrSync.ri.SortSet(sf.SetId, ids);
            }
            catch (Exception ex)
            {
                FlickrSync.Error("Error sorting set "+sf.SetTitle+" ("+sf.SetId+")", ex, FlickrSync.ErrorType.Info);
            }
        }
Example #4
0
        private SyncItem CreateSyncItem(SyncFolder sf, FileInfo fi, ImageInfo ii, SyncItem.Actions action, string name, long max_size)
        {
            var si = new SyncItem();

            si.Action = action;

            if (fi.Length > max_size)
            {
                si.Action = SyncItem.Actions.ActionNone;
            }

            si.Filename = fi.FullName;
            si.SetId = sf.SetId;
            si.SetTitle = sf.SetTitle;
            si.SetDescription = sf.SetDescription;
            si.NoDeleteTags = sf.NoDeleteTags;

            if (!string.IsNullOrEmpty(ii.GetTitle()) && sf.SyncMethod != SyncFolder.Methods.SyncFilename)
            {
                si.Title = ii.GetTitle();
            }
            else
            {
                si.Title = name;
            }

            si.Description = ii.GetDescription();
            si.Tags = ii.GetTagsArray();

            if (!string.IsNullOrEmpty(ii.GetCity()))
            {
                si.Tags.Add(ii.GetCity());
            }

            if (!string.IsNullOrEmpty(ii.GetCountry()))
            {
                si.Tags.Add(ii.GetCountry());
            }

            si.GeoLat = ii.GetGeo(true);
            si.GeoLong = ii.GetGeo(false);

            si.FolderPath = sf.FolderPath;
            si.Permission = sf.Permission;

            return si;
        }
Example #5
0
        private bool IsPhotoMatch(SyncFolder sf, PhotoInfo pi, ImageInfo ii, string name)
        {
            if (sf.SyncMethod == SyncFolder.Methods.SyncFilename && pi.Title == name)
            {
                return true;
            }

            if (sf.SyncMethod == SyncFolder.Methods.SyncDateTaken && pi.DateTaken == ii.GetDateTaken())
            {
                return true;
            }

            if (sf.SyncMethod == SyncFolder.Methods.SyncTitleOrFilename)
            {
                string title = ii.GetTitle();
                if (string.IsNullOrEmpty(title))
                {
                    title = name;
                }

                if (pi.Title == title)
                {
                    return true;
                }
            }

            return false;
        }
Example #6
0
        private bool ShouldExcludePhoto(SyncFolder sf, FileInfo fi, out ImageInfo ii)
        {
            ii = new ImageInfo();
            string[] ftags = sf.FilterTags.Split(';');
            for (int i = 0; i < ftags.GetLength(0); i++)
            {
                ftags[i] = ftags[i].Trim();
            }

            bool include = true;

            if (sf.FilterType == SyncFolder.FilterTypes.FilterIncludeTags ||
                sf.FilterType == SyncFolder.FilterTypes.FilterStarRating ||
                sf.SyncMethod == SyncFolder.Methods.SyncDateTaken ||
                sf.SyncMethod == SyncFolder.Methods.SyncTitleOrFilename)
            {
                ii.Load(fi.FullName, ImageInfo.FileTypes.FileTypeUnknown);
            }

            if (sf.FilterType == SyncFolder.FilterTypes.FilterIncludeTags)
            {
                include = false;

                foreach (string tag in ii.GetTagsArray())
                {
                    foreach (string tag2 in ftags)
                    {
                        if (string.Equals(tag, tag2, StringComparison.OrdinalIgnoreCase))
                        {
                            include = true;
                            break;
                        }
                    }

                    if (include)
                    {
                        break;
                    }
                }
            }

            if (sf.FilterType == SyncFolder.FilterTypes.FilterStarRating)
            {
                if (sf.FilterStarRating > ii.GetStarRating())
                {
                    include = false;
                }
            }

            /*if (fi.Length > max_size)
                include = false;*/

            return !include;
        }
Example #7
0
 public SyncFolderForm(SyncFolder pSyncFolder)
 {
     InitializeComponent();
     sf=pSyncFolder;
 }
Example #8
0
        private void treeFolders_AfterCheck(object sender, TreeViewEventArgs e)
        {
            Cursor = Cursors.WaitCursor;

            if (e.Node.Checked)
            {
                if (syncprop_status == SyncPropertiesStatus.CancelAll)
                {
                    e.Node.Checked = false;

                    treeFolders.RefreshTreeNodes(treeFolders.Nodes);
                    CalcTooltips();
                    Cursor = Cursors.Default;
                    return;
                }

                SyncFolder sf = new SyncFolder(e.Node.Name);

                //try to match Set name
                foreach (Photoset ps in FlickrSync.ri.GetAllSets())
                {
                    if (ps.Title.Equals(Path.GetFileName(e.Node.Name),StringComparison.CurrentCultureIgnoreCase))
                    {
                        sf.SetId = ps.PhotosetId;
                        break;
                    }
                }
                if (sf.SetId == "")
                    sf.SetTitle = Path.GetFileName(e.Node.Name);

                if (syncprop_status == SyncPropertiesStatus.OKAll)
                {
                    li.Add(sf);
                }
                else
                {
                    SyncFolderForm sff = new SyncFolderForm(sf);
                    if (syncprop_status == SyncPropertiesStatus.MultipleUndef)
                        sff.SetMultiple(true);

                    DialogResult dr=sff.ShowDialog();

                    if (dr == DialogResult.OK || dr==DialogResult.Yes)  //Yes means OK to All
                        li.Add(sf);
                    else
                        e.Node.Checked = false;

                    if (dr == DialogResult.Yes && syncprop_status == SyncPropertiesStatus.MultipleUndef)
                        syncprop_status = SyncPropertiesStatus.OKAll;

                    if (dr == DialogResult.Abort) //CancelAll
                    {
                        syncprop_status = SyncPropertiesStatus.CancelAll;

                        treeFolders.RefreshTreeNodes(treeFolders.Nodes);
                        CalcTooltips();
                        Cursor = Cursors.Default;
                        return;
                    }
                }
            }
            else
                li.Remove(e.Node.Name);

            treeFolders.RefreshTreeNodes(treeFolders.Nodes);
            CalcTooltips();
            Cursor = Cursors.Default;
        }
Example #9
0
 public void Add(SyncFolder sf)
 {
     SyncFolders.Add(sf);
 }
Example #10
0
        public void LoadFromXML(string xml)
        {
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(xml);
            XPathNavigator nav = xmldoc.CreateNavigator();
            XPathNodeIterator iterator=nav.Select("/FlickrSync/SyncFolder");

            while (iterator.MoveNext())
            {
                SyncFolder sf=new SyncFolder();
                XPathNavigator nav2 = iterator.Current;
                sf.LoadFromXPath(nav2);

                DirectoryInfo dir = new DirectoryInfo(sf.FolderPath);
                if (!dir.Exists)
                {
                    if (FlickrSync.messages_level!=FlickrSync.MessagesLevel.MessagesNone)
                    {
                        if (MessageBox.Show("Folder " + sf.FolderPath + " no longer exists. Remove from configuration?", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            FlickrSync.Log(FlickrSync.LogLevel.LogAll,sf.FolderPath + "marked for removal from configuration");
                            continue;
                        }
                        else
                            FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + "does not exists");
                    }
                }

                SyncFolders.Add(sf);
            }

            iterator = nav.Select("/FlickrSync/PathInfo");

            while (iterator.MoveNext())
            {
                PathInfo pi = new PathInfo();
                XPathNavigator nav2 = iterator.Current;
                pi.LoadFromXPath(nav2);

                DirectoryInfo dir = new DirectoryInfo(pi.Path);
                if (!dir.Exists)
                {
                    if (!pi.ManualAdd)
                        continue;

                    if (FlickrSync.messages_level != FlickrSync.MessagesLevel.MessagesNone)
                    {
                        if (MessageBox.Show("Folder " + pi.Path + " no longer exists. Remove from configuration?", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            FlickrSync.Log(FlickrSync.LogLevel.LogAll, "Path" + pi.Path + " marked for removal from configuration");
                            continue;
                        }
                        else
                            FlickrSync.Log(FlickrSync.LogLevel.LogAll, "Path" + pi.Path + " no longer exists");
                    }
                }

                PathInfoList.Add(pi);
            }
        }
Example #11
0
        /***
         * Clone Implementation
         * */
        public object Clone()
        {
            SyncFolder clone=new SyncFolder();
            clone.FolderPath = FolderPath;
            clone.LastSync = LastSync;

            clone.SetId = SetId;
            clone.SetTitle = SetTitle;
            clone.SetDescription = SetDescription;
            clone.SyncMethod = SyncMethod;
            clone.FilterType = FilterType;
            clone.FilterTags = FilterTags;
            clone.FilterStarRating = FilterStarRating;
            clone.Permission = Permission;
            clone.NoDelete = NoDelete;
            clone.NoDeleteTags = NoDeleteTags;
            clone.OrderType = OrderType;
            clone.NoInitialReplace = NoInitialReplace;

            clone.Children = Properties.Settings.Default.Children;

            return clone;
        }