Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MainFlickrSync = new FlickrSync();

            if (MainFlickrSync != null)
            {
                if (args.Length > 0)
                {
                    foreach (string str in args)
                    {
                        if (str.ToLower().Contains(@"/auto"))
                            FlickrSync.autorun = true;
                    }
                }

                try
                {
                    Application.Run(MainFlickrSync);
                }
                catch (Exception ex)
                {
                    FlickrSync.Error("Unknown error detected - exiting FlickrSync.", ex, FlickrSync.ErrorType.FatalError);
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MainFlickrSync = new FlickrSync();

            if (MainFlickrSync != null)
            {
                if (args.Length > 0)
                {
                    foreach (string str in args)
                    {
                        if (str.ToLower().Contains(@"/auto"))
                        {
                            FlickrSync.autorun = true;
                        }
                    }
                }

                try
                {
                    Application.Run(MainFlickrSync);
                }
                catch (Exception ex)
                {
                    FlickrSync.Error("Unknown error detected - exiting FlickrSync.", ex, FlickrSync.ErrorType.FatalError);
                }
            }
        }
Ejemplo n.º 3
0
        private void preferencesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Preferences pref = new Preferences();

            if (pref.ShowDialog() == DialogResult.OK)
            {
                messages_level = FlickrSync.StringToMsgLevel(Properties.Settings.Default.MessageLevel);
                log_level      = FlickrSync.StringToLogLevel(Properties.Settings.Default.LogLevel);
                if (autorun)
                {
                    messages_level = MessagesLevel.MessagesNone;
                }
            }
        }
Ejemplo n.º 4
0
 public RemoteInfo()
 {
     try
     {
         webClient = new WebClient();
         CreateFlickrObject();
     }
     catch (FlickrNet.Exceptions.LoginFailedInvalidTokenException invalidTokenEx)
     {
         throw invalidTokenEx;
     }
     catch (Exception ex)
     {
         FlickrSync.Error("Error connecting to flickr", ex, FlickrSync.ErrorType.Connect);
     }
 }
Ejemplo n.º 5
0
        private void FlickrSync_Load(object sender, EventArgs e)
        {
            string token = "";

            try {
                token = Properties.Settings.Default.FlickrToken;
            }
            catch (Exception)
            {
            }

            if (token == "")
            {
                FlickrGetToken();
            }

            messages_level = FlickrSync.StringToMsgLevel(Properties.Settings.Default.MessageLevel);
            log_level      = FlickrSync.StringToLogLevel(Properties.Settings.Default.LogLevel);
            if (autorun)
            {
                messages_level = MessagesLevel.MessagesNone;
            }

            // ri is needed to get the user. TODO: Get User without using ri
            ri = new RemoteInfo();

            UpdateUser();
            LoadConfig();
            Reload();
            FlickrSync.Log(LogLevel.LogBasic, "Application loaded");

            if (autorun)
            {
                WindowState = FormWindowState.Minimized;
            }
            else
            {
                WindowState = FormWindowState.Maximized;
            }

            if (autorun)
            {
                ViewAndSync();
                Close();
            }
        }
Ejemplo n.º 6
0
        private void SyncFolderForm_Load(object sender, EventArgs e)
        {
            labelFolderPath.Text              = sf.FolderPath;
            textBoxTitle.Text                 = sf.SetTitle;
            textBoxDescription.Text           = sf.SetDescription;
            comboBoxMethod.SelectedIndex      = (int)sf.SyncMethod;
            comboBoxFilterType.SelectedIndex  = (int)sf.FilterType;
            comboBoxPermissions.SelectedIndex = (int)sf.Permission;
            checkBoxNoDelete.Checked          = sf.NoDelete;
            checkBoxNoDeleteTags.Checked      = sf.NoDeleteTags;
            comboBoxOrderType.SelectedIndex   = (int)sf.OrderType;
            checkBoxNoInitialReplace.Checked  = sf.NoInitialReplace;

            if (sf.FilterType == SyncFolder.FilterTypes.FilterIncludeTags)
            {
                labelTags.Visible     = true;
                textBoxTags.Visible   = true;
                textBoxTags.Text      = sf.FilterTags;
                buttonTagList.Visible = true;
            }

            star_rating = sf.FilterStarRating;
            if (sf.FilterType == SyncFolder.FilterTypes.FilterStarRating)
            {
                UpdateStarRating();
            }

            listViewSet.LargeImageList = Program.MainFlickrSync.GetImageList();

            try
            {
                foreach (Photoset psi in FlickrSync.ri.GetAllSets())
                {
                    ListViewItem lvi = listViewSet.Items.Add(psi.PhotosetId, psi.Title, psi.PhotosetId);
                    if (psi.PhotosetId == sf.SetId)
                    {
                        lvi.Selected = true;
                    }
                }
            }
            catch (Exception ex)
            {
                FlickrSync.Error("Error loading", ex, FlickrSync.ErrorType.Normal);
                this.Close();
            }
        }
Ejemplo n.º 7
0
        private void CreateFlickrObject()
        {
            f = new Flickr(Properties.Settings.Default.FlickrApiKey, Properties.Settings.Default.FlickrShared);
            OAuthAccessToken oauth = Properties.Settings.Default.OAuthToken;

            f.OAuthAccessToken       = oauth.Token;
            f.OAuthAccessTokenSecret = oauth.TokenSecret;

            f.Proxy             = FlickrSync.GetProxy(true);
            f.HttpTimeout       = 240000;
            f.OnUploadProgress += new EventHandler <FlickrNet.UploadProgressEventArgs>(Flickr_OnUploadProgress);
            sets = f.PhotosetsGetList();
            if (sets == null)
            {
                sets = new PhotosetCollection();
            }

            string user = User();  //force access to check connection
        }
Ejemplo n.º 8
0
        public RemoteInfo()
        {
            try
            {
                f                   = new Flickr(Properties.Settings.Default.FlickrApiKey, Properties.Settings.Default.FlickrShared, Properties.Settings.Default.FlickrToken);
                f.Proxy             = FlickrSync.GetProxy(true);
                f.OnUploadProgress += new Flickr.UploadProgressHandler(Flickr_OnUploadProgress);
                sets                = f.PhotosetsGetList().PhotosetCollection;
                if (sets == null)
                {
                    sets = new Photoset[0];
                }

                string user = User();  //force access to check connection
            }
            catch (Exception ex)
            {
                FlickrSync.Error("Error connecting to flickr", ex, FlickrSync.ErrorType.Connect);
            }
        }
Ejemplo n.º 9
0
        private void Preferences_Load(object sender, EventArgs e)
        {
            comboBoxMethod.SelectedIndex        = (int)SyncFolder.StringToMethod(Properties.Settings.Default.Method);
            comboBoxOrderType.SelectedIndex     = (int)SyncFolder.StringToOrderType(Properties.Settings.Default.OrderType);
            checkBoxNoDelete.Checked            = Properties.Settings.Default.NoDelete;
            checkBoxNoDeleteTags.Checked        = Properties.Settings.Default.NoDeleteTags;
            checkBoxShowThumbnailImages.Checked = Properties.Settings.Default.UseThumbnailImages;

            checkBoxUseProxy.Checked = Properties.Settings.Default.ProxyUse;
            SetProxyState();
            textBoxProxyHost.Text = Properties.Settings.Default.ProxyHost;
            textBoxProxyPort.Text = Properties.Settings.Default.ProxyPort;
            textBoxProxyUser.Text = Properties.Settings.Default.ProxyUser;
            textBoxProxyPass.Text = Properties.Settings.Default.ProxyPass;

            comboBoxMsgLevel.SelectedIndex = (int)FlickrSync.StringToMsgLevel(Properties.Settings.Default.MessageLevel);
            comboBoxLogLevel.SelectedIndex = (int)FlickrSync.StringToLogLevel(Properties.Settings.Default.LogLevel);
            labelLogFile.Text = Properties.Settings.Default.LogFile;

            buttonLogFile.Visible = (((FlickrSync.LogLevel)comboBoxLogLevel.SelectedIndex) != FlickrSync.LogLevel.LogNone);
            labelLogFile.Visible  = (((FlickrSync.LogLevel)comboBoxLogLevel.SelectedIndex) != FlickrSync.LogLevel.LogNone);
        }
Ejemplo n.º 10
0
        private void buttonTagList_Click(object sender, EventArgs e)
        {
            ArrayList taglist = new ArrayList();

            FileInfo[] files = { };
            ImageInfo  ii    = new ImageInfo();

            try
            {
                DirectoryInfo dir = new DirectoryInfo(sf.FolderPath);

                string   lookfor    = "*.jpg;*.jpeg;*.gif;*.png;*.tif;*.tiff;*.bmp";
                string[] extensions = lookfor.Split(new char[] { ';' });

                ArrayList myfileinfos = new ArrayList();
                foreach (string ext in extensions)
                {
                    myfileinfos.AddRange(dir.GetFiles(ext));
                }

                files = (FileInfo[])myfileinfos.ToArray(typeof(FileInfo));
            }
            catch (Exception ex)
            {
                FlickrSync.Error("Error accessing path: " + sf.FolderPath, ex, FlickrSync.ErrorType.Normal);
            }

            this.Cursor = Cursors.WaitCursor;

            foreach (FileInfo fi in files)
            {
                try
                {
                    ii.Load(fi.FullName, ImageInfo.FileTypes.FileTypeUnknown);
                }
                catch (Exception ex)
                {
                    this.Cursor = Cursors.Default;
                    FlickrSync.Error("Error loading image information: " + fi.FullName, ex, FlickrSync.ErrorType.Normal);
                    return;
                }

                foreach (string tag in ii.GetTagsArray())
                {
                    bool exists = false;
                    foreach (string tagexist in taglist)
                    {
                        if (tag == tagexist)
                        {
                            exists = true;
                            break;
                        }
                    }

                    if (!exists)
                    {
                        taglist.Add(tag);
                    }
                }
            }

            this.Cursor = Cursors.Default;

            SelectFromList listForm = new SelectFromList(taglist);

            listForm.ShowDialog();

            if (textBoxTags.Text == "")
            {
                textBoxTags.Text = listForm.Selected;
            }
            else
            {
                textBoxTags.Text += "; " + listForm.Selected;
            }
        }
Ejemplo n.º 11
0
        static public WebProxy GetProxy(bool interactive)
        {
            if (!Properties.Settings.Default.ProxyUse)
            {
                return(null);
            }

            string domain_user = Properties.Settings.Default.ProxyUser;
            string pass        = Properties.Settings.Default.ProxyPass;

            if (pass == "")
            {
                pass = proxy_password;
            }

            if (pass == "")
            {
                if (interactive)
                {
                    Login l = new Login(domain_user, pass);
                    if (l.ShowDialog() != DialogResult.OK)
                    {
                        return(null);
                    }

                    if (!Properties.Settings.Default.ProxyUse)
                    {
                        return(null);
                    }

                    domain_user = l.GetUser();
                    pass        = l.GetPass();
                }

                Properties.Settings.Default.ProxyUser = domain_user;
                Properties.Settings.Default.Save();

                proxy_password = pass;
            }

            string domain;
            string proxyuser;

            if (domain_user.Contains(@"\"))
            {
                int pos = domain_user.IndexOf('\\');
                domain    = domain_user.Substring(0, pos);
                proxyuser = domain_user.Substring(pos + 1, domain_user.Length - pos - 1);
            }
            else
            {
                domain    = "";
                proxyuser = domain_user;
            }

            try {
                WebProxy proxyObject = new WebProxy(Properties.Settings.Default.ProxyHost, Int16.Parse(Properties.Settings.Default.ProxyPort));
                proxyObject.Credentials = new NetworkCredential(proxyuser, pass, domain);
                return(proxyObject);
            }
            catch (Exception ex)
            {
                FlickrSync.Error("Error connecting to Proxy", ex, ErrorType.Connect);
                return(null);
            }
        }
Ejemplo n.º 12
0
        private void FlickrSync_Load(object sender, EventArgs e)
        {
            // probably not needed but just to make sure no message from previous versions is shown
            if (Properties.Settings.Default.MessageId.CompareTo("090130_0000") < 0)
            {
                Properties.Settings.Default.MessageId = "090130_0000";
                Properties.Settings.Default.Save();
            }

            HashUsers = new ArrayList();

            OAuthAccessToken token = null;

            try {
                token = Properties.Settings.Default.OAuthToken;
            }
            catch (Exception)
            {
            }

            if (token == null)
            {
                FlickrGetToken();
            }

            messages_level = FlickrSync.StringToMsgLevel(Properties.Settings.Default.MessageLevel);
            log_level      = FlickrSync.StringToLogLevel(Properties.Settings.Default.LogLevel);
            if (autorun)
            {
                messages_level = MessagesLevel.MessagesNone;
            }

            // ri is needed to get the user. TODO: Get User without using ri
            try
            {
                ri = new RemoteInfo();
            }
            catch (FlickrNet.Exceptions.LoginFailedInvalidTokenException)
            {
                FlickrGetToken();
                ri = new RemoteInfo();
            }

            UpdateUser();
            LoadConfig();
            Reload();
            FlickrSync.Log(LogLevel.LogBasic, "Application loaded");

            if (autorun)
            {
                WindowState = FormWindowState.Minimized;
            }
            else
            {
                WindowState = FormWindowState.Maximized;
            }

            if (!message_tested)
            {
                try
                {
                    webBrowser1.Navigate(Properties.Settings.Default.MessageUrl + "?version=" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
                }
                catch (Exception)
                {
                }
            }

            if (autorun)
            {
                ViewAndSync();
                Close();
            }
        }
Ejemplo n.º 13
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);
            }
        }
Ejemplo n.º 14
0
 public void SaveToXML()
 {
     Properties.Settings.Default.LocalInfoXml = GetSyncXML();
     FlickrSync.SaveConfig();
 }
Ejemplo n.º 15
0
        public string ReplacePicture(string filename, string photoid, string title, string caption, ArrayList tags, FlickrSync.Permissions permission, bool NoDeleteTags, double?GeoLat, double?GeoLong)
        {
            string id = f.ReplacePicture(filename, photoid);

            f.PhotosSetMeta(id, title, caption);

            ArrayList specialtags = new ArrayList();

            foreach (string tag in tags)
            {
                if (tag.ToLower().StartsWith("flickrsync:") || tag.ToLower().StartsWith(@"""flickrsync:"))
                {
                    specialtags.Add(tag);
                }
            }

            foreach (string stag in specialtags)
            {
                tags.Remove(stag);

                string stag2 = stag.ToLower();
                // To support picasa replace colons with equal sign (to be able to use flickrsync:perm:friends instead of flickrsync:perm=friends)
                stag2 = stag2.Replace(':', '=');

                if (stag2.Contains("flickrsync=perm=private"))
                {
                    permission = FlickrSync.Permissions.PermPrivate;
                }
                else if (stag2.Contains("flickrsync=perm=default"))
                {
                    permission = FlickrSync.Permissions.PermDefault;
                }
                else if (stag2.Contains("flickrsync=perm=familyfriends"))
                {
                    permission = FlickrSync.Permissions.PermFamilyFriends;
                }
                else if (stag2.Contains("flickrsync=perm=friends"))
                {
                    permission = FlickrSync.Permissions.PermFriends;
                }
                else if (stag2.Contains("flickrsync=perm=family"))
                {
                    permission = FlickrSync.Permissions.PermFamily;
                }
                else if (stag2.Contains("flickrsync=perm=public"))
                {
                    permission = FlickrSync.Permissions.PermPublic;
                }
            }

            f.PhotosSetPerms(id,
                             permission == FlickrSync.Permissions.PermPublic,
                             permission == FlickrSync.Permissions.PermFriends || permission == FlickrSync.Permissions.PermFamilyFriends,
                             permission == FlickrSync.Permissions.PermFamily || permission == FlickrSync.Permissions.PermFamilyFriends,
                             PermissionComment.Everybody, PermissionAddMeta.Everybody);

            string user = f.AuthCheckToken(Properties.Settings.Default.FlickrToken).User.UserId;

            PhotoInfoTag[] ftags = f.TagsGetListPhoto(id); //.Tags.TagCollection;

            if (ftags != null)
            {
                foreach (PhotoInfoTag ftag in ftags)
                {
                    if (ftag.AuthorId == user)
                    {
                        bool found = false;
                        for (int i = 0; i < tags.Count; i++)
                        {
                            if ((string)tags[i] == ftag.Raw)
                            {
                                found = true;
                                tags.RemoveAt(i);
                                break;
                            }
                        }

                        if (!found && !NoDeleteTags)
                        {
                            f.PhotosRemoveTag(ftag.TagId);
                        }
                    }
                }
            }

            foreach (string tag in tags)
            {
                if (tag.Length > 0 && tag[0] == '"' && tag[tag.Length - 1] == '"')
                {
                    f.PhotosAddTags(id, tag);
                }
                else
                {
                    f.PhotosAddTags(id, @"""" + tag + @"""");
                }
            }

            if (GeoLat != null && GeoLong != null)
            {
                try
                {
                    f.PhotosGeoSetLocation(id, (double)GeoLat, (double)GeoLong);
                }
                catch (Exception ex)
                {
                    FlickrSync.Error("Error setting Geo location: " + filename + " Lat=" + GeoLat + " Long=" + GeoLong, ex, FlickrSync.ErrorType.Normal);
                }
            }

            return(id);
        }
Ejemplo n.º 16
0
        public void LoadFromXML(string xml)
        {
            // current search/replace pattern in case base directory has moved
            List <SearchReplace> paths = new List <SearchReplace>();

            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 && paths.Count > 0)
                {
                    for (int i = 0; i < paths.Count; i++)
                    {
                        if (sf.FolderPath.StartsWith(paths[i].oldpath))
                        {
                            // Directory no longer exists, but it seems that we might be able to find its new location,
                            // based on an alternate directory location we got from a previously missing directory
                            string potentialFolderPath = sf.FolderPath.Replace(paths[i].oldpath, paths[i].newpath); // replace prefix as we did last time
                            dir = new DirectoryInfo(potentialFolderPath);
                            // Have we succeeded? silently replace prefix
                            if (dir.Exists)
                            {
                                FlickrSync.Log(FlickrSync.LogLevel.LogAll, "Replaced " + sf.FolderPath + " with " + potentialFolderPath + " based on previous alternate directory location");
                                sf.FolderPath = potentialFolderPath;
                                paths[i].use_count++;
                            }
                        }
                    }
                }
                if (!dir.Exists)
                {
                    if (FlickrSync.messages_level != FlickrSync.MessagesLevel.MessagesNone)
                    {
                        InformationBoxResult r = InformationBox.Show(
                            "Folder " + sf.FolderPath + " no longer exists. Remove from list of folders to sync?",
                            "Folder not found", InformationBoxButtons.YesNoUser1, new string[] { "Find on disk", String.Empty }, InformationBoxIcon.Exclamation, InformationBoxDefaultButton.Button2);
                        if (r == InformationBoxResult.Yes)
                        {
                            FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + "marked for removal from configuration");
                            continue;
                        }
                        else if (r == InformationBoxResult.User1)
                        {
                            Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog cofd = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog();
                            //cofd.InitialDirectory = oldpaths[oldpaths.Length-1];
                            cofd.Multiselect    = false;
                            cofd.IsFolderPicker = true;
                            if (cofd.ShowDialog() == Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogResult.Ok)
                            {
                                string        newfolderpath = cofd.FileName.ToString();
                                SearchReplace p             = new SearchReplace(sf.FolderPath, newfolderpath);
                                paths.Add(p);
                                FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + "replaced by " + newfolderpath + " in the configuration");
                                FlickrSync.Log(FlickrSync.LogLevel.LogAll, "From now on, we will try replacing " + p.oldpath + " by " + p.newpath);
                                sf.FolderPath = newfolderpath;
                            }
                            else
                            {
                                FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + "not replaced after all");
                                continue;
                            }
                        }
                        else
                        {
                            FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + "does not exists");
                        }
                    }
                }

                SyncFolders.Add(sf);
            }

            foreach (var p in paths)
            {
                if (p.use_count > 0)
                {
                    MessageBox.Show("Replaced Folder prefix " + p.oldpath + " with " + p.newpath + ((p.use_count == 1) ? " once" : " " + p.use_count.ToString() + " times"), "Info", MessageBoxButtons.OK);
                }
            }
            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);
            }
        }
Ejemplo n.º 17
0
        public string UploadPicture(string filename,string title,string description,ArrayList tags,FlickrSync.Permissions permission)
        {
            ArrayList specialtags = new ArrayList();
            foreach (string tag in tags)
            {
                if (tag.ToLower().StartsWith("flickrsync:") || tag.ToLower().StartsWith(@"""flickrsync:"))
                    specialtags.Add(tag);
            }

            foreach (string stag in specialtags)
            {
                tags.Remove(stag);

                string stag2=stag.ToLower();
                // To support picasa replace colons with equal sign (to be able to use flickrsync:perm:friends instead of flickrsync:perm=friends)
                stag2=stag2.Replace(':', '=');

                if (stag2.Contains("flickrsync=perm=private")) permission = FlickrSync.Permissions.PermPrivate;
                else if (stag2.Contains("flickrsync=perm=default")) permission = FlickrSync.Permissions.PermDefault;
                else if (stag2.Contains("flickrsync=perm=familyfriends")) permission = FlickrSync.Permissions.PermFamilyFriends;
                else if (stag2.Contains("flickrsync=perm=friends")) permission = FlickrSync.Permissions.PermFriends;
                else if (stag2.Contains("flickrsync=perm=family")) permission = FlickrSync.Permissions.PermFamily;
                else if (stag2.Contains("flickrsync=perm=public")) permission = FlickrSync.Permissions.PermPublic;
            }

            string tags_str = "";
            foreach (string tag in tags)
                if (tag.Length>0 && tag[0]=='"' && tag[tag.Length-1]=='"')
                    tags_str=tags_str+tag;
                else
                    tags_str = tags_str + @"""" + tag + @""" ";

            string id = "";
            if (permission==FlickrSync.Permissions.PermDefault)
                id=f.UploadPicture(filename,title,description,tags_str);
            else
                id=f.UploadPicture(filename,title,description,tags_str,
                    permission==FlickrSync.Permissions.PermPublic,
                    permission==FlickrSync.Permissions.PermFamily || permission==FlickrSync.Permissions.PermFamilyFriends,
                    permission==FlickrSync.Permissions.PermFriends || permission==FlickrSync.Permissions.PermFamilyFriends);

            // remove special tags. If there is an error it will be ignored (not very relevant)
            // they were removed previously from tags_str but flickr ignores this on upload
            try
            {
                foreach (string stag in specialtags)
                {
                    PhotoInfoTag[] taglist=f.TagsGetListPhoto(id);
                    foreach (PhotoInfoTag pit in taglist)
                        if (pit.Raw == stag)
                            f.PhotosRemoveTag(pit.TagId);
                }
            }
            catch (Exception)
            {
            }

            return id;
        }
Ejemplo n.º 18
0
        public string ReplacePicture(string filename,string photoid,string title,string caption,ArrayList tags,FlickrSync.Permissions permission,bool NoDeleteTags,double? GeoLat,double? GeoLong)
        {
            string id=f.ReplacePicture(filename, photoid);
            f.PhotosSetMeta(id, title, caption);

            ArrayList specialtags = new ArrayList();
            foreach (string tag in tags)
            {
                if (tag.ToLower().StartsWith("flickrsync:") || tag.ToLower().StartsWith(@"""flickrsync:"))
                    specialtags.Add(tag);
            }

            foreach (string stag in specialtags)
            {
                tags.Remove(stag);

                string stag2 = stag.ToLower();
                // To support picasa replace colons with equal sign (to be able to use flickrsync:perm:friends instead of flickrsync:perm=friends)
                stag2=stag2.Replace(':', '=');

                if (stag2.Contains("flickrsync=perm=private")) permission = FlickrSync.Permissions.PermPrivate;
                else if (stag2.Contains("flickrsync=perm=default")) permission = FlickrSync.Permissions.PermDefault;
                else if (stag2.Contains("flickrsync=perm=familyfriends")) permission = FlickrSync.Permissions.PermFamilyFriends;
                else if (stag2.Contains("flickrsync=perm=friends")) permission = FlickrSync.Permissions.PermFriends;
                else if (stag2.Contains("flickrsync=perm=family")) permission = FlickrSync.Permissions.PermFamily;
                else if (stag2.Contains("flickrsync=perm=public")) permission = FlickrSync.Permissions.PermPublic;
            }

            f.PhotosSetPerms(id,
                permission == FlickrSync.Permissions.PermPublic,
                permission == FlickrSync.Permissions.PermFriends || permission == FlickrSync.Permissions.PermFamilyFriends,
                permission == FlickrSync.Permissions.PermFamily || permission == FlickrSync.Permissions.PermFamilyFriends,
                PermissionComment.Everybody, PermissionAddMeta.Everybody);

            string user=f.AuthCheckToken(Properties.Settings.Default.FlickrToken).User.UserId;

            PhotoInfoTag[] ftags = f.TagsGetListPhoto(id); //.Tags.TagCollection;

            if (ftags != null)
            {
                foreach (PhotoInfoTag ftag in ftags)
                {
                    if (ftag.AuthorId == user)
                    {
                        bool found = false;
                        for (int i = 0; i < tags.Count; i++)
                        {
                            if ((string)tags[i] == ftag.Raw)
                            {
                                found = true;
                                tags.RemoveAt(i);
                                break;
                            }
                        }

                        if (!found && !NoDeleteTags)
                            f.PhotosRemoveTag(ftag.TagId);
                    }
                }
            }

            foreach (string tag in tags)
            {
                if (tag.Length > 0 && tag[0] == '"' && tag[tag.Length - 1] == '"')
                    f.PhotosAddTags(id, tag);
                else
                    f.PhotosAddTags(id, @"""" + tag + @"""");
            }

            if (GeoLat != null && GeoLong != null)
            {
                try
                {
                    f.PhotosGeoSetLocation(id, (double)GeoLat, (double)GeoLong);
                }
                catch (Exception ex)
                {
                    FlickrSync.Error("Error setting Geo location: " + filename + " Lat=" + GeoLat + " Long=" + GeoLong,  ex, FlickrSync.ErrorType.Normal);
                }
            }

            return id;
        }