Beispiel #1
0
        private void CalcSync()
        {
            this.Cursor = Cursors.WaitCursor;
            this.Refresh();
            Flickr.CacheDisabled = true;
            SyncDate = DateTime.Now;
            int count_images = 0;
            long max_size = FlickrSync.ri.MaxFileSize();

            if (Properties.Settings.Default.UseThumbnailImages)
            {
                imageList1.Images.Clear();
                imageList1.ImageSize = new System.Drawing.Size(75, 75);
            }
            ArrayList tmp= performSyncFolders();
            foreach (SyncFolder sf in tmp )
            {
                Application.DoEvents();

                if (string.IsNullOrEmpty(sf.SetId) && string.IsNullOrEmpty(sf.SetTitle))
                {
                    this.Cursor = Cursors.Default;
                    if (FlickrSync.messages_level == FlickrSync.MessagesLevel.MessagesAll)
                    {
                        MessageBox.Show(sf.FolderPath + " has no associated Set", "Warning");
                    }

                    FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + " has no associated set");
                    this.Cursor = Cursors.WaitCursor;
                    continue;
                }

                List<FileInfo> files = GetFiles(sf);

                // Skip sync folders that have same number of photos as photo sets
                if (!string.IsNullOrEmpty(sf.SetId))
                {
                    Photoset photoset = FlickrSync.ri.GetPhotoset(sf.SetId);
                    if (photoset.NumberOfPhotos == files.Count)
                    {
                        continue;
                    }
                }

                var photos = new List<PhotoInfo>();
                try
                {
                    photos = GetPhotos(sf);
                }
                catch (Exception ex)
                {
                    FlickrSync.Error("Error loading information from Set " + sf.SetId, ex, FlickrSync.ErrorType.Normal);
                    Close();
                }

                ListViewGroup group;
                if (string.IsNullOrEmpty(sf.SetId))
                {
                    group = new ListViewGroup("Folder: " + sf.FolderPath + "; Set: " + sf.SetTitle);
                }
                else
                {
                    try
                    {
                        group = new ListViewGroup("Folder: " + sf.FolderPath + "; Set: " + FlickrSync.ri.GetPhotoset(sf.SetId).Title);
                    }
                    catch (Exception)
                    {
                        group = new ListViewGroup("Folder: " + sf.FolderPath + "; Set: " + sf.SetId);
                    }
                }

                listViewToSync.Groups.Add(group);

                foreach (FileInfo fi in files)
                {
                    ImageInfo ii;
                    if (ShouldExcludePhoto(sf, fi, out ii))
                    {
                        continue;
                    }

                    string name = GetImageNameFromFileName(fi.Name);

                    // Matching photos
                    int pos = -1;
                    bool found = false;
                    foreach (PhotoInfo pi in photos)
                    {
                        pos++;

                        if (IsPhotoMatch(sf, pi, ii, name))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        if (ii.GetFileName() != fi.FullName)
                        {
                            ii.Load(fi.FullName, ImageInfo.FileTypes.FileTypeUnknown);
                        }

                        SyncItem si = CreateSyncItem(sf, fi, ii, SyncItem.Actions.ActionUpload, name, max_size);

                        int position = 0;
                        if (Properties.Settings.Default.UseThumbnailImages)
                        {
                            imageList1.Images.Add(count_images.ToString(), Thumbnail(fi.FullName, count_images.ToString(), true, si.Action));
                            position = count_images;
                            count_images++;
                        }

                        ListViewItem lvi;
                        if (si.Action != SyncItem.Actions.ActionNone)
                        {
                            lvi = listViewToSync.Items.Add("NEW: " + fi.Name, position);
                            lvi.ForeColor = Color.Blue;
                        }
                        else
                        {
                            lvi = listViewToSync.Items.Add("SKIP: " + fi.Name, position);
                            lvi.ForeColor = Color.LightGray;
                        }

                        lvi.ToolTipText = lvi.Text + " " + group.Header;
                        group.Items.Add(lvi);

                        si.item_id = lvi.Index;
                        SyncItems.Add(si);
                    }
                    else
                    {
                        photos[pos].Found = true;

                        // Compare time is based on local info DateSync because flickr clock could be misaligned with local clock
                        DateTime compare = photos[pos].DateSync;
                        if (compare == new DateTime(2000, 1, 1))
                        {
                            compare = photos[pos].DateUploaded;
                        }

                        if (compare < fi.LastWriteTime)
                        {
                            if (ii.GetFileName() != fi.FullName)
                            {
                                ii.Load(fi.FullName, ImageInfo.FileTypes.FileTypeUnknown);
                            }

                            SyncItem si = CreateSyncItem(sf, fi, ii, SyncItem.Actions.ActionReplace, name, max_size);

                            if (sf.LastSync == (new DateTime(2000, 1, 1)) && sf.NoInitialReplace)
                            {
                                si.Action = SyncItem.Actions.ActionNone;
                            }

                            si.PhotoId = photos[pos].PhotoId;

                            int position = 0;
                            if (Properties.Settings.Default.UseThumbnailImages)
                            {
                                imageList1.Images.Add(count_images.ToString(), Thumbnail(fi.FullName, count_images.ToString(), true, SyncItem.Actions.ActionReplace));
                                position = count_images;
                                count_images++;
                            }

                            ListViewItem lvi;
                            if (si.Action != SyncItem.Actions.ActionNone)
                            {
                                lvi = listViewToSync.Items.Add("REPLACE: " + fi.Name, position);
                                lvi.ForeColor = Color.Black;
                            }
                            else
                            {
                                lvi = listViewToSync.Items.Add("SKIP: " + fi.Name, position);
                                lvi.ForeColor = Color.LightGray;
                            }

                            lvi.ToolTipText = lvi.Text+" "+group.Header;
                            group.Items.Add(lvi);

                            si.item_id = lvi.Index;
                            SyncItems.Add(si);
                        }
                    }
                }

                if (!sf.NoDelete)
                {
                    foreach (PhotoInfo pi in photos)
                    {
                        if (!pi.Found)
                        {
                            SyncItem si = new SyncItem();
                            si.Action = SyncItem.Actions.ActionDelete;
                            si.PhotoId = pi.PhotoId;
                            si.Title = pi.Title;
                            si.SetId = sf.SetId;

                            int position = 0;
                            if (Properties.Settings.Default.UseThumbnailImages)
                            {
                                imageList1.Images.Add(count_images.ToString(), Thumbnail(pi.PhotoId, count_images.ToString(), false, SyncItem.Actions.ActionDelete));
                                position = count_images;
                                count_images++;
                            }

                            ListViewItem lvi = listViewToSync.Items.Add("DELETE: " + pi.Title,position);
                            lvi.ForeColor = Color.Red;
                            lvi.ToolTipText = lvi.Text + " " + group.Header;
                            group.Items.Add(lvi);

                            si.item_id = lvi.Index;
                            SyncItems.Add(si);

                        }
                    }
                }

                if(FlickrSync.autorun){

                    if(SyncItems.Count > int.Parse(Properties.Settings.Default.ItemLimit) &&  int.Parse(Properties.Settings.Default.ItemLimit)> 0){
                        break;
                    }
                }
            }

            FlickrSync.Log(FlickrSync.LogLevel.LogAll, "Prepared Synchronization successful Total items:" + SyncItems.Count);

            Flickr.CacheDisabled = false;
            this.Cursor = Cursors.Default;

            if(FlickrSync.autorun){
                // Autosync
                startThreadExecuteSync();

            }
        }
Beispiel #2
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;
        }
Beispiel #3
0
        private Image Thumbnail(string org,string key,bool local,SyncItem.Actions action)
        {
            ThumbnailTask tt;
            tt.org = org;
            tt.key = key;
            tt.local = local;
            tt.action = action;
            Tasks.Add(tt);

            switch (tt.action)
            {
                case SyncItem.Actions.ActionUpload:
                    return Properties.Resources.icon_new;
                case SyncItem.Actions.ActionReplace:
                    return Properties.Resources.icon_replace;
                case SyncItem.Actions.ActionDelete:
                    return Properties.Resources.icon_delete;
                case SyncItem.Actions.ActionNone:
                    return Properties.Resources.icon_none;
            }

            return Properties.Resources.flickrsync;
        }