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

Last change on this file since 26935 was 26935, checked in by kenl, 10 years ago

Compatabiilty with Piwigo 2.6 plus a couple bug fixes.

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