Skip to content

Commit 1889f41

Browse files
committed
Bugfix for #116 crash on long filepath names >260 chars
1 parent 254a7a9 commit 1889f41

2 files changed

Lines changed: 53 additions & 5 deletions

File tree

CSVLintNppPlugin/CsvLint/CsvGenerateCode.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,15 @@ public static void GeneratePythonPanda(CsvDefinition csvdef)
277277
IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());
278278

279279
// Python requires forward slash for filepaths
280-
string FILE_PATH = Path.GetDirectoryName(notepad.GetCurrentFilePath());
280+
string FILE_PATH = "";
281+
try
282+
{
283+
FILE_PATH = Path.GetDirectoryName(notepad.GetCurrentFilePath());
284+
}
285+
catch (Exception ex)
286+
{
287+
// Path.GetDirectoryName will crash on long filepath (>260 chars)
288+
}
281289
string FILE_NAME = notepad.GetCurrentFilePath();
282290

283291
FILE_PATH = FILE_PATH.Replace("\\", "\\\\");
@@ -565,7 +573,15 @@ public static void GenerateRScript(CsvDefinition csvdef)
565573
IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());
566574

567575
// R-studio requires forward slash for filepaths
568-
string FILE_PATH = Path.GetDirectoryName(notepad.GetCurrentFilePath());
576+
string FILE_PATH = "";
577+
try
578+
{
579+
FILE_PATH = Path.GetDirectoryName(notepad.GetCurrentFilePath());
580+
}
581+
catch (Exception ex)
582+
{
583+
// Path.GetDirectoryName will crash on long filepath (>260 chars)
584+
}
569585
string FILE_NAME = notepad.GetCurrentFilePath();
570586

571587
FILE_PATH = FILE_PATH.Replace("\\", "/");
@@ -808,7 +824,15 @@ public static void GeneratePowerShell(CsvDefinition csvdef)
808824
IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());
809825

810826
// Python requires forward slash for filepaths
811-
string FILE_PATH = Path.GetDirectoryName(notepad.GetCurrentFilePath()).TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
827+
string FILE_PATH = "";
828+
try
829+
{
830+
FILE_PATH = Path.GetDirectoryName(notepad.GetCurrentFilePath()).TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
831+
}
832+
catch (Exception ex)
833+
{
834+
// Path.GetDirectoryName will crash on long filepath (>260 chars)
835+
}
812836
string FILE_NAME = Path.GetFileName(notepad.GetCurrentFilePath());
813837

814838
StringBuilder ps1 = new StringBuilder();

CSVLintNppPlugin/CsvLint/CsvSchemaIni.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,18 @@ class CsvSchemaIni
2323
public static Dictionary<string, string> ReadIniSection(string filePath)
2424
{
2525
// file name and path of the file to be edited
26-
string path = Path.GetDirectoryName(filePath);
26+
string path = "";
27+
try
28+
{
29+
path = Path.GetDirectoryName(filePath);
30+
}
31+
catch (Exception ex)
32+
{
33+
//will fail on long filepath names (>260 chars)
34+
//simply ignore and don't read ini file from long paths
35+
//MessageBox.Show(ex.ToString());
36+
};
37+
2738
string file = Path.GetFileName(filePath);
2839

2940
// schema.ini and section name
@@ -85,7 +96,20 @@ public static bool WriteIniSection(string filePath, string inikeys, out string e
8596
{
8697
errmsg = string.Empty;
8798
// file name and path of the edited file
88-
string path = Path.GetDirectoryName(filePath);
99+
string path = "";
100+
try
101+
{
102+
path = Path.GetDirectoryName(filePath);
103+
}
104+
catch (Exception ex)
105+
{
106+
//will fail on long filepath names (>260 chars)
107+
//cannot save ini file in long paths
108+
//MessageBox.Show(ex.ToString());
109+
errmsg = ex.Message;
110+
return false;
111+
}
112+
;
89113
string file = Path.GetFileName(filePath);
90114

91115
// schema.ini and section name

0 commit comments

Comments
 (0)