source: extensions/Picasa2Piwigo/Picasa2Piwigo/StatusForm.cs @ 32020

Last change on this file since 32020 was 30536, checked in by kenl, 9 years ago

Version 1.4

File size: 59.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using System.Diagnostics;
10using System.IO;
11using System.Net;
12using System.Xml;
13using System.Resources;
14using System.Globalization;
15using System.Threading;
16using Picasa2PiwigoConstants;
17
18namespace Picasa2Piwigo
19{
20    using Picasa2PiwigoConstants;
21    using Picasa2PiwigoCommonFunctions;
22
23    public partial class StatusForm : Form
24    {
25        bool stop_button_pressed = false;
26        int command_to_run;
27        string[] local_command_line_args;
28        int[] piwigo_person_tag_count = new int[constants.MAX_NUMBER_OF_CONTACTS];
29 
30        CookieContainer cookiesjar = new CookieContainer();
31        public StatusForm(int command, string[] command_line_args)
32        {
33            CultureInfo ci;
34            ci = new CultureInfo(Thread.CurrentThread.CurrentCulture.Name);
35            Thread.CurrentThread.CurrentUICulture = ci;
36            Thread.CurrentThread.CurrentCulture = ci;
37            if (Picasa2PiwigoConstants.constants.DEBUG_LOCALE)
38            {
39#pragma warning disable 0162
40                Thread.CurrentThread.CurrentUICulture = new CultureInfo(Picasa2PiwigoConstants.constants.SET_LOCALE);
41#pragma warning restore 0162
42            }
43                InitializeComponent();
44                command_to_run = command;
45                local_command_line_args = command_line_args;           
46        }
47
48        private void StatusForm_Load(object sender, EventArgs e)
49        {
50            bool step_passed;
51            XmlDocument TagList = new XmlDocument();
52            XmlDocument AlbumList = new XmlDocument();
53            int NewPiwigoAlbumId;
54            string PiwigoVersionNumber;
55
56            this.button1.Text = WinFormStrings.SFbutton1StrRes;
57            this.Text = WinFormStrings.SFCaptionsStrRes;
58            this.label1.Text = WinFormStrings.SFlabel1StrRes;
59
60            LabelAdjust AdjustLabelClass = new LabelAdjust();
61            AdjustLabelClass.AdjustLabelSize(label1);
62            AdjustLabelClass.AdjustButtonSize(button1);
63
64            DialogResult = DialogResult.Yes;
65            this.Show();
66            StatusRefresh();
67
68            //4.  Retrieve tags
69            //SetStatus("Retrieving tags...");
70            //step_passed = UpdateStatus(SyncPiwigoGetTags(ref TagList));
71            //if (!step_passed)
72           // {
73            //    return;
74            //}
75
76            switch (command_to_run)
77            {
78                case constants.COMMAND_START_UP:
79                    logit.WriteLog("Start up");
80
81                    //1.  Reading Picasa contacts
82                    SetStatus(WinFormStrings.ReadContactsFileStrRes);                   
83                    step_passed = UpdateStatus((SyncPiwigoReadPicasaContacts()));
84                    if (stop_button_pressed)
85                    {
86                        return;
87                    }
88                    if (!step_passed)
89                    {
90                        return;
91                    }
92
93                    logit.WriteLog("Read picasa contacts");   
94                    //2.  Validate that server can be reached                   
95                    SetStatus(WinFormStrings.CheckServerConnStrRes);
96                    step_passed = UpdateStatus((SyncPiwigoCheckServerStatus()));
97                    if (!step_passed)
98                    {
99                        return;
100                    }
101                    if (stop_button_pressed)
102                    {
103                        return;
104                    }
105
106                    //3.  Login                   
107                    logit.WriteLog("logging in");   
108                    SetStatus(WinFormStrings.LogInStrRes);
109                    step_passed = UpdateStatus(SyncPiwigoLogIn());
110                    if (!step_passed)
111                    {
112                        return;
113                    }
114                    if (stop_button_pressed)
115                    {
116                        return;
117                    }
118
119                    //4.  Get Piwigo Version
120                    PiwigoVersionNumber = "";
121                    logit.WriteLog("getting version number from piwigo");   
122                    SetStatus(WinFormStrings.GetPiwigoVersionStrRes);
123                    step_passed = UpdateStatus(SyncPiwigoGetVersion(ref PiwigoVersionNumber));
124                    if (stop_button_pressed)
125                    {
126                        return;
127                    }
128                    GlobalClass.PiwigoVersionNumber = PiwigoVersionNumber;                   
129
130                    //5.  Get list of albums
131                    logit.WriteLog("getting list of albums from piwigo");   
132                    SetStatus(WinFormStrings.RetrieveAlbumListStRes);
133                    step_passed = UpdateStatus(SyncPiwigoGetAlbums(ref AlbumList));
134                    if (step_passed)
135                    {
136                        GlobalClass.AlbumList = AlbumList;
137                        return;
138                    }
139                    if (stop_button_pressed)
140                    {
141                        return;
142                    }
143                break;
144
145                case constants.COMMAND_ADD_TO_ALBUM:
146                    logit.WriteLog("Add to Album");
147
148                    //1.  Validate that server can be reached
149                    SetStatus(WinFormStrings.CheckServerConnStrRes);
150                    step_passed = UpdateStatus((SyncPiwigoCheckServerStatus()));
151                    if (!step_passed)
152                    {
153                        return;
154                    }
155                    if (stop_button_pressed)
156                    {
157                        return;
158                    }
159
160                    //2.  Login
161                    SetStatus(WinFormStrings.LogInStrRes);
162                    step_passed = UpdateStatus(SyncPiwigoLogIn());
163                    if (!step_passed)
164                    {
165                        return;
166                    }
167                    if (stop_button_pressed)
168                    {
169                        return;
170                    }
171                   
172                    //3.  upload photos
173                    NewPiwigoAlbumId = GlobalClass.AddAlbumCategoryID;
174                    SetStatus(WinFormStrings.UploadPhotosStrRes);
175                    step_passed = UpdateStatus(SyncPiwigoAddPhoto(NewPiwigoAlbumId));
176                    if (!step_passed)
177                    {
178                        return;
179                    }
180                    if (stop_button_pressed)
181                    {
182                        return;
183                    }
184
185                break;
186
187                case constants.COMMAND_NEW_ALBUM:
188                    logit.WriteLog("New Album");
189
190                    //1.  Validate that server can be reached
191                    SetStatus(WinFormStrings.CheckServerConnStrRes);
192                    step_passed = UpdateStatus((SyncPiwigoCheckServerStatus()));
193                    if (!step_passed)
194                    {
195                        return;
196                    }
197                    if (stop_button_pressed)
198                    {
199                        return;
200                    }
201
202                    //2.  Login
203                    SetStatus(WinFormStrings.LogInStrRes);
204                    step_passed = UpdateStatus(SyncPiwigoLogIn());
205                    if (!step_passed)
206                    {
207                        return;
208                    }
209                    if (stop_button_pressed)
210                    {
211                        return;
212                    }
213
214                    //3. Create new album
215                    SetStatus(WinFormStrings.CreateNewAlbumRes);
216                    NewPiwigoAlbumId = -1;
217                    step_passed = UpdateStatus(SyncPiwigoCreateAlbum(ref NewPiwigoAlbumId));
218                    if (!step_passed)
219                    {
220                        return;
221                    }
222                    if (stop_button_pressed)
223                    {
224                        return;
225                    }
226
227                    //4.  upload photos                   
228                    SetStatus(WinFormStrings.UploadPhotosStrRes);
229                    step_passed = UpdateStatus(SyncPiwigoAddPhoto(NewPiwigoAlbumId));
230                    if (!step_passed)
231                    {
232                        return;
233                    }
234                    if (stop_button_pressed)
235                    {
236                        return;
237                    }
238
239                break;
240            }
241        }
242
243        public int SearchForNameXML(byte[] filedata, byte[] name_sig, int k, int exif_length)
244        {
245
246            byte firstByte = name_sig[0];
247            int index = -1;
248            int n, match_count;
249
250            n = k;
251            do
252            {
253                match_count = 0;
254                if ((index = Array.IndexOf(filedata, firstByte, n)) >= 0)
255                {
256                    for (int i = 0; i < name_sig.Length; i++)
257                    {
258                        if (index + i > exif_length - 2)
259                        {
260                            break;
261                        }
262                        if (name_sig[i] != filedata[index + i])
263                        {
264                            break;
265                        }
266                        else
267                        {
268                            match_count++;
269                        }
270                    }
271                    if (match_count == name_sig.Length)
272                    {
273                        //found a person
274                        return index + name_sig.Length;
275                    }
276                }
277                n = index + 1;
278            } while (index != -1);
279            return index;
280        }
281        private static int ByteSearch(byte[] searchIn, byte[] searchBytes, int start)
282        {
283            int found = -1;
284            bool matched = false;
285            //only look at this if we have a populated search array and search bytes with a sensible start
286            if (searchIn.Length > 0 && searchBytes.Length > 0 && start <= (searchIn.Length - searchBytes.Length) && searchIn.Length >= searchBytes.Length)
287            {
288                //iterate through the array to be searched
289                for (int i = start; i <= searchIn.Length - searchBytes.Length; i++)
290                {
291                    //if the start bytes match we will start comparing all other bytes
292                    if (searchIn[i] == searchBytes[0])
293                    {
294                        if (searchIn.Length > 1)
295                        {
296                            //multiple bytes to be searched we have to compare byte by byte
297                            matched = true;
298                            for (int y = 1; y <= searchBytes.Length - 1; y++)
299                            {
300                                if (searchIn[i + y] != searchBytes[y])
301                                {
302                                    matched = false;
303                                    break;
304                                }
305                            }
306                            //everything matched up
307                            if (matched)
308                            {
309                                found = i;
310                                break;
311                            }
312         
313                        }
314                        else
315                        {
316                            //search byte is only one bit nothing else to do
317                            found = i;
318                            break; //stop the loop
319                        }
320         
321                    }
322                }
323         
324            }
325            return found;
326        }
327        public string GetCommentListFromXml(string xmlstring)
328        {
329            string tag_list, s;
330            int j, k, l, m, n;
331
332            tag_list = "";
333            k = xmlstring.IndexOf("<dc:description>");
334            if (k != -1)
335            {
336                l = xmlstring.IndexOf("/dc:description", k);
337                if (l != -1)
338                {
339                    j = k;
340                    do
341                    {
342                        j = xmlstring.IndexOf("<rdf:li", j+1);
343                        if (j != -1 && j < l)
344                        {
345                            n = xmlstring.IndexOf(">", j);
346                            if (n != -1 && n < l)
347                            {
348                                m = xmlstring.IndexOf("</rdf:li>", j);
349                                if (m != -1 && m < l)
350                                {
351                                    s = xmlstring.Substring(n + 1, m - n - 1);
352                                    tag_list += RemoveCommaFromContract(s);
353                                    tag_list += ",";
354                                }
355                            }
356                        }
357                    } while (j != -1);
358                }
359            }
360            if (tag_list.Length > 1)
361            {
362                tag_list = tag_list.Substring(0, tag_list.Length - 1);
363            }
364
365            return tag_list;
366        }
367
368        public string GetTagListFromXml(string xmlstring)
369        {
370            string tag_list, s;
371            int j, k, l, m;
372
373            tag_list = "";
374            k = xmlstring.IndexOf("<dc:subject>");
375            if (k != -1)
376            {
377                l = xmlstring.IndexOf("</dc:subject>",k);
378                if (l != -1)
379                {
380                    j = k;
381                    do
382                    {
383                        j = xmlstring.IndexOf("<rdf:li>", j+1);
384                        if (j != -1 && j < l)
385                        {
386                            m = xmlstring.IndexOf("</rdf:li>", j);
387                            if (m != -1 && m < l)
388                            {
389                                s = xmlstring.Substring(j + 8, m - j - 8);
390                                tag_list += RemoveCommaFromContract(s);
391                                tag_list += ",";
392                            }
393                        }
394                    } while (j != -1);
395                }
396            }
397            if (tag_list.Length > 1)
398            {
399                tag_list = tag_list.Substring(0, tag_list.Length - 1);
400            }
401
402            return tag_list;
403        }
404
405        public void SyncPiwigoGetTagsandComments(ref string tag_list, ref string comment_list, string filename)
406        {
407            byte[] filedata = new byte[100 * 1024];
408            byte[] name_sig = new byte[] {0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 
409                0x70, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x6D, 0x77, 0x67, 0x2D, 0x72, 0x73, 0x3A, 
410                0x4E, 0x61, 0x6D, 0x65, 0x3D, 0x22 };
411            int temp1, temp2, k, i, l, m;
412            UInt16 signature, exif_length;
413            byte[] temp_array = new byte[1];
414            byte[] xml_start = { 0x3C, 0x78, 0x3A, 0x78, 0x6D, 0x70, 0x6D, 0x65, 0x74, 0x61 };
415            byte[] xml_end = { 0x3C, 0x2F, 0x78, 0x3A, 0x78, 0x6D, 0x70, 0x6D, 0x65, 0x74, 0x61, 0x3E };
416            string xml_content;
417            XmlDocument xmldoc = new XmlDocument();
418           
419            try
420            {
421                BinaryReader b = new BinaryReader(File.Open(filename, FileMode.Open));
422
423                signature = b.ReadUInt16();
424                if (signature != 0xD8FF)
425                {
426                    b.Close();
427                    return;
428                }
429                signature = b.ReadUInt16();
430                if (signature != 0xE1FF && signature != 0xE0FF)
431                {
432                    b.Close();
433                    return;
434                }
435                for (i = 0; i < 2; i++)
436                {
437                    //get length
438                    temp1 = b.ReadByte();
439                    temp2 = b.ReadByte();
440                    exif_length = (UInt16)((temp1 << 8) + temp2);
441                    filedata = b.ReadBytes(exif_length - 1);
442
443                    //search file data for xml
444                    l = -1;
445                    k = ByteSearch(filedata, xml_start, 0);
446                    if (k != -1)
447                    {
448                        l = ByteSearch(filedata, xml_end, k);
449                    }
450
451                    if (k != -1 && l != -1)
452                    {
453                        xml_content = System.Text.Encoding.UTF8.GetString(filedata, k, l - k + xml_end.Length);
454                        tag_list = GetTagListFromXml(xml_content);
455                        comment_list = GetCommentListFromXml(xml_content);
456                        break;
457                    }
458                    m = exif_length;
459                    if (m > filedata.Length)
460                    {
461                        m = filedata.Length + 1;
462                    }
463                    Array.Clear(filedata, 0, m - 1);
464                }
465
466
467                b.Close();
468            }
469            catch (IOException e)
470            {
471                e.ToString();
472                return;
473            }
474            catch (Exception e)
475            {
476                e.ToString();
477                return;
478            }
479
480
481        }
482        public void SearchForNamesInExif(ref bool[] found_contact_in_photo_array, constants.PersonIDStruct[] contact_array, string filename, int person_count)
483        {
484            byte[] filedata = new byte[100 * 1024];
485            byte[] name_sig = new byte[] {0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 
486                0x70, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x6D, 0x77, 0x67, 0x2D, 0x72, 0x73, 0x3A, 
487                0x4E, 0x61, 0x6D, 0x65, 0x3D, 0x22 };
488            int temp1, temp2, k, l, i, m, LengthToConvert;
489            UInt16 signature, exif_length;
490            string name_from_photo, tempstr;
491            byte[] temp_array = new byte[4];
492
493            try
494            {
495                BinaryReader b = new BinaryReader(File.Open(filename, FileMode.Open));
496
497                signature = b.ReadUInt16();
498                if (signature != 0xD8FF)
499                {
500                    b.Close();
501                    return;
502                }
503                signature = b.ReadUInt16();
504                if (signature != 0xE1FF && signature != 0xE0FF)
505                {
506                    b.Close();
507                    return;
508                }
509                for (i = 0; i < 2; i++)
510                {
511                    //get length
512                    temp1 = b.ReadByte();
513                    temp2 = b.ReadByte();
514                    exif_length = (UInt16)((temp1 << 8) + temp2);
515                    filedata = b.ReadBytes(exif_length - 1);
516                    k = 0;
517                    do
518                    {
519                        k = SearchForNameXML(filedata, name_sig, k, exif_length);
520                        if (k != -1)
521                        {
522                            name_from_photo = "";
523                            //found a name
524                            if (k >= exif_length - 5)
525                            {
526                                //just in case we're trying to read beyond end of filedata
527                                //probably will never happen
528                                logit.WriteLog("Read to end of xml");
529                                break;
530                            }
531                            temp_array[0] = filedata[k];
532                            temp_array[1] = filedata[k + 1];
533                            temp_array[2] = filedata[k + 2];
534                            temp_array[3] = filedata[k + 3];
535                            //tempstr = Encoding.UTF8.GetString(filedata);
536                            if (exif_length - k > 1024)
537                            {
538                                LengthToConvert = 1024;
539                            }
540                            else
541                            {
542                                LengthToConvert = exif_length - k;
543                            }
544                            if (LengthToConvert < 3)
545                            {
546                                logit.WriteLog("Too close to end of xml");
547                                break;
548                            }
549                            tempstr = Encoding.UTF8.GetString(filedata, k, LengthToConvert);
550                            l = tempstr.IndexOf("\"");
551                            if (l != -1)
552                            {
553                                tempstr = tempstr.Substring(0, l);
554                                k += tempstr.Length;
555                                name_from_photo = tempstr;
556
557                                if (name_from_photo.Substring(0, 1) == "0")
558                                {
559                                    name_from_photo = name_from_photo.Substring(1);
560                                }
561                                //have name, search for it in array
562                                for (i = 0; i < person_count; i++)
563                                {
564                                    if (name_from_photo == contact_array[i].name)
565                                    {
566                                        found_contact_in_photo_array[i] = true;
567                                        break;
568                                    }
569                                }
570                            }
571                            else
572                            {
573                                //couldn't find end of name, abort
574                                logit.WriteLog("couldn't find end of name: " + tempstr);
575                                break;
576                            }
577                        }
578                        k++;
579                    } while (k != 0);
580                    m = exif_length;
581                    if (m > filedata.Length)
582                    {
583                        m = filedata.Length + 1;
584                    }
585                    Array.Clear(filedata, 0, m - 1);
586                }
587
588
589                b.Close();
590            }
591            catch (IOException e)
592            {
593                e.ToString();
594                return;
595            }
596            catch (Exception e)
597            {
598                e.ToString();
599                return;
600            }
601        }
602        public string RemoveCommaFromContract(string contact)
603        {
604            string cleaned_name, s, t;
605            int k;
606
607            cleaned_name = contact;
608
609            //do we have to remove commma
610            if (HaveToRemoveComma())
611            {
612                do
613                {
614                    k = cleaned_name.IndexOf(",");
615                    if (k != -1)
616                    {
617                        s = cleaned_name.Substring(0, k);
618                        t = cleaned_name.Substring(k + 1);
619                        cleaned_name = s + t;
620                    }
621                } while (k != -1);
622            }
623            else
624            {
625                //commas are ok, so escape them
626                cleaned_name = cleaned_name.Replace(",", "/,");
627            }
628            return cleaned_name;
629        }
630        public string SyncPiwigoGetFaceTags(string filename)
631        {
632            int k, l;
633            string filepath, inidata, photofilename, photo_file_name, ini_unique_id;
634            string face_tag_list;
635            bool[] found_contact_in_photo_array = new bool[Picasa2PiwigoConstants.constants.MAX_NUMBER_OF_CONTACTS];
636            bool found_photo;
637            bool finished_faces, found_person;
638            System.IO.StreamReader inifile;
639
640            face_tag_list = "";
641
642            k = filename.LastIndexOf("\\");
643            filepath = filename.Substring(0, k);
644            photofilename = filename.Substring(k + 1);
645            photo_file_name = "";
646
647            //if it's a video file then skip it
648            if (!CheckFileNameExtension(photofilename.ToLower()))
649            {
650                return face_tag_list;
651            }
652
653            //parse photo
654            for (k = 0; k < GlobalClass.person_count; k++)
655            {
656                found_contact_in_photo_array[k] = false;
657            }
658            SearchForNamesInExif(ref found_contact_in_photo_array, GlobalClass.contact_array, filename, GlobalClass.person_count);
659            for (k = 0; k < GlobalClass.person_count; k++)
660            {
661                if (found_contact_in_photo_array[k])
662                {
663                    face_tag_list += RemoveCommaFromContract(GlobalClass.contact_array[k].name) + ",";
664                }
665            }
666
667            inifile = null;
668            if (File.Exists(filepath + "\\.picasa.ini"))
669            {
670                logit.WriteLog("picasa.ini file exists");
671                try
672                {
673                    inifile = new System.IO.StreamReader(filepath + "\\.picasa.ini");
674                }
675                catch
676                {
677                    if (face_tag_list.Length > 1)
678                    {
679                        face_tag_list = face_tag_list.Substring(0, face_tag_list.Length - 1);
680                    }
681                    return face_tag_list;
682                }
683            }
684            else if (File.Exists(filepath + "\\Picasa.ini"))
685            {
686                logit.WriteLog("Picasa.ini file exists");
687                try
688                {
689                    inifile = new System.IO.StreamReader(filepath + "\\Picasa.ini");
690                }
691                catch
692                {
693                    if (face_tag_list.Length > 1)
694                    {
695                        face_tag_list = face_tag_list.Substring(0, face_tag_list.Length - 1);
696                    }
697                    return face_tag_list;
698                }
699            } 
700           
701            k = 0;
702            found_photo = false;
703            if (inifile != null)
704            {
705                while ((inidata = inifile.ReadLine()) != null)
706                {                   
707                    if (inidata.Length > 4)
708                    {
709                        if (inidata.Substring(0, 1) == "[")
710                        {
711                            found_photo = false;
712                            k = inidata.IndexOf("]");                           
713                            if (k != -1)
714                            {
715                                photo_file_name = inidata.Substring(1, k - 1);
716                            }
717                            if (photo_file_name.ToUpper() != photofilename.ToUpper())
718                            {
719                                continue;
720                            }
721
722                            if (CheckFileNameExtension(photo_file_name.ToLower()))
723                            {
724                                found_photo = true;
725                            }
726                        }
727                        else if (inidata.Substring(0, 6) == "faces=" && found_photo)
728                        {
729                            finished_faces = false;
730                            k = 0;
731                            do
732                            {
733                                k = inidata.IndexOf("),", k);
734                                if (k != -1)
735                                {
736                                    l = inidata.IndexOf(";", k);
737                                    if (l == -1)
738                                    {
739                                        l = inidata.Length;
740                                    }
741                                    if (l != -1)
742                                    {
743                                        ini_unique_id = inidata.Substring(k + 2, l - k - 2);
744
745                                        //found face in a picture, but who?
746                                        l = 0;
747                                        found_person = false;
748                                        do
749                                        {
750                                            if (GlobalClass.picasa_unique_id_arrary[l].unique_id == ini_unique_id)
751                                            {
752                                                //did we already find this person?
753                                                if (found_contact_in_photo_array[l] == false)
754                                                {
755                                                    found_person = true;
756                                                    break;
757                                                }
758                                            }
759                                            l++;
760                                        } while (l < GlobalClass.unique_id_count);
761
762                                        //found person
763                                        if (found_person)
764                                        {
765                                            if (photo_file_name.Length > 3)
766                                            {
767                                                face_tag_list += GlobalClass.contact_array[l].name + ",";
768                                                logit.WriteLog("face_tag_list:  " + face_tag_list);
769                                            }
770                                        }
771                                    }
772                                    k++;
773                                }
774                                else
775                                {
776                                    finished_faces = true;
777                                }
778                            } while (!finished_faces);
779                        }
780                    }
781                }
782            }
783            //remove last comma
784            if (face_tag_list.Length > 1)
785            {
786                logit.WriteLog("end face_tag_list:  " + face_tag_list);
787                face_tag_list = face_tag_list.Substring(0, face_tag_list.Length - 1);
788            }
789            return face_tag_list;
790        }
791        public bool SyncPiwigoReadPicasaContacts()
792        {
793            int i, k, l;
794            string filedata, person_str, unique_id;
795            bool person_exists;
796            System.IO.StreamReader file;
797
798            try
799            {
800                file = new System.IO.StreamReader(FormSettings.Default.PicasaContactsLocation);
801            }
802            catch (Exception e)
803            {
804                GlobalClass.StatusDialogErrorMessage = WinFormStrings.UnableToOpenContactsStrRes + "  " + 
805                    e.Message;
806                return false;
807            }
808
809            for (i = 0; i < constants.MAX_NUMBER_OF_CONTACTS; i++)
810            {
811                piwigo_person_tag_count[i] = 0;
812            }
813            GlobalClass.person_count = 0;
814            GlobalClass.unique_id_count = 0;
815            while ((filedata = file.ReadLine()) != null)
816            {
817                //parse name and unique id
818                k = filedata.IndexOf("contact id=");
819                if (k != -1)
820                {
821                    unique_id = filedata.Substring(k + 12, 16);
822                    k = filedata.IndexOf("name=");
823                    l = filedata.IndexOf("\"", k + 6);
824                    person_str = filedata.Substring(k + 6, (l - k - 6));
825                    Debug.WriteLine("Person: " + person_str + " ID: " + unique_id);
826                    //does this person already exist
827                    person_exists = false;
828                    for (i = 0; i < GlobalClass.person_count; i++)
829                    {
830                        if (person_str == GlobalClass.contact_array[i].name)
831                        {
832                            person_exists = true;
833                            break;
834                        }
835                    }
836
837                    if (!person_exists)
838                    {
839                        GlobalClass.contact_array[GlobalClass.person_count].name = person_str;
840                        GlobalClass.contact_array[GlobalClass.person_count].index = GlobalClass.person_count;
841                        GlobalClass.picasa_unique_id_arrary[GlobalClass.unique_id_count].unique_id = unique_id;
842                        GlobalClass.picasa_unique_id_arrary[GlobalClass.unique_id_count].index = GlobalClass.person_count;
843                        GlobalClass.person_count++;
844                        if (GlobalClass.person_count >= constants.MAX_NUMBER_OF_CONTACTS)
845                        {
846                            GlobalClass.StatusDialogErrorMessage = WinFormStrings.TooManyPeopleTags;
847                            return false;   
848                        }
849                    }
850                    else
851                    {
852                        GlobalClass.picasa_unique_id_arrary[GlobalClass.unique_id_count].unique_id = unique_id;
853                        GlobalClass.picasa_unique_id_arrary[GlobalClass.unique_id_count].index = i;
854                    }
855                    GlobalClass.unique_id_count++;
856                }
857                Debug.WriteLine("Number of contacts: " + GlobalClass.person_count.ToString());
858            }           
859            return true;
860        }
861        public bool SyncPiwigoCheckServerStatus()
862        {
863            string WebResponse, WebRequest, xmlResponse;
864
865            WebRequest = FormSettings.Default.PiwigoUrlSetting + "/ws.php?method=pwg.session.getStatus";
866            logit.WriteLog(WebRequest);
867
868            WebResponse = SendWebGet(WebRequest);
869            logit.WriteLog(WebResponse);
870
871            if (WebResponse.IndexOf("An error occurred:") != -1)
872            {
873                GlobalClass.StatusDialogErrorMessage = WebResponse;
874                return false;
875            }
876
877            xmlResponse = XmlGetAttribute(FilterForXML(WebResponse), "stat");
878            if (xmlResponse == "ok")
879            {
880                return true;
881            }
882            GlobalClass.StatusDialogErrorMessage = WinFormStrings.UnableToContactServerStrRes;
883            return false;
884        }
885        public bool SyncPiwigoLogIn()
886        {
887            string WebResponse, WebRequest, xmlResponse, PostData;
888            byte[] dummy_data = new byte[1];
889            bool response;
890
891            dummy_data[0] = 0;
892            WebRequest = FormSettings.Default.PiwigoUrlSetting + "/ws.php?method=pwg.session.login";           
893            PostData = "username=" + FormSettings.Default.PiwigoUserName + "&password=" + FormSettings.Default.PiwigoPassword;
894            logit.WriteLog(WebRequest);
895            logit.WriteLog("username=" + FormSettings.Default.PiwigoUserName + "&password=" + "*****");
896            response = SendWebPost(WebRequest, PostData, "application/x-www-form-urlencoded");           
897            if (!response)
898            {
899                logit.WriteLog("Log In Post Fail.");
900                return false;
901            }
902            WebRequest = FormSettings.Default.PiwigoUrlSetting + "/ws.php?method=pwg.session.getStatus";
903            logit.WriteLog(WebRequest);
904            WebResponse = SendWebGet(WebRequest);
905            logit.WriteLog(WebResponse);
906            if (WebResponse.IndexOf("An error occurred:") != -1)
907            {
908                GlobalClass.StatusDialogErrorMessage = WebResponse;
909                return false;
910            }
911            xmlResponse = XmlGetElement(FilterForXML(WebResponse), "username");
912            if (xmlResponse == FormSettings.Default.PiwigoUserName)
913            {
914                return true;
915            }
916            GlobalClass.StatusDialogErrorMessage = WinFormStrings.UnableToLogInStrRes;
917            return false;
918        }
919
920        public bool SyncPiwigoGetVersion(ref string PiwigoVersionNumber)
921        {
922            string WebResponse, WebRequest, xmlResponse;
923
924            WebRequest = FormSettings.Default.PiwigoUrlSetting + "/ws.php?method=pwg.getVersion";
925            logit.WriteLog(WebRequest);
926
927            WebResponse = SendWebGet(WebRequest);
928            logit.WriteLog(WebResponse);
929
930            PiwigoVersionNumber = "";
931            if (WebResponse.IndexOf("An error occurred:") != -1)
932            {
933                GlobalClass.StatusDialogErrorMessage = WebResponse;
934                return false;
935            }
936
937            xmlResponse = XmlGetAttribute(FilterForXML(WebResponse), "stat");
938            if (xmlResponse != "ok")
939            {
940                GlobalClass.StatusDialogErrorMessage = WinFormStrings.UnableToGetVersionStrRes;
941                return false;
942            }
943
944            PiwigoVersionNumber = XmlGetElement(FilterForXML(WebResponse), "rsp");
945            PiwigoVersionNumber = PiwigoVersionNumber.Substring(1);
946            PiwigoVersionNumber = PiwigoVersionNumber.Substring(0,PiwigoVersionNumber.Length -1);
947            return true;
948        }
949        public bool SyncPiwigoGetAlbums(ref XmlDocument AlbumList)
950        {
951            string WebResponse, WebRequest, xmlResponse;
952            int piwigo_minor_version;
953
954            piwigo_minor_version = Convert.ToInt32(GlobalClass.PiwigoVersionNumber.Substring(2, 1));
955            if (piwigo_minor_version >= 6)
956            {
957                WebRequest = FormSettings.Default.PiwigoUrlSetting + "/ws.php?method=pwg.categories.getList&fullname=true&recursive=true";
958            }
959            else
960            {
961                WebRequest = FormSettings.Default.PiwigoUrlSetting + "/ws.php?method=pwg.categories.getList&fullname=\"true\"&recursive=\"false\"";
962            }
963
964            logit.WriteLog(WebRequest);
965
966            WebResponse = SendWebGet(WebRequest);
967            logit.WriteLog(WebResponse);
968
969            if (WebResponse.IndexOf("An error occurred:") != -1)
970            {
971                GlobalClass.StatusDialogErrorMessage = WebResponse;
972                return false;
973            }
974            xmlResponse = XmlGetAttribute(FilterForXML(WebResponse), "stat");
975            if (xmlResponse == "ok")
976            {
977                AlbumList.LoadXml(FilterForXML(WebResponse));
978                return true;
979            }
980            GlobalClass.StatusDialogErrorMessage = WinFormStrings.UnableToRetreiveAlbumStrRes;
981            return false;
982        }
983        public bool SyncPiwigoGetTags(ref XmlDocument TagList)
984        {
985            string WebResponse, WebRequest, xmlResponse;
986
987            WebRequest = FormSettings.Default.PiwigoUrlSetting + "/ws.php?method=pwg.tags.getList";
988            logit.WriteLog(WebRequest);
989
990            WebResponse = SendWebGet(WebRequest);
991            logit.WriteLog(WebResponse);
992
993            if (WebResponse.IndexOf("An error occurred:") != -1)
994            {
995                GlobalClass.StatusDialogErrorMessage = WebResponse;
996                return false;
997            }
998            xmlResponse = XmlGetAttribute(FilterForXML(WebResponse), "stat");
999            if (xmlResponse == "ok")
1000            {
1001                TagList.LoadXml(FilterForXML(WebResponse));
1002                return true;
1003            }
1004            GlobalClass.StatusDialogErrorMessage = WinFormStrings.UnableToRetreiveTagsStrRes;
1005            return false;
1006        }
1007        public bool SyncPiwigoCreateAlbum(ref int NewPiwigoAlbumID)
1008        {
1009            string WebResponse, WebRequest, xmlResponse, tempstr;
1010
1011            NewPiwigoAlbumID = -1;
1012            WebRequest = FormSettings.Default.PiwigoUrlSetting + "/ws.php?method=pwg.categories.add&name=" 
1013                +  GlobalClass.NewAlbumName;
1014            if (Form1Settings.Default.AccessValue == WinFormStrings.PublicStrRes)
1015            {
1016                tempstr = "public";
1017            }
1018            else
1019            {
1020                tempstr = "private";
1021            }           
1022            WebRequest += "&status=" + tempstr;
1023            if (GlobalClass.NewAlbumNameParentID != -1)
1024            {
1025                WebRequest += "&parent=" + GlobalClass.NewAlbumNameParentID.ToString();
1026            }
1027
1028            if (GlobalClass.NewAlbumDescription.Length != 0)
1029            {
1030                WebRequest += "&comment=" + GlobalClass.NewAlbumDescription;
1031            }
1032
1033            logit.WriteLog(WebRequest);
1034
1035            WebResponse = SendWebGet(WebRequest);
1036            logit.WriteLog(WebResponse);
1037
1038            if (WebResponse.IndexOf("An error occurred:") != -1)
1039            {
1040                GlobalClass.StatusDialogErrorMessage = WebResponse;
1041                return false;
1042            }
1043            xmlResponse = XmlGetAttribute(FilterForXML(WebResponse), "stat");
1044            if (xmlResponse == "ok")
1045            {
1046                NewPiwigoAlbumID = Convert.ToInt32(XmlGetElement(FilterForXML(WebResponse), "id"));               
1047                return true;
1048            }
1049            GlobalClass.StatusDialogErrorMessage = WinFormStrings.UnableToCreateAlbumStrRes;
1050            return false;   
1051        }
1052        public bool SyncPiwigoAddPhoto(int NewPiwigoAlbumId)
1053        {
1054            int i,k, di;
1055            string WebResponse, WebRequest, xmlResponse, filename;
1056            byte[] PhotoFileContents;
1057            string [] file_to_send = {local_command_line_args[0]};
1058            string[,] post_array = new string[10,2];
1059            string image_id, filtered_xml;
1060            bool upload_failed, response;
1061            string face_tag_list, tag_list, comment_list, all_tags;
1062
1063            upload_failed = false;
1064            for (i = 0; i < local_command_line_args.Length; i++)
1065            {
1066                if (stop_button_pressed)
1067                {
1068                    return false;
1069                }
1070
1071                SetStatus(WinFormStrings.UploadingPHotoStrRes + " " + (i + 1).ToString() + " " + WinFormStrings.ofStrREf + " " + local_command_line_args.Length.ToString() + "...");
1072
1073                k = local_command_line_args[i].LastIndexOf("\\");
1074                filename = local_command_line_args[i].Substring(k + 1);
1075                if (CheckFileNameExtension(filename.ToLower()))
1076                {
1077                    face_tag_list = SyncPiwigoGetFaceTags(local_command_line_args[i]);
1078
1079                    tag_list = "";
1080                    comment_list = "";
1081                    all_tags = "";
1082                    SyncPiwigoGetTagsandComments(ref tag_list, ref comment_list, local_command_line_args[i]);
1083
1084                    if (face_tag_list.Length != 0)
1085                    {
1086                        all_tags = face_tag_list;
1087                    }
1088                    if (tag_list.Length != 0)
1089                    {
1090                        if (all_tags.Length != 0)
1091                        {
1092                            all_tags += ",";
1093                        }
1094                        all_tags += tag_list;
1095                    }
1096
1097                    k = local_command_line_args[i].LastIndexOf("\\");
1098                    filename = local_command_line_args[i].Substring(k + 1);
1099                    PhotoFileContents = FileToByteArray(local_command_line_args[i]);
1100
1101                    WebRequest = FormSettings.Default.PiwigoUrlSetting + "/ws.php?method=pwg.images.addSimple";
1102
1103                    WebResponse = "";
1104                    local_command_line_args[i] = local_command_line_args[i].Replace("\\", "\\\\");
1105                    post_array[0, 0] = "name=\"category\"";
1106                    post_array[0, 1] = NewPiwigoAlbumId.ToString();
1107                    post_array[1, 0] = "name=\"name\"";
1108                    post_array[1, 1] = filename;
1109                    k = 2;
1110                    if (all_tags.Length != 0)
1111                    {
1112                        post_array[k, 0] = "name=\"tags\"";
1113                        post_array[k, 1] = all_tags;
1114                        k++;
1115                    }
1116                    if (comment_list.Length != 0)
1117                    {
1118                        post_array[k, 0] = "name=\"comment\"";
1119                        post_array[k, 1] = "\"" + comment_list + "\"";
1120                        k++;
1121                    }
1122                    post_array[k, 0] = "name=\"image\"" + ";filename=" + "\"" + local_command_line_args[i] + "\"";
1123
1124                    logit.WriteLog(WebRequest);
1125                    for (di = 0; di < k; di++)
1126                    {
1127                        logit.WriteLog(post_array[di, 0] + " " + post_array[di, 1]);
1128                    }
1129
1130
1131                    response = SendWebPostMultipart(WebRequest, post_array, "multipart/form-data", PhotoFileContents,
1132                        ref WebResponse);
1133
1134                    logit.WriteLog(WebResponse);
1135
1136                    GlobalClass.StatusDialogErrorMessage = WinFormStrings.UploadUnableToUploadStrRes;                   
1137
1138                    if (!response)
1139                    {
1140                        return false;
1141                    }
1142
1143                    filtered_xml = FilterForXML(WebResponse);
1144                    if (filtered_xml.Length == 0)
1145                    {                       
1146                        logit.WriteLog("No xml response after upload.");
1147                        return false;
1148                    }
1149
1150                    xmlResponse = XmlGetAttribute(filtered_xml, "stat");
1151                    if (xmlResponse == "ok")
1152                    {
1153                        image_id = XmlGetElement(FilterForXML(WebResponse), "image_id");
1154                    }
1155                    else
1156                    {
1157                        upload_failed = true;
1158                    }
1159                }
1160            }
1161            return !upload_failed;
1162        }
1163        public string SendWebGet(string webrequest)
1164        {
1165            string webresponse;
1166            webresponse = "";
1167
1168            try
1169            {
1170                ServicePointManager.Expect100Continue = false;
1171                ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
1172                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
1173                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(webrequest);
1174                request.CookieContainer = cookiesjar;
1175                request.Proxy = null;
1176                request.Timeout = 60000;
1177                request.Credentials = CredentialCache.DefaultCredentials;
1178                request.Referer = "user-agent";
1179                request.UserAgent = "Mozilla/5.0";
1180                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
1181
1182                Stream dataStream = response.GetResponseStream();
1183                StreamReader reader = new StreamReader(dataStream);
1184                // Read the content.
1185                webresponse = reader.ReadToEnd();
1186                reader.Close();
1187                dataStream.Close();
1188                response.Close();
1189            }
1190            catch (Exception e)
1191            {
1192                webresponse = WinFormStrings.ErrorOcurredStrRes + " " + e.Message;
1193            }
1194            return webresponse;
1195        }
1196        public bool SendWebPost(string webrequest, string post_data, string content_type)
1197        {
1198            try
1199            {
1200                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(webrequest);
1201                ServicePointManager.Expect100Continue = false;
1202                ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
1203                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
1204                request.CookieContainer = cookiesjar;
1205                request.Proxy = null;
1206                request.Timeout = 60000;
1207                request.Method = "POST";
1208                request.Credentials = CredentialCache.DefaultCredentials;
1209                request.Referer = "user-agent";
1210                request.UserAgent = "Mozilla/5.0";
1211
1212                // Create POST data and convert it to a byte array.
1213                string postData = post_data;
1214                byte[] byteArray = Encoding.UTF8.GetBytes(postData);
1215
1216                // Set the ContentType property of the WebRequest.
1217                request.ContentType = content_type;
1218
1219                // Set the ContentLength property of the WebRequest.
1220                request.ContentLength = byteArray.Length;
1221
1222                // Get the request stream.
1223                Stream dataStream = request.GetRequestStream();
1224
1225                // Write the data to the request stream.
1226                dataStream.Write(byteArray, 0, byteArray.Length);
1227
1228                WebResponse response = request.GetResponse();
1229                // Display the status.
1230                Console.WriteLine(((HttpWebResponse)response).StatusDescription);
1231                // Get the stream containing content returned by the server.
1232                dataStream = response.GetResponseStream();
1233                // Open the stream using a StreamReader for easy access.
1234                StreamReader reader = new StreamReader(dataStream);
1235                // Read the content.
1236                string responseFromServer = reader.ReadToEnd();
1237                // Display the content.
1238
1239                // Close the Stream object.
1240                dataStream.Close();
1241            }
1242            catch (Exception e)
1243            {
1244                GlobalClass.StatusDialogErrorMessage = WinFormStrings.ErrorOcurredStrRes + " " + e.Message;
1245                return false;
1246            }
1247            return true;
1248        }
1249        public string XmlGetAttribute(string xmlstring, string element)
1250        {
1251            string foundattribute;
1252
1253            foundattribute = "";
1254            XmlDocument StatusResponse = new XmlDocument();
1255            StatusResponse.LoadXml(xmlstring);
1256            XmlElement ResponseElem = StatusResponse.DocumentElement;
1257           
1258            if (ResponseElem.HasAttribute(element))
1259            {
1260                foundattribute = ResponseElem.GetAttribute(element);
1261            }
1262            return foundattribute;
1263        }
1264        public string XmlGetElement(string xmlstring, string element)
1265        {
1266            XmlDocument StatusResponse = new XmlDocument();
1267
1268            if (xmlstring.Length != 0)
1269            {
1270                StatusResponse.LoadXml(xmlstring);
1271                XmlNodeList nodelist = StatusResponse.GetElementsByTagName(element);
1272                foreach (XmlNode anode in nodelist)
1273                {
1274                    return anode.ChildNodes[0].Value;
1275                }
1276            }
1277            return "";
1278        }
1279        public bool UpdateStatus(bool result)
1280        {
1281            if (result)
1282            {
1283                this.StatusTextBox.Text += WinFormStrings.OKStrRes;
1284            }
1285            else
1286            {
1287                this.StatusTextBox.Text += WinFormStrings.FailedStrRes;
1288                DialogResult = DialogResult.No;
1289            }
1290            StatusRefresh();
1291            return result;
1292        }
1293        public void SetStatus(string status)
1294        {
1295            this.StatusTextBox.Text = status;
1296            StatusRefresh();
1297        }
1298        public void StatusRefresh()
1299        {
1300            this.Refresh();
1301            this.StatusTextBox.Update();
1302            Application.DoEvents();
1303        }
1304        public byte[] FileToByteArray(string _FileName)
1305        {
1306            byte[] _Buffer = null;
1307                 
1308            try
1309            {
1310                // Open file for reading
1311                System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
1312                 
1313                // attach filestream to binary reader
1314                System.IO.BinaryReader _BinaryReader = new System.IO.BinaryReader(_FileStream);
1315                         
1316                // get total byte length of the file
1317                long _TotalBytes = new System.IO.FileInfo(_FileName).Length;
1318                 
1319                // read entire file into buffer
1320                _Buffer = _BinaryReader.ReadBytes((Int32)_TotalBytes);
1321                         
1322                // close file reader
1323                _FileStream.Close();
1324                _FileStream.Dispose();
1325                _BinaryReader.Close();
1326            }
1327            catch (Exception _Exception)
1328            {
1329                // Error
1330                Console.WriteLine("File Read Error: ", _Exception.ToString());
1331            }
1332         
1333            return _Buffer;
1334        }
1335        public bool SendWebPostMultipart(string webrequest, string[,] post_data, string content_type, byte[] binary_content, ref string response_from_server)
1336        {
1337            int i;
1338            ServicePointManager.Expect100Continue = false;
1339            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
1340            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
1341            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(webrequest);
1342            request.CookieContainer = cookiesjar;
1343            string boundary, formdataTemplate;
1344            Stream dataStream;
1345            byte[] byteArray;
1346            Stream memStream = new System.IO.MemoryStream();
1347
1348            request.Proxy = null;
1349            request.Timeout = 10 * 60 * 1000;
1350            request.Method = "POST";
1351            request.Credentials = CredentialCache.DefaultCredentials;
1352            request.KeepAlive = true;
1353            request.Referer = "user-agent";
1354            request.UserAgent = "Mozilla/5.0";
1355
1356            try
1357            {
1358                // Create POST data and convert it to a byte array.                                   
1359                boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");
1360                content_type = "multipart/form-data; boundary=" + boundary;
1361
1362                // Set the ContentType property of the WebRequest.
1363                request.ContentType = content_type;
1364
1365                byte[] boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" +
1366                    boundary + "\r\n");
1367
1368                memStream.Write(boundarybytes, 0, boundarybytes.Length);
1369
1370                byteArray = Encoding.UTF8.GetBytes("");
1371
1372                for (i = 0; i < 10; i++)
1373                {
1374                    if (post_data[i, 0] != null)
1375                    {
1376                        formdataTemplate = "Content-Disposition: form-data; "
1377                            + post_data[i, 0] + "\r\n";
1378                        if (post_data[i, 1] != null)
1379                        {
1380                            formdataTemplate += "\r\n";
1381                            formdataTemplate += post_data[i, 1];
1382                        }
1383
1384                        if (post_data[i + 1, 0] != null)
1385                        {
1386                            formdataTemplate += "\r\n--" + boundary + "\r\n";
1387                        }
1388
1389                        byte[] byteArray2 = Encoding.UTF8.GetBytes(formdataTemplate);
1390
1391                        // Set the ContentLength property of the WebRequest.
1392                        //request.ContentLength = byteArray.Length;
1393                        memStream.Write(byteArray2, 0, byteArray2.Length);
1394                    }
1395                    else
1396                    {
1397                        break;
1398                    }
1399                }
1400                formdataTemplate = "Content-Type: image/jpeg\r\n\r\n";
1401                byte[] byteArray3 = Encoding.UTF8.GetBytes(formdataTemplate);
1402                memStream.Write(byteArray3, 0, byteArray3.Length);
1403                memStream.Write(binary_content, 0, binary_content.Length);
1404
1405                formdataTemplate = "\r\n--" + boundary + "--\r\n";
1406                byte[] byteArray4 = Encoding.UTF8.GetBytes(formdataTemplate);
1407                memStream.Write(byteArray4, 0, byteArray4.Length);
1408
1409                memStream.Position = 0;
1410                byte[] tempBuffer = new byte[memStream.Length];
1411                memStream.Read(tempBuffer, 0, tempBuffer.Length);
1412                memStream.Close();
1413
1414                request.ContentLength = tempBuffer.Length;
1415
1416                dataStream = request.GetRequestStream();
1417                dataStream.Write(tempBuffer, 0, tempBuffer.Length);
1418                dataStream.Close();
1419
1420
1421                WebResponse response = request.GetResponse();
1422                // Display the status.
1423                Console.WriteLine(((HttpWebResponse)response).StatusDescription);
1424                // Get the stream containing content returned by the server.
1425                dataStream = response.GetResponseStream();
1426                // Open the stream using a StreamReader for easy access.
1427                StreamReader reader = new StreamReader(dataStream);
1428                // Read the content.
1429                response_from_server = reader.ReadToEnd();
1430                // Display the content.
1431
1432                // Close the Stream object.
1433                dataStream.Close();
1434            }
1435            catch (Exception e)
1436            {               
1437                GlobalClass.StatusDialogErrorMessage = WinFormStrings.ErrorOcurredStrRes + " " + e.Message;
1438                return false;
1439            }
1440            return true;
1441        }
1442
1443        private void button1_Click(object sender, EventArgs e)
1444        {
1445            GlobalClass.StatusDialogErrorMessage = WinFormStrings.StopButtonStrRes;
1446            DialogResult = DialogResult.No;
1447            stop_button_pressed = true;           
1448        }
1449        public bool HaveToRemoveComma()
1450        {
1451            int k,l;
1452            int major_version, sub_version, minor_version;
1453
1454
1455            k = GlobalClass.PiwigoVersionNumber.IndexOf(".");
1456            if (k == -1)
1457            {
1458                return true;
1459            }
1460
1461            l = 0;
1462            if (GlobalClass.PiwigoVersionNumber.Length >= k + 1)
1463            {
1464                l = GlobalClass.PiwigoVersionNumber.IndexOf(".", k + 1);
1465                if (l == -1)
1466                {
1467                    return true;
1468                }
1469            }
1470
1471            major_version = Convert.ToInt32(GlobalClass.PiwigoVersionNumber.Substring(0, k));
1472            sub_version = Convert.ToInt32(GlobalClass.PiwigoVersionNumber.Substring(k+1, l-k-1));
1473            minor_version = Convert.ToInt32(GlobalClass.PiwigoVersionNumber.Substring(l+1));
1474
1475            return true;
1476        }
1477        public bool CheckFileNameExtension(string photofilename)
1478        {
1479            if (photofilename.IndexOf(".jpg", StringComparison.OrdinalIgnoreCase) == -1 &&
1480                  photofilename.IndexOf(".jpeg", StringComparison.OrdinalIgnoreCase) == -1 &&
1481                  photofilename.IndexOf(".gif", StringComparison.OrdinalIgnoreCase) == -1 &&
1482                  photofilename.IndexOf(".png", StringComparison.OrdinalIgnoreCase) == -1 &&
1483                  photofilename.IndexOf(".tga", StringComparison.OrdinalIgnoreCase) == -1 &&
1484                  photofilename.IndexOf(".tif", StringComparison.OrdinalIgnoreCase) == -1 &&
1485                  photofilename.IndexOf(".tiff", StringComparison.OrdinalIgnoreCase) == -1 &&
1486                  photofilename.IndexOf(".psd", StringComparison.OrdinalIgnoreCase) == -1)
1487            {
1488                return false;
1489            }
1490            return true;
1491        }
1492        public string FilterForXML(string input_xml)
1493        {
1494            int k;
1495            string xml_only_str;
1496
1497            xml_only_str = "";
1498            k = input_xml.IndexOf("<?xml version=");
1499            if (k != -1)
1500            {
1501                xml_only_str = input_xml.Substring(k);
1502            }
1503            else
1504            {
1505                logit.WriteLog("No xml found in string");
1506            }
1507            return xml_only_str;
1508        }
1509    }
1510}
Note: See TracBrowser for help on using the repository browser.