Skip to content

Commit

Permalink
b135
Browse files Browse the repository at this point in the history
  • Loading branch information
dkxce authored Feb 16, 2022
1 parent b231db6 commit 3aa8272
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 40 deletions.
2 changes: 1 addition & 1 deletion KMZRebuilder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<DependentUpon>GPXTachograph.cs</DependentUpon>
</Compile>
<Compile Include="InputBox.cs">
<SubType>Component</SubType>
<SubType>Form</SubType>
</Compile>
<Compile Include="InterpolateLess.cs">
<SubType>Form</SubType>
Expand Down
82 changes: 46 additions & 36 deletions KMZRebuilederForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 126 additions & 1 deletion KMZRebuilederForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ private void RegisterFileAsses()
{
FileAss.SetFileAssociation("kmz", "KMZFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
FileAss.SetFileAssociation("kml", "KMLFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
FileAss.SetFileAssociation("kmf", "KMZFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
FileAss.SetFileAssociation("wpt", "WPTFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
FileAss.SetFileAssociation("gpx", "GPXFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
FileAss.SetFileAssociation("gpi", "KMZFile", "Open in KMZRebuilder", CurrentDirectory() + @"\KMZRebuilder.exe");
Expand Down Expand Up @@ -273,7 +274,7 @@ private void bgFiles_DragDrop(object sender, DragEventArgs e)
private void AddFiles_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
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";
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";
ofd.DefaultExt = ".kmz";
ofd.Multiselect = true;
if (ofd.ShowDialog() == DialogResult.OK) LoadFiles(ofd.FileNames);
Expand Down Expand Up @@ -332,6 +333,11 @@ private void LoadFiles(string[] files)
};

int c = kmzFiles.Items.Count;
if ((files.Length == 1) && ((Path.GetExtension(files[0]).ToLower() == ".kmf")))
{
OpenFilesInList(files[0]);
return;
};
if ((files.Length == 1) && ((Path.GetExtension(files[0]).ToLower() == ".rpp")))
{
waitBox.Show("Wait", "Loading map...");
Expand Down Expand Up @@ -3012,6 +3018,8 @@ private void FilesMenu_Opening(object sender, CancelEventArgs e)

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

savelistbtnm.Enabled = kmzFiles.Items.Count > 0;

// NO ADD AFTER //
reloadOriginalFileToolStripMenuItem.Text = "Reload Original file";
if (kmzFiles.SelectedIndices.Count == 0) return;
Expand Down Expand Up @@ -8652,7 +8660,124 @@ private void uncheckwptskiptrueToolStripMenuItem_Click(object sender, EventArgs
SetLayersCheckByDescIf("wpt_skip=true", false);
}

private void saveToFileToolStripMenuItem_Click(object sender, EventArgs e)
{
if (kmzFiles.Items.Count == 0) return;
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "Save file list as";
sfd.DefaultExt = ".kmf";
sfd.Filter = "KMZRebuilder File List (*.kmf)|*.kmf";
try
{
sfd.FileName = (outName.Text.Length > 0 ? outName.Text : "File List") + ".kmf";
}
catch
{
sfd.FileName = "File List.kmf";
};
string fn = null;
if (sfd.ShowDialog() == DialogResult.OK) fn = sfd.FileName;
sfd.Dispose();
if (String.IsNullOrEmpty(fn)) return;
SaveFilesInList(fn);
}

private void SaveFilesInList(string fileName)
{
if (kmzFiles.Items.Count == 0) return;
Directory.SetCurrentDirectory(Path.GetDirectoryName(fileName));
FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine("[KMZRebuilder KMF File]");
sw.WriteLine("#Created " + DateTime.Now.ToString());
sw.WriteLine("@" + outName.Text);
for (int i = 0; i < kmzFiles.Items.Count; i++)
{
KMFile kmf = (KMFile)kmzFiles.Items[i];
string fPath = Path.GetFullPath(kmf.src_file_pth);
string rPath = MakeRelativePath(fileName, fPath);
if(!String.IsNullOrEmpty(rPath)) sw.Write(rPath + " * " );
sw.WriteLine(fPath);
if (String.IsNullOrEmpty(fPath))
sw.WriteLine(kmf.src_file_pth);
};
sw.Close();
fs.Close();
}

public static string MakeRelativePath(string fromPath, string toPath)
{
if (String.IsNullOrEmpty(fromPath)) return null;
if (String.IsNullOrEmpty(toPath)) return null;

try
{
Uri fromUri = new Uri(fromPath);
Uri toUri = new Uri(toPath);

if (fromUri.Scheme != toUri.Scheme) { return toPath; };

Uri relativeUri = fromUri.MakeRelativeUri(toUri);
String relativePath = Uri.UnescapeDataString(relativeUri.ToString());

if (toUri.Scheme.Equals("file", StringComparison.InvariantCultureIgnoreCase))
{
relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
};

return relativePath;
}
catch { return null; };
}

private void OpenFilesInList(string fileName)
{
if (!File.Exists(fileName)) return;
Directory.SetCurrentDirectory(Path.GetDirectoryName(fileName));
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
List<string> fls = new List<string>();
string oName = "";
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
if (String.IsNullOrEmpty(line)) continue;
if (line.StartsWith("[")) continue;
if (line.StartsWith("]")) continue;
if (line.StartsWith("{")) continue;
if (line.StartsWith("}")) continue;
if (line.StartsWith("?")) continue;
if (line.StartsWith("#")) continue;
if (line.StartsWith(";")) continue;
if (line.StartsWith("%")) continue;
if (line.StartsWith("^")) continue;
if (line.StartsWith("&")) continue;
if (line.StartsWith("*")) continue;
if (line.StartsWith("@")) { oName = line.Substring(1).Trim(); continue; };

string[] ln = line.Split(new char[] { '*' }, StringSplitOptions.RemoveEmptyEntries);
if (ln == null) continue;
if (ln.Length == 0) continue;
for (int i = 0; i < ln.Length; i++)
{
line = ln[i].Trim();
if (File.Exists(line))
{
line = Path.GetFullPath(line);
fls.Add(line);
i = ln.Length;
};
};
};
sr.Close();
fs.Close();
if (fls.Count > 0)
{
LoadFiles(fls.ToArray());
if (!String.IsNullOrEmpty(oName))
outName.Text = oName;
};
}
}

public class FilesListBox : CheckedListBox
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("22.2.8.133")]
[assembly: AssemblyFileVersion("22.2.8.133")]
[assembly: AssemblyVersion("22.2.16.135")]
[assembly: AssemblyFileVersion("22.2.16.135")]
Binary file modified bin/Debug/KMZRebuilder.exe
Binary file not shown.

0 comments on commit 3aa8272

Please sign in to comment.