mirror of
https://github.com/chylex/Backup-Essentials.git
synced 2025-08-25 23:35:11 +02:00
BackupEssentials
Backup
Controls
Data
Pages
Properties
Resources
Sys
Utils
FileLock.cs
FileUtils.cs
KeyEqualityComparer.cs
NativeMethods.cs
NumberSerialization.cs
ObservableDictionary.cs
ProgramArgsParser.cs
SafeDictionary.cs
ScheduledUpdate.cs
StringDictionarySerializer.cs
WindowsFileUtils.cs
WindowsVersion.cs
WpfExtensions.cs
App.xaml
App.xaml.cs
AppPageManager.cs
BackupEssentials.csproj
BackupReportWindow.xaml
BackupReportWindow.xaml.cs
BackupWindow.xaml
BackupWindow.xaml.cs
MainWindow.xaml
MainWindow.xaml.cs
TestingWindow.xaml
TestingWindow.xaml.cs
.gitignore
BackupEssentials.sln
LICENSE
README.md
61 lines
1.9 KiB
C#
61 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace BackupEssentials.Utils{
|
|
class ProgramArgsParser{
|
|
private string[] Args;
|
|
|
|
public ProgramArgsParser(string[] args){
|
|
this.Args = args;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns true if the arguments contain a flag (-<flag>). The dash in front is handled automatically.
|
|
/// </summary>
|
|
public bool HasFlag(string flag){
|
|
return Args.Contains("-"+flag);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the next argument after a flag (-<flag>), as long as it is not another flag. The dash in front is handled automatically.
|
|
/// </summary>
|
|
public string GetValue(string flag, string defaultValue){
|
|
flag = "-"+flag;
|
|
|
|
for(int a = 0; a < Args.Length-1; a++){
|
|
if (Args[a].Equals(flag)){
|
|
return Args[a+1].StartsWith("-",StringComparison.Ordinal) ? defaultValue : Args[a+1];
|
|
}
|
|
}
|
|
|
|
return defaultValue;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all arguments after a flag (-<flag>) until it hits another flag. The dash in front is handled automatically.
|
|
/// </summary>
|
|
public string[] GetMultiValue(string flag){
|
|
flag = "-"+flag;
|
|
List<string> list = new List<string>();
|
|
|
|
for(int a = 0; a < Args.Length-1; a++){
|
|
if (Args[a].Equals(flag)){
|
|
for(int index = a+1; index < Args.Length; index++){
|
|
if (Args[index].StartsWith("-",StringComparison.Ordinal))break;
|
|
else list.Add(Args[index]);
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
return list.ToArray();
|
|
}
|
|
|
|
public override string ToString(){
|
|
return string.Join(" ",Args);
|
|
}
|
|
}
|
|
}
|