55using GeneralUpdate . Differential ;
66using GeneralUpdate . Infrastructure . DataServices . Pick ;
77using GeneralUpdate . Infrastructure . MVVM ;
8+ using GeneralUpdate . PacketTool . Models ;
89using GeneralUpdate . PacketTool . Services ;
910using GeneralUpdate . Zip . Factory ;
11+ using Newtonsoft . Json ;
12+ using System . Net . Http . Json ;
1013using System . Text ;
1114
1215namespace GeneralUpdate . PacketTool . ViewModels
@@ -21,8 +24,10 @@ public class MainViewModel : ViewModeBase
2124 private bool isPublish ;
2225 private AsyncRelayCommand buildCommand ;
2326 private AsyncRelayCommand < string > selectFolderCommand ;
27+ private AsyncRelayCommand buildJsonCommand ;
2428 private readonly IFolderPickerService _folderPickerService ;
2529 private MainService _mainService ;
30+ private const string _jsonTemplateFileName = "version.json" ;
2631
2732 #endregion
2833
@@ -60,6 +65,11 @@ public AsyncRelayCommand BuildCommand
6065 get => buildCommand ?? ( buildCommand = new AsyncRelayCommand ( BuildPacketCallback ) ) ;
6166 }
6267
68+ public AsyncRelayCommand BuildJsonCommand
69+ {
70+ get => buildJsonCommand ?? ( buildJsonCommand = new AsyncRelayCommand ( BuildJsonCallback ) ) ;
71+ }
72+
6373 public List < string > AppTypes
6474 {
6575 get
@@ -94,15 +104,17 @@ public List<string> Encodings
94104 {
95105 if ( _currentEncoding == null )
96106 {
97- _encodings = new List < string > ( ) ;
98- _encodings . Add ( "Default" ) ;
99- _encodings . Add ( "UTF8" ) ;
100- _encodings . Add ( "UTF7" ) ;
101- _encodings . Add ( "Unicode" ) ;
102- _encodings . Add ( "UTF32" ) ;
103- _encodings . Add ( "BigEndianUnicode" ) ;
104- _encodings . Add ( "Latin1" ) ;
105- _encodings . Add ( "ASCII" ) ;
107+ _encodings = new List < string >
108+ {
109+ "Default" ,
110+ "UTF8" ,
111+ "UTF7" ,
112+ "Unicode" ,
113+ "UTF32" ,
114+ "BigEndianUnicode" ,
115+ "Latin1" ,
116+ "ASCII"
117+ } ;
106118 }
107119 return _encodings ;
108120 }
@@ -127,7 +139,7 @@ public string CurrnetAppType
127139
128140 public string CurrentVersion { get => _currentVersion ; set => SetProperty ( ref _currentVersion , value ) ; }
129141 public string CurrentClientAppKey { get => _currentClientAppKey ; set => SetProperty ( ref _currentClientAppKey , value ) ; }
130-
142+
131143 #endregion
132144
133145 #region Private Methods
@@ -217,6 +229,31 @@ await _mainService.PostUpgradPakcet<UploadReapDTO>(Url,packetPath, String2AppTyp
217229 }
218230 }
219231
232+ /// <summary>
233+ /// Build version template file (json).
234+ /// </summary>
235+ /// <returns></returns>
236+ /// <exception cref="NotImplementedException"></exception>
237+ private async Task BuildJsonCallback ( )
238+ {
239+ var pickerResult = await _folderPickerService . PickFolderTaskAsync ( ) ;
240+ if ( pickerResult == null )
241+ {
242+ await Shell . Current . DisplayAlert ( "Pick options" , "No results were selected !" , "ok" ) ;
243+ return ;
244+ }
245+ string path = Path . Combine ( pickerResult , _jsonTemplateFileName ) ;
246+ if ( File . Exists ( path ) ) await Shell . Current . DisplayAlert ( "Build options" , "File already exists !" , "check" ) ;
247+ var jsonModel = new VersionTmplateModel ( ) ;
248+ await BuildVersionTemplate ( path , jsonModel ) ;
249+ }
250+
251+ private async Task BuildVersionTemplate < T > ( string path , T content ) where T : class
252+ {
253+ string json = JsonConvert . SerializeObject ( content ) ;
254+ await File . WriteAllTextAsync ( path , json , System . Text . Encoding . UTF8 ) ;
255+ }
256+
220257 private bool ValidationParameters ( ) => ( string . IsNullOrEmpty ( SourcePath ) || string . IsNullOrEmpty ( TargetPath ) || string . IsNullOrEmpty ( PatchPath ) ||
221258 string . IsNullOrEmpty ( PacketName ) || string . IsNullOrEmpty ( CurrentFormat ) || string . IsNullOrEmpty ( CurrentEncoding ) ) ;
222259
0 commit comments