Exemple #1
0
        public static void savePhotoParameters(Form ownerForm, string folderOrZipName)
        {
            if (Project.photoParametersDonotwrite)
            {
                return;
            }

            if (AllFormats.isZipFile(folderOrZipName))
            {
                if (!File.Exists(folderOrZipName))
                {
                    Project.ErrorBox(ownerForm, "Zip file not found: " + folderOrZipName);
                    return;
                }

                string ppfName = folderOrZipName + "|" + Project.PHOTO_PARAM_FILE_NAME;
                string message = "Confirm: will write new Camera Time Shift to " + ppfName
                                    + "\n\nDo you want to create/overwrite the file (inside the ZIP archive)?";

                if (!Project.photoParametersAsk || Project.YesNoBox(ownerForm, message))
                {
                    if (!File.Exists(folderOrZipName))
                    {
                        Project.ErrorBox(ownerForm, "Failed to open Zip file: " + folderOrZipName);
                        return;
                    }

                    XmlDocument xmlDoc = null;

                    using (ZipFile zip = new ZipFile(folderOrZipName))
                    {
                        ZipEntry entry = zip.GetEntry(Project.PHOTO_PARAM_FILE_NAME);
                        if (entry == null)
                        {
                            LibSys.StatusBar.Trace("IP: creating photo parameters entry: " + folderOrZipName + "|" + Project.PHOTO_PARAM_FILE_NAME);
                            xmlDoc = makePhotoParametersXmlDoc();
                            zip.BeginUpdate();
                        }
                        else
                        {
                            string fileName = entry.Name;
                            LibSys.StatusBar.Trace("IP: existing photo parameters entry: " + folderOrZipName + "|" + fileName);

                            xmlDoc = new XmlDocument();
                            Stream stream = zip.GetInputStream(entry);

                            using (StreamReader rdr = new StreamReader(stream))
                            {
                                xmlDoc.LoadXml(rdr.ReadToEnd());
                            }

                            editPhotoParametersXmlDoc(xmlDoc);

                            zip.BeginUpdate();
                            zip.Delete(entry);
                        }

                        StringMemoryDataSource m = new StringMemoryDataSource(xmlDoc.OuterXml);

                        zip.Add(m, Project.PHOTO_PARAM_FILE_NAME);

                        lastPhotoParametersFileName = ppfName;

                        zip.CommitUpdate();
                    }
                }
            }
            else
            {
                if (!Directory.Exists(folderOrZipName))
                {
                    Project.ErrorBox(ownerForm, "Folder not found: " + folderOrZipName);
                    return;
                }

                string ppfName = Path.Combine(folderOrZipName, Project.PHOTO_PARAM_FILE_NAME);
                string message = "Confirm: will write new Camera Time Shift to " + ppfName + "\n\nDo you want to "
                    + (File.Exists(ppfName) ? "overwrite" : "create") + " the file?";
                if (!Project.photoParametersAsk || Project.YesNoBox(ownerForm, message))
                {
                    try
                    {
                        if (File.Exists(ppfName))
                        {
                            LibSys.StatusBar.Trace("IP: existing photo parameters file: " + ppfName);
                            XmlDocument xmlDoc = new XmlDocument();
                            xmlDoc.Load(ppfName);

                            editPhotoParametersXmlDoc(xmlDoc);

                            xmlDoc.Save(ppfName);

                            lastPhotoParametersFileName = ppfName;
                        }
                        else
                        {
                            LibSys.StatusBar.Trace("IP: creating photo parameters file: " + ppfName);
                            XmlDocument xmlDoc = makePhotoParametersXmlDoc();

                            xmlDoc.Save(ppfName);

                            lastPhotoParametersFileName = ppfName;
                        }
                    }
                    catch (Exception e)
                    {
                        LibSys.StatusBar.Error("DlgPhotoManager:savePhotoParameters() " + e.Message);
                    }
                }
            }
        }
Exemple #2
0
        public static void savePhotoPositions(Form ownerForm, string folderOrZipName)
        {
            if (Project.photoPositionsDonotwrite)
            {
                return;
            }

            XmlDocument xmlDoc = makePhotoPositionsXmlDoc();

            if (AllFormats.isZipFile(folderOrZipName))
            {
                if (!File.Exists(folderOrZipName))
                {
                    Project.ErrorBox(ownerForm, "Zip file not found: " + folderOrZipName);
                    return;
                }

                string ppfName = folderOrZipName + "|" + Project.PHOTO_POSITIONS_FILE_NAME;

                string message = "Confirm: will write photo positions to " + ppfName
                    + "\n\nDo you want to create/overwrite the file (inside the ZIP archive)?";

                if (!Project.photoPositionsAsk || Project.YesNoBox(ownerForm, message))
                {
                    if (!File.Exists(folderOrZipName))
                    {
                        Project.ErrorBox(ownerForm, "Failed to open Zip file: " + folderOrZipName);
                        return;
                    }

                    using (ZipFile zip = new ZipFile(folderOrZipName))
                    {
                        ZipEntry entry = zip.GetEntry(Project.PHOTO_POSITIONS_FILE_NAME);
                        if (entry == null)
                        {
                            LibSys.StatusBar.Trace("IP: creating photo positions entry: " + folderOrZipName + "|" + Project.PHOTO_POSITIONS_FILE_NAME);
                            zip.BeginUpdate();
                        }
                        else
                        {
                            string fileName = entry.Name;
                            LibSys.StatusBar.Trace("IP: existing photo positions entry: " + folderOrZipName + "|" + fileName);

                            zip.BeginUpdate();
                            zip.Delete(entry);
                        }

                        StringMemoryDataSource m = new StringMemoryDataSource(xmlDoc.OuterXml);

                        zip.Add(m, Project.PHOTO_POSITIONS_FILE_NAME);

                        zip.CommitUpdate();
                    }
                }
            }
            else
            {
                if (!Directory.Exists(folderOrZipName))
                {
                    Project.ErrorBox(ownerForm, "Folder not found: " + folderOrZipName);
                    return;
                }

                string ppfName = Path.Combine(folderOrZipName, Project.PHOTO_POSITIONS_FILE_NAME);
                try
                {
                    if (File.Exists(ppfName))
                    {
                        LibSys.StatusBar.Trace("IP: existing photo positions file: " + ppfName);
                    }
                    else
                    {
                        LibSys.StatusBar.Trace("IP: creating photo positions file: " + ppfName);
                    }
                    xmlDoc.Save(ppfName);
                }
                catch (Exception e)
                {
                    LibSys.StatusBar.Error("DlgPhotoManager:savePhotoPositions() " + e.Message);
                }
            }
        }