Skip to content

Commit 3aa8272

Browse files
authored
b135
1 parent b231db6 commit 3aa8272

File tree

5 files changed

+175
-40
lines changed

5 files changed

+175
-40
lines changed

KMZRebuilder.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
<DependentUpon>GPXTachograph.cs</DependentUpon>
110110
</Compile>
111111
<Compile Include="InputBox.cs">
112-
<SubType>Component</SubType>
112+
<SubType>Form</SubType>
113113
</Compile>
114114
<Compile Include="InterpolateLess.cs">
115115
<SubType>Form</SubType>

KMZRebuilederForm.Designer.cs

Lines changed: 46 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

KMZRebuilederForm.cs

Lines changed: 126 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ private void RegisterFileAsses()
205205
{
206206
FileAss.SetFileAssociation("kmz", "KMZFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
207207
FileAss.SetFileAssociation("kml", "KMLFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
208+
FileAss.SetFileAssociation("kmf", "KMZFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
208209
FileAss.SetFileAssociation("wpt", "WPTFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
209210
FileAss.SetFileAssociation("gpx", "GPXFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
210211
FileAss.SetFileAssociation("gpi", "KMZFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
@@ -273,7 +274,7 @@ private void bgFiles_DragDrop(object sender, DragEventArgs e)
273274
private void AddFiles_Click(object sender, EventArgs e)
274275
{
275276
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";
277278
ofd.DefaultExt = ".kmz";
278279
ofd.Multiselect = true;
279280
if (ofd.ShowDialog() == DialogResult.OK) LoadFiles(ofd.FileNames);
@@ -332,6 +333,11 @@ private void LoadFiles(string[] files)
332333
};
333334

334335
int c = kmzFiles.Items.Count;
336+
if ((files.Length == 1) && ((Path.GetExtension(files[0]).ToLower() == ".kmf")))
337+
{
338+
OpenFilesInList(files[0]);
339+
return;
340+
};
335341
if ((files.Length == 1) && ((Path.GetExtension(files[0]).ToLower() == ".rpp")))
336342
{
337343
waitBox.Show("Wait", "Loading map...");
@@ -3012,6 +3018,8 @@ private void FilesMenu_Opening(object sender, CancelEventArgs e)
30123018

30133019
CFPBF.Enabled = (File.Exists(CurrentDirectory() + @"\KMZPOIfromOSM.exe"));
30143020

3021+
savelistbtnm.Enabled = kmzFiles.Items.Count > 0;
3022+
30153023
// NO ADD AFTER //
30163024
reloadOriginalFileToolStripMenuItem.Text = "Reload Original file";
30173025
if (kmzFiles.SelectedIndices.Count == 0) return;
@@ -8652,7 +8660,124 @@ private void uncheckwptskiptrueToolStripMenuItem_Click(object sender, EventArgs
86528660
SetLayersCheckByDescIf("wpt_skip=true", false);
86538661
}
86548662

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+
}
86558684

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+
}
86568781
}
86578782

86588783
public class FilesListBox : CheckedListBox

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929
// Build Number
3030
// Revision
3131
//
32-
[assembly: AssemblyVersion("22.2.8.133")]
33-
[assembly: AssemblyFileVersion("22.2.8.133")]
32+
[assembly: AssemblyVersion("22.2.16.135")]
33+
[assembly: AssemblyFileVersion("22.2.16.135")]

bin/Debug/KMZRebuilder.exe

4 KB
Binary file not shown.

0 commit comments

Comments
 (0)