mirror of
				https://github.com/lantean-code/qbtmud.git
				synced 2025-10-31 12:03:42 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			81 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			81 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| namespace Lantean.QBitTorrentClient.Models
 | |
| {
 | |
|     public class SaveLocation
 | |
|     {
 | |
|         public bool IsWatchedFolder { get; set; }
 | |
| 
 | |
|         public bool IsDefaltFolder { get; set; }
 | |
| 
 | |
|         public string? SavePath { get; set; }
 | |
| 
 | |
|         public static SaveLocation Create(object? value)
 | |
|         {
 | |
|             if (value is int intValue)
 | |
|             {
 | |
|                 if (intValue == 0)
 | |
|                 {
 | |
|                     return new SaveLocation
 | |
|                     {
 | |
|                         IsWatchedFolder = true
 | |
|                     };
 | |
|                 }
 | |
|                 else if (intValue == 1)
 | |
|                 {
 | |
|                     return new SaveLocation
 | |
|                     {
 | |
|                         IsDefaltFolder = true
 | |
|                     };
 | |
|                 }
 | |
|             }
 | |
|             else if (value is string stringValue)
 | |
|             {
 | |
|                 if (stringValue == "0")
 | |
|                 {
 | |
|                     return new SaveLocation
 | |
|                     {
 | |
|                         IsWatchedFolder = true
 | |
|                     };
 | |
|                 }
 | |
|                 else if (stringValue == "1")
 | |
|                 {
 | |
|                     return new SaveLocation
 | |
|                     {
 | |
|                         IsDefaltFolder = true
 | |
|                     };
 | |
|                 }
 | |
|                 else
 | |
|                 {
 | |
|                     return new SaveLocation
 | |
|                     {
 | |
|                         SavePath = stringValue
 | |
|                     };
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             throw new ArgumentOutOfRangeException(nameof(value));
 | |
|         }
 | |
| 
 | |
|         public object ToValue()
 | |
|         {
 | |
|             if (IsWatchedFolder)
 | |
|             {
 | |
|                 return 0;
 | |
|             }
 | |
|             else if (IsDefaltFolder)
 | |
|             {
 | |
|                 return 1;
 | |
|             }
 | |
|             else if (SavePath is not null)
 | |
|             {
 | |
|                 return SavePath;
 | |
|             }
 | |
| 
 | |
|             throw new InvalidOperationException("Invalid value.");
 | |
|         }
 | |
| 
 | |
|         public override string? ToString()
 | |
|         {
 | |
|             return ToValue().ToString();
 | |
|         }
 | |
|     }
 | |
| } |