@@ -205,6 +205,7 @@ private void RegisterFileAsses()
205
205
{
206
206
FileAss.SetFileAssociation("kmz", "KMZFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
207
207
FileAss.SetFileAssociation("kml", "KMLFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
208
+ FileAss.SetFileAssociation("kmf", "KMZFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
208
209
FileAss.SetFileAssociation("wpt", "WPTFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
209
210
FileAss.SetFileAssociation("gpx", "GPXFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
210
211
FileAss.SetFileAssociation("gpi", "KMZFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
@@ -273,7 +274,7 @@ private void bgFiles_DragDrop(object sender, DragEventArgs e)
273
274
private void AddFiles_Click(object sender, EventArgs e)
274
275
{
275
276
OpenFileDialog ofd = new OpenFileDialog();
276
- ofd.Filter = "Main Supported Files|*.kml;*.kmz;*.gpx;*.dat;*.wpt;*.db3;*.osm;*.gdb;*.fit;*.zip;*.rpp;*.dxml;*.gpi|KML Format (*.kml)|*.kml|KMZ Format (*.kmz)|*.kmz|GPX Exchange Format (*.gpx)|*.gpx|ProGorod Favorites.dat (*.dat)|*.dat|OziExplorer Waypoint File (*.wpt)|*.wpt|SASPlanet SQLite (*.db3)|*.db3|OSM Export File (*.osm)|*.osm|Navitel Waypoints (*.gdb)|*.gdb|Garmin Ant Fit (*.fit)|*.fit|Garmin POI (*.gpi)|*.gpi";
277
+ ofd.Filter = "Main Supported Files|*.kml;*.kmz;*.gpx;*.dat;*.wpt;*.db3;*.osm;*.gdb;*.fit;*.zip;*.rpp;*.dxml;*.gpi;*.kmf |KML Format (*.kml)|*.kml|KMZ Format (*.kmz)|*.kmz|GPX Exchange Format (*.gpx)|*.gpx|ProGorod Favorites.dat (*.dat)|*.dat|OziExplorer Waypoint File (*.wpt)|*.wpt|SASPlanet SQLite (*.db3)|*.db3|OSM Export File (*.osm)|*.osm|Navitel Waypoints (*.gdb)|*.gdb|Garmin Ant Fit (*.fit)|*.fit|Garmin POI (*.gpi)|*.gpi|KMZRebuilder Files List (*.kmf)|*.kmf ";
277
278
ofd.DefaultExt = ".kmz";
278
279
ofd.Multiselect = true;
279
280
if (ofd.ShowDialog() == DialogResult.OK) LoadFiles(ofd.FileNames);
@@ -332,6 +333,11 @@ private void LoadFiles(string[] files)
332
333
};
333
334
334
335
int c = kmzFiles.Items.Count;
336
+ if ((files.Length == 1) && ((Path.GetExtension(files[0]).ToLower() == ".kmf")))
337
+ {
338
+ OpenFilesInList(files[0]);
339
+ return;
340
+ };
335
341
if ((files.Length == 1) && ((Path.GetExtension(files[0]).ToLower() == ".rpp")))
336
342
{
337
343
waitBox.Show("Wait", "Loading map...");
@@ -3012,6 +3018,8 @@ private void FilesMenu_Opening(object sender, CancelEventArgs e)
3012
3018
3013
3019
CFPBF.Enabled = (File.Exists(CurrentDirectory() + @"\KMZPOIfromOSM.exe"));
3014
3020
3021
+ savelistbtnm.Enabled = kmzFiles.Items.Count > 0;
3022
+
3015
3023
// NO ADD AFTER //
3016
3024
reloadOriginalFileToolStripMenuItem.Text = "Reload Original file";
3017
3025
if (kmzFiles.SelectedIndices.Count == 0) return;
@@ -8652,7 +8660,124 @@ private void uncheckwptskiptrueToolStripMenuItem_Click(object sender, EventArgs
8652
8660
SetLayersCheckByDescIf("wpt_skip=true", false);
8653
8661
}
8654
8662
8663
+ private void saveToFileToolStripMenuItem_Click(object sender, EventArgs e)
8664
+ {
8665
+ if (kmzFiles.Items.Count == 0) return;
8666
+ SaveFileDialog sfd = new SaveFileDialog();
8667
+ sfd.Title = "Save file list as";
8668
+ sfd.DefaultExt = ".kmf";
8669
+ sfd.Filter = "KMZRebuilder File List (*.kmf)|*.kmf";
8670
+ try
8671
+ {
8672
+ sfd.FileName = (outName.Text.Length > 0 ? outName.Text : "File List") + ".kmf";
8673
+ }
8674
+ catch
8675
+ {
8676
+ sfd.FileName = "File List.kmf";
8677
+ };
8678
+ string fn = null;
8679
+ if (sfd.ShowDialog() == DialogResult.OK) fn = sfd.FileName;
8680
+ sfd.Dispose();
8681
+ if (String.IsNullOrEmpty(fn)) return;
8682
+ SaveFilesInList(fn);
8683
+ }
8655
8684
8685
+ private void SaveFilesInList(string fileName)
8686
+ {
8687
+ if (kmzFiles.Items.Count == 0) return;
8688
+ Directory.SetCurrentDirectory(Path.GetDirectoryName(fileName));
8689
+ FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
8690
+ StreamWriter sw = new StreamWriter(fs);
8691
+ sw.WriteLine("[KMZRebuilder KMF File]");
8692
+ sw.WriteLine("#Created " + DateTime.Now.ToString());
8693
+ sw.WriteLine("@" + outName.Text);
8694
+ for (int i = 0; i < kmzFiles.Items.Count; i++)
8695
+ {
8696
+ KMFile kmf = (KMFile)kmzFiles.Items[i];
8697
+ string fPath = Path.GetFullPath(kmf.src_file_pth);
8698
+ string rPath = MakeRelativePath(fileName, fPath);
8699
+ if(!String.IsNullOrEmpty(rPath)) sw.Write(rPath + " * " );
8700
+ sw.WriteLine(fPath);
8701
+ if (String.IsNullOrEmpty(fPath))
8702
+ sw.WriteLine(kmf.src_file_pth);
8703
+ };
8704
+ sw.Close();
8705
+ fs.Close();
8706
+ }
8707
+
8708
+ public static string MakeRelativePath(string fromPath, string toPath)
8709
+ {
8710
+ if (String.IsNullOrEmpty(fromPath)) return null;
8711
+ if (String.IsNullOrEmpty(toPath)) return null;
8712
+
8713
+ try
8714
+ {
8715
+ Uri fromUri = new Uri(fromPath);
8716
+ Uri toUri = new Uri(toPath);
8717
+
8718
+ if (fromUri.Scheme != toUri.Scheme) { return toPath; };
8719
+
8720
+ Uri relativeUri = fromUri.MakeRelativeUri(toUri);
8721
+ String relativePath = Uri.UnescapeDataString(relativeUri.ToString());
8722
+
8723
+ if (toUri.Scheme.Equals("file", StringComparison.InvariantCultureIgnoreCase))
8724
+ {
8725
+ relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
8726
+ };
8727
+
8728
+ return relativePath;
8729
+ }
8730
+ catch { return null; };
8731
+ }
8732
+
8733
+ private void OpenFilesInList(string fileName)
8734
+ {
8735
+ if (!File.Exists(fileName)) return;
8736
+ Directory.SetCurrentDirectory(Path.GetDirectoryName(fileName));
8737
+ FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
8738
+ StreamReader sr = new StreamReader(fs);
8739
+ List<string> fls = new List<string>();
8740
+ string oName = "";
8741
+ while (!sr.EndOfStream)
8742
+ {
8743
+ string line = sr.ReadLine();
8744
+ if (String.IsNullOrEmpty(line)) continue;
8745
+ if (line.StartsWith("[")) continue;
8746
+ if (line.StartsWith("]")) continue;
8747
+ if (line.StartsWith("{")) continue;
8748
+ if (line.StartsWith("}")) continue;
8749
+ if (line.StartsWith("?")) continue;
8750
+ if (line.StartsWith("#")) continue;
8751
+ if (line.StartsWith(";")) continue;
8752
+ if (line.StartsWith("%")) continue;
8753
+ if (line.StartsWith("^")) continue;
8754
+ if (line.StartsWith("&")) continue;
8755
+ if (line.StartsWith("*")) continue;
8756
+ if (line.StartsWith("@")) { oName = line.Substring(1).Trim(); continue; };
8757
+
8758
+ string[] ln = line.Split(new char[] { '*' }, StringSplitOptions.RemoveEmptyEntries);
8759
+ if (ln == null) continue;
8760
+ if (ln.Length == 0) continue;
8761
+ for (int i = 0; i < ln.Length; i++)
8762
+ {
8763
+ line = ln[i].Trim();
8764
+ if (File.Exists(line))
8765
+ {
8766
+ line = Path.GetFullPath(line);
8767
+ fls.Add(line);
8768
+ i = ln.Length;
8769
+ };
8770
+ };
8771
+ };
8772
+ sr.Close();
8773
+ fs.Close();
8774
+ if (fls.Count > 0)
8775
+ {
8776
+ LoadFiles(fls.ToArray());
8777
+ if (!String.IsNullOrEmpty(oName))
8778
+ outName.Text = oName;
8779
+ };
8780
+ }
8656
8781
}
8657
8782
8658
8783
public class FilesListBox : CheckedListBox
0 commit comments