| 18 |
|
/// <param name="file"></param> |
| 19 |
|
static public bool backupFile(string file) |
| 20 |
|
{ |
| 21 |
< |
//try |
| 22 |
< |
//{ |
| 23 |
< |
// System.IO.File.Copy(file, file + ".bak", false); //make a backup first //false is to not override already created backups |
| 24 |
< |
//} |
| 25 |
< |
//catch (Exception e) |
| 26 |
< |
//{ |
| 27 |
< |
// Program.printAppError(Program.appErrors.BACKUPS_ALREADY_EXISTS, "Couldn't backup file " + file + " :\n" + e.Message); |
| 28 |
< |
// return false; |
| 29 |
< |
//} |
| 21 |
> |
try |
| 22 |
> |
{ |
| 23 |
> |
System.IO.File.Copy(file, file + ".bak", false); //make a backup first //false is to not override already created backups |
| 24 |
> |
} |
| 25 |
> |
catch (Exception e) |
| 26 |
> |
{ |
| 27 |
> |
Program.printAppError(Program.appErrors.BACKUPS_ALREADY_EXISTS, "Couldn't backup file " + file + " :\n" + e.Message); |
| 28 |
> |
return false; |
| 29 |
> |
} |
| 30 |
|
return true; |
| 31 |
|
} |
| 32 |
|
|
| 86 |
|
public static List<String> getXmlFilesWildcard(String filewildcard) |
| 87 |
|
{ |
| 88 |
|
List<String> xmlFiles = new List<String>(); |
| 89 |
< |
String[] files = System.IO.Directory.GetFiles(getExePath()); //Get all files in executable directory |
| 89 |
> |
|
| 90 |
> |
String dir = Path.GetDirectoryName(filewildcard); // Get the specified directory |
| 91 |
> |
if (dir == "") |
| 92 |
> |
{ |
| 93 |
> |
dir = Util.getExePath(); |
| 94 |
> |
} |
| 95 |
> |
String wildcard = Path.GetFileName(filewildcard); // Get files/wildcard |
| 96 |
> |
String[] files = System.IO.Directory.GetFiles(dir); //Get all files in specified directory |
| 97 |
|
|
| 98 |
|
foreach (String file in files) |
| 99 |
|
{ |
| 100 |
< |
Regex wildcardRegex = new Regex(Util.WildcardToRegex(filewildcard), RegexOptions.IgnoreCase); //case insensitivity |
| 100 |
> |
Regex wildcardRegex = new Regex(Util.WildcardToRegex(wildcard), RegexOptions.IgnoreCase); //case insensitivity |
| 101 |
|
if (wildcardRegex.IsMatch(Path.GetFileName(file))) |
| 102 |
|
{ |
| 103 |
|
xmlFiles.Add(file); |
| 143 |
|
{ |
| 144 |
|
return Type.GetType("Mono.Runtime") != null; |
| 145 |
|
} |
| 146 |
+ |
|
| 147 |
+ |
public static bool ContainsIgnoreCase(string source, string sToSearch) |
| 148 |
+ |
{ |
| 149 |
+ |
return source.IndexOf(sToSearch, StringComparison.OrdinalIgnoreCase) >= 0; |
| 150 |
+ |
} |
| 151 |
+ |
|
| 152 |
+ |
// Thanks DarthDevilous for the regex! http://forums.thedailywtf.com/forums/t/2478.aspx |
| 153 |
+ |
public static string[] stringToArgsArray(string args) |
| 154 |
+ |
{ |
| 155 |
+ |
MatchCollection ms = Regex.Matches(args, "([^\" ]*(\"[^\"]*\")[^\" ]*)|[^\" ]+"); |
| 156 |
+ |
List<string> listArgs=new List<string>(); |
| 157 |
+ |
foreach (Match m in ms) |
| 158 |
+ |
{ |
| 159 |
+ |
listArgs.Add(m.Value.Replace("\"","")); //remove quotes or it will cause an error |
| 160 |
+ |
} |
| 161 |
+ |
return listArgs.ToArray(); |
| 162 |
+ |
} |
| 163 |
|
} |
| 164 |
|
} |