Exemple #1
0
        private void ShowOpenDBDialog()
        {
            try {
                FileChooserDialog dlg = new FileChooserDialog(Catalog.GetString("Open Database"), null,
                                                              FileChooserAction.Open,
                                                              Catalog.GetString("Cancel"),
                                                              ResponseType.Cancel, Catalog.GetString("Open"),
                                                              ResponseType.Accept);
                dlg.SetCurrentFolder(AppConfig.DataDirectory);
                FileFilter filter = new FileFilter();
                filter.Name = "OCM Databases";
                filter.AddPattern("*.ocm");
                dlg.AddFilter(filter);

                if (dlg.Run() == (int)ResponseType.Accept)
                {
                    dlg.Hide();
                    AppConfig.DBFile = dlg.Filename;
                    m_Store          = new FileStore(dlg.Filename);
                }
                else
                {
                    dlg.Hide();
                }
            } catch (Exception) {
                return;
            }
        }
Exemple #2
0
        public void StartDelete(List <Geocache> caches, OCMMainWindow win)
        {
            this.copyLabel.Markup = Catalog.GetString("<big><b>Deleting Geocaches</b></big>");
            this.Title            = Catalog.GetString("Delete Caches....");
            targetDBLabel.Visible = false;
            TargetLabel.Visible   = false;
            ACacheStore store = win.App.CacheStore;

            store.StartUpdate();
            double count = 0;

            total = caches.Count;
            foreach (Geocache cache in caches)
            {
                if (cancel)
                {
                    store.CancelUpdate();
                    this.Hide();
                    this.Dispose();
                    return;
                }
                count++;
                DeleteProgress(count, cache.Name);
                store.DeleteWaypoint(cache.Name);
                win.DeleteCacheImages(cache.Name);
            }
            statusLabel.Markup   = Catalog.GetString("<i>Complete</i>");
            progressBar.Text     = Catalog.GetString("Complete");
            buttonOk.Visible     = true;
            buttonCancel.Visible = false;
            store.CompleteUpdate();
        }
Exemple #3
0
        public void InitializeApp(string filename, bool quitAfterImport)
        {
            m_Store = new FileStore(m_Config.DBFile);
            InitalizeTracing();
            m_Locations    = LocationList.LoadLocationList();
            m_QuickFilters = QuickFilters.LoadQuickFilters();
            m_Profiles     = GPSProfileList.LoadProfileList();
            m_Tools        = EToolList.LoadEToolList();
            m_Bookmarks    = new BookmarkManager(this);
            m_CentreLat    = AppConfig.LastLat;
            m_CentreLon    = AppConfig.LastLon;
            m_CentreName   = AppConfig.LastName;
            m_Window       = new OCMMainWindow(this);
            QuickFilter startup = m_QuickFilters.GetFilter(AppConfig.StartupFilter);

            if (startup != null)
            {
                m_Window.CacheList.ApplyInitalQuickFilter(startup);
            }

            if (filename != null)
            {
                if (filename.EndsWith(".zip"))
                {
                    ImportZip(filename);
                }
                else
                {
                    ImportGPXFile(filename);
                }
                if (quitAfterImport)
                {
                    this.End();
                }
                else
                {
                    ShowMainWindow();
                }
            }
            else
            {
                m_splash = new OCMSplash();
                m_splash.Show();
                UpdateGUIThread();
                m_splash.Preload(this, startup);
            }
        }
Exemple #4
0
        public void SetDBFile(string filename, bool isNew)
        {
            if (!isNew)
            {
                CheckDBFile(filename);
            }
            FilterList        advanced  = null;
            List <FilterList> comboFilt = null;

            if (m_Store != null)
            {
                advanced  = m_Store.AdvancedFilters;
                comboFilt = m_Store.CombinationFilter;
                m_Store.Dispose();
            }
            m_Store = new FileStore(filename);
            m_Store.AdvancedFilters   = advanced;
            m_Store.CombinationFilter = comboFilt;
            m_Config.DBFile           = filename;
            m_Window.Title            = Utilities.GetShortFileName(filename) + "- OCM";
        }
Exemple #5
0
        public void CreateDB()
        {
            FileChooserDialog dlg = new FileChooserDialog(Catalog.GetString("Create database"), null, FileChooserAction.Save, Catalog.GetString("Cancel"), ResponseType.Cancel, Catalog.GetString("Save"), ResponseType.Accept);

            dlg.SetCurrentFolder(AppConfig.DataDirectory);
            dlg.CurrentName = "newdb.ocm";
            FileFilter filter = new FileFilter();

            filter.Name = "OCM Databases";
            filter.AddPattern("*.ocm");
            dlg.AddFilter(filter);
            if (dlg.Run() == (int)ResponseType.Accept)
            {
                if (System.IO.File.Exists(dlg.Filename))
                {
                    dlg.Hide();
                    MessageDialog mdlg = new MessageDialog(null, DialogFlags.Modal, MessageType.Warning, ButtonsType.YesNo, Catalog.GetString("Are you sure you want to overwrite '{0}'"), dlg.Filename);
                    if ((int)ResponseType.No == mdlg.Run())
                    {
                        mdlg.Hide();
                        return;
                    }
                    else
                    {
                        mdlg.Hide();
                        System.IO.File.Delete(dlg.Filename);
                    }
                }
                dlg.Hide();
                AppConfig.DBFile = dlg.Filename;
                m_Store          = new FileStore(dlg.Filename);
                return;
            }
            dlg.Destroy();
            return;
        }
 public void Start(String filename, ACacheStore store)
 {
     this.Show();
     try {
         m_parser.StartUpdate(store);
         FileStream stream = File.OpenRead(filename);
         m_total = m_parser.PreParseForSingle(stream, store);
         stream.Close();
         stream          = File.OpenRead(filename);
         m_progress      = 0;
         m_progressCount = 0;
         m_timeStart     = DateTime.Now;
         ParseFile(stream, store);
         stream.Close();
         if (!m_parser.Cancel)
         {
             m_parser.EndUpdate(store);
         }
     } catch (Exception e) {
         this.Hide();
         OCMApp.ShowException(e);
         this.Dispose();
     }
 }
 public CleanupManager(ACacheStore astore, List <Geocache> caches)
 {
     logsToDelete    = new List <string>();
     cachesToCleanup = caches;
     store           = astore;
 }
 /// <summary>
 /// Sends Geocaches to a device
 /// </summary>
 /// <param name="caches">
 /// A list of geocaches <see cref="List<Geocache>"/>
 /// </param>
 /// <param name="profile">
 /// A gps profiles <see cref="GPSProfile"/>
 /// </param>
 /// <param name="includeChildren">
 /// If true, include child waypoints<see cref="System.Boolean"/>
 /// </param>
 /// <param name="store">
 /// The source cache store <see cref="ACacheStore"/>
 /// </param>
 public void Start(List <Geocache> caches, GPSProfile profile, bool includeChildren, ACacheStore store)
 {
     try {
         total = caches.Count + 1;
         if (profile.CacheLimit != -1 && profile.CacheLimit < caches.Count)
         {
             total = profile.CacheLimit + 1;
         }
         writer.Limit             = profile.CacheLimit;
         writer.BabelFile         = profile.OutputFile;
         writer.BabelFormat       = profile.BabelFormat;
         writer.DescMode          = profile.DescMode;
         writer.NameMode          = profile.NameMode;
         writer.LogLimit          = profile.LogLimit;
         writer.IncludeAttributes = profile.IncludeAttributes;
         writer.OtherBabelParams  = profile.OtherProperties;
         writer.IncludeChildren   = includeChildren;
         writer.ForcePlainText    = profile.ForcePlainText;
         OCMApp.UpdateGUIThread();
         writer.WriteToGPS(caches, profile.WaypointMappings, store);
         this.Show();
     } catch (Exception e) {
         this.Hide();
         OCMApp.ShowException(e);
     }
 }
 /// <summary>
 /// Sends Geocaches to a device, always including child waypoints
 /// </summary>
 /// <param name="caches">
 /// A list of geocaches <see cref="List<Geocache>"/>
 /// </param>
 /// <param name="profile">
 /// A GPS profile <see cref="GPSProfile"/>
 /// </param>
 /// <param name="store">
 /// The source CacheStore <see cref="ACacheStore"/>
 /// </param>
 public void Start(List <Geocache> caches, GPSProfile profile, ACacheStore store)
 {
     Start(caches, profile, true, store);
 }
Exemple #10
0
 public void Start(String filename, List <Geocache> list, Dictionary <string, string> wmappings, ACacheStore store)
 {
     total = list.Count;
     if (m_writer.Limit != -1 && m_writer.Limit < total)
     {
         total = m_writer.Limit;
     }
     fileLabel.Markup = Catalog.GetString("<b>File: </b>") + filename;
     m_writer.WriteGPXFile(filename, list, wmappings, store);
 }
Exemple #11
0
        public void Start(String targetDB, bool isMove, ModeEnum modeType, OCMMainWindow win)
        {
            if (isMove)
            {
                Title            = Catalog.GetString("Move Caches...");
                copyLabel.Markup = Catalog.GetString("Moving Geocaches");
            }
            List <Geocache> caches;

            if (modeType == CopyingProgress.ModeEnum.VISIBLE)
            {
                caches = win.CacheList.UnfilteredCaches;
            }
            else if (modeType == CopyingProgress.ModeEnum.SELECTED)
            {
                caches = new List <Geocache> ();
                caches.Add(win.CacheList.SelectedCache);
            }
            else
            {
                caches = null;
                //caches = new List<Geocache> (UIMonitor.getInstance ().CacheStore.GetUnfilteredCaches(0d,0d,new string[0]));
            }
            ACacheStore target = new FileStore(targetDB);
            ACacheStore source = win.App.CacheStore;

            targetDBLabel.Text = targetDB;
            double count = 0;

            total = caches.Count;
            if (target.NeedsUpgrade)
            {
                MessageDialog dlg = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok,
                                                      Catalog.GetString("The target database needs to be upgraded. " +
                                                                        "Please open the target database before trying to copy/move caches."));
                dlg.Run();
                dlg.Hide();
                this.Hide();
                return;
            }
            buttonOk.Visible = false;
            List <String> str = new List <String>();

            foreach (Geocache c in caches)
            {
                str.Add(c.Name);
            }

            target.StartUpdate();
            target.PurgeAllLogs(str.ToArray());
            target.PurgeAllAttributes(str.ToArray());
            target.PurgeAllTravelBugs(str.ToArray());
            foreach (Geocache cache in caches)
            {
                if (cancel)
                {
                    target.CancelUpdate();
                    this.Hide();
                    this.Dispose();
                    return;
                }

                count++;
                UpdateProgress(count, cache.Name);
                target.AddWaypointOrCache(cache, false, false);
                List <CacheLog> logs = source.GetCacheLogs(cache.Name);
                foreach (CacheLog log in logs)
                {
                    target.AddLog(cache.Name, log);
                }

                List <Waypoint> children = source.GetChildWaypoints(new string[] { cache.Name });
                foreach (Waypoint child in children)
                {
                    target.AddWaypointOrCache(child, false, false);
                }

                CacheAttribute[] attributes = source.GetAttributes(cache.Name);
                foreach (CacheAttribute attribute in attributes)
                {
                    target.AddAttribute(cache.Name, attribute);
                }

                if (isMove)
                {
                    source.DeleteWaypoint(cache.Name);
                }
            }
            statusLabel.Markup   = Catalog.GetString("<i>Complete</i>");
            progressBar.Text     = Catalog.GetString("Complete");
            buttonOk.Visible     = true;
            buttonCancel.Visible = false;
            target.CompleteUpdate();
        }
        public void StartMulti(String directoryPath, ACacheStore store, bool deleteOnCompletion)
        {
            m_isMulti   = true;
            m_timeStart = DateTime.Now;
            string[] files = Directory.GetFiles(directoryPath);
            m_parser.StartUpdate(store);

            // Count total files
            m_progress             = 0;
            m_progressCount        = 0;
            m_total                = 0;
            multiFileLabel.Visible = true;

            List <string> dirs = new List <string>();

            // Prescan for zip files and uncompress
            for (int i = 0; i < files.Length; i++)
            {
                if (files[i].EndsWith(".zip"))
                {
                    this.progressbar6.Text = Catalog.GetString("Unzipping");
                    DirectoryInfo info = Directory.CreateDirectory(files[i].Substring(0, files[i].Length - 4));
                    dirs.Add(info.FullName);
                    multiFileLabel.Text      = Catalog.GetString("Unizpping");
                    this.waypointName.Markup = "<i>" + Catalog.GetString("Unzipping") + ":" + files[i] + "</i>";
                    while (Gtk.Application.EventsPending())
                    {
                        Gtk.Application.RunIteration(false);
                    }
                    ProcessStartInfo start = new ProcessStartInfo();
                    start.FileName  = "unzip";
                    start.Arguments = "-o \"" + files[i] + "\" -d \"" + info.FullName + "\"";
                    Process unzip = Process.Start(start);
                    while (!unzip.HasExited)
                    {
                        // Do nothing until exit
                    }
                    if (deleteOnCompletion)
                    {
                        File.Delete(files[i]);
                    }
                }
            }

            // Rescan for all GPX files, including those uncompressed by ZIP files
            List <string> fileList = new List <string>();

            string[] directories = Directory.GetDirectories(directoryPath);
            BuildFileList(directoryPath, fileList);
            foreach (string dir in directories)
            {
                BuildFileList(dir, fileList);
            }

            int currCount = 0;

            foreach (string file in fileList)
            {
                if (file.EndsWith(".gpx"))
                {
                    currCount++;
                    //Clean out attributes,tbs,and logs that will be overwritten
                    if (m_parser.Cancel)
                    {
                        return;
                    }
                    FileStream fs = System.IO.File.OpenRead(file);
                    m_parser.clearForImport(fs, store);
                    fs.Close();
                    // Need to reopen the file
                    fs = System.IO.File.OpenRead(file);
                    multiFileLabel.Text = String.Format(Catalog.GetString("Processing File {0} of {1}"), currCount, fileList.Count);
                    ParseFile(fs, store);
                    fs.Close();
                    if (deleteOnCompletion)
                    {
                        File.Delete(file);
                    }
                }
            }

            if (deleteOnCompletion)
            {
                foreach (string dir in dirs)
                {
                    Directory.Delete(dir);
                }
            }
            m_parser.EndUpdate(store);
            HandleCompletion();
        }
 private void ParseFile(FileStream fs, ACacheStore store)
 {
     fileLabel.Markup = Catalog.GetString("<b>File: </b>") + fs.Name;
     m_parser.parseGPXFile(fs, store);
 }