public string EncryptionKey = "1111111111111111111111111111111111111111111111111111111111111111";
public string CacheDirectory = Path.GetTempPath();
,
EncryptionKey = App.Settings.EncryptionKey,
CacheDirectory = App.Settings.CacheDirectory
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="1">
<TextBox x:Name="TitleStorageFileNameTextBox" Margin="2" TextChanged="TitleStorageFileNameTextBox_TextChanged" Text="{Binding TitleStorageFileName, UpdateSourceTrigger=PropertyChanged}" />
<Button Width="100" Height="23" Margin="2" Content="Query file" Command="{Binding TitleStorageQueryFile}" />
<TextBox x:Name="TitleStorageTagTextBox" Margin="2" TextChanged="TitleStorageTagTextBox_TextChanged" Text="{Binding TitleStorageTag, UpdateSourceTrigger=PropertyChanged}" />
<Button Width="100" Height="23" Margin="2" Content="Query by tag" Command="{Binding TitleStorageQueryFileList}" />
<Button Width="100" Height="23" Margin="2" Content="Download file" Command="{Binding TitleStorageReadFile}" />
</StackPanel>
<ListView x:Name="TitleStorageFilesListView" Grid.Column="0" Margin="2" ItemsSource="{Binding TitleStorageFiles}" SelectedItem="{Binding SelectedTitleStorageFile}" SelectionChanged="TitleStorageFilesListView_SelectionChanged">
<ListView.View>
<GridView>
<GridViewColumn Header="Filename" Width="150" DisplayMemberBinding="{Binding Filename}">
<GridViewColumn.HeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Left" />
</Style>
</GridViewColumn.HeaderContainerStyle>
</GridViewColumn>
<GridViewColumn Header="MD5Hash" Width="250" DisplayMemberBinding="{Binding MD5Hash}">
<GridViewColumn.HeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Left" />
</Style>
</GridViewColumn.HeaderContainerStyle>
</GridViewColumn>
<GridViewColumn Header="FileSizeBytes" Width="100" DisplayMemberBinding="{Binding FileSizeBytes}">
<GridViewColumn.HeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Left" />
</Style>
</GridViewColumn.HeaderContainerStyle>
</GridViewColumn>
<GridViewColumn Header="UnencryptedDataSizeBytes" Width="150" DisplayMemberBinding="{Binding UnencryptedDataSizeBytes}">
<GridViewColumn.HeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Left" />
</Style>
</GridViewColumn.HeaderContainerStyle>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
public partial class TitleStorageView : UserControl
{
public TitleStorageViewModel ViewModel { get { return ViewModelLocator.TitleStorage; } }
public TitleStorageView()
{
InitializeComponent();
DataContext = ViewModel;
}
private void TitleStorageFilesListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void TitleStorageFileNameTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
ViewModel.TitleStorageQueryFile.RaiseCanExecuteChanged();
}
private void TitleStorageTagTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
ViewModel.TitleStorageQueryFileList.RaiseCanExecuteChanged();
}
}
public class TitleStorageViewModel : BindableBase
{
private ObservableCollection<FileMetadata> _titleStorageFiles;
public ObservableCollection<FileMetadata> TitleStorageFiles
{
get { return _titleStorageFiles; }
set { SetProperty(ref _titleStorageFiles, value); }
}
private FileMetadata _selectedTitleStorageFile;
public FileMetadata SelectedTitleStorageFile
{
get { return _selectedTitleStorageFile; }
set { SetProperty(ref _selectedTitleStorageFile, value); }
}
private string _titleStorageFileName;
public string TitleStorageFileName
{
get { return _titleStorageFileName; }
set { SetProperty(ref _titleStorageFileName, value); }
}
private string _titleStorageTag;
public string TitleStorageTag
{
get { return _titleStorageTag; }
set { SetProperty(ref _titleStorageTag, value); }
}
}
private static TitleStorageViewModel _titleStorage;
public static TitleStorageViewModel TitleStorage
{
get { return _titleStorage ??= new TitleStorageViewModel(); }
}
public static class TitleStorageService
{
public static void QueryFile(string fileName)
{
var queryFileOptions = new QueryFileOptions()
{
LocalUserId = ProductUserId.FromString(ViewModelLocator.Main.ProductUserId),
Filename = fileName
};
ViewModelLocator.Main.StatusBarText = $"Querying title storage file <{queryFileOptions.Filename}>...";
App.Settings.PlatformInterface.GetTitleStorageInterface()
.QueryFile(queryFileOptions, null, (QueryFileCallbackInfo queryFileCallbackInfo) =>
{
Debug.WriteLine($"QueryFile {queryFileCallbackInfo.ResultCode}");
if (queryFileCallbackInfo.ResultCode == Result.Success)
{
var copyFileMetadataByFilenameOptions = new CopyFileMetadataByFilenameOptions()
{
LocalUserId = ProductUserId.FromString(ViewModelLocator.Main.ProductUserId),
Filename = fileName
};
var result = App.Settings.PlatformInterface.GetTitleStorageInterface()
.CopyFileMetadataByFilename(copyFileMetadataByFilenameOptions, out var metadata);
if (result == Result.Success)
{
ViewModelLocator.TitleStorage.TitleStorageFiles.Add(metadata);
}
}
ViewModelLocator.Main.StatusBarText = string.Empty;
});
}
public static void QueryFileList(string tag)
{
var queryFileListOptions = new QueryFileListOptions()
{
LocalUserId = ProductUserId.FromString(ViewModelLocator.Main.ProductUserId),
ListOfTags = new string[] { tag }
};
ViewModelLocator.Main.StatusBarText = $"Querying title storage files by tag <{tag}>...";
App.Settings.PlatformInterface.GetTitleStorageInterface()
.QueryFileList(queryFileListOptions, null, (QueryFileListCallbackInfo queryFileListCallbackInfo) =>
{
Debug.WriteLine($"QueryFileList {queryFileListCallbackInfo.ResultCode}");
if (queryFileListCallbackInfo.ResultCode == Result.Success)
{
for (uint i = 0; i < queryFileListCallbackInfo.FileCount; i++)
{
var copyFileMetadataAtIndexOptions = new CopyFileMetadataAtIndexOptions()
{
Index = i,
LocalUserId = ProductUserId.FromString(ViewModelLocator.Main.ProductUserId)
};
var result = App.Settings.PlatformInterface.GetTitleStorageInterface()
.CopyFileMetadataAtIndex(copyFileMetadataAtIndexOptions, out var metadata);
if (result == Result.Success)
{
ViewModelLocator.TitleStorage.TitleStorageFiles.Add(metadata);
}
}
}
ViewModelLocator.Main.StatusBarText = string.Empty;
});
}
}
public class TitleStorageQueryFileCommand : CommandBase
{
public override bool CanExecute(object parameter)
{
return !string.IsNullOrWhiteSpace(ViewModelLocator.Main.ProductUserId) && !string.IsNullOrWhiteSpace(ViewModelLocator.TitleStorage
.TitleStorageFileName);
}
public override void Execute(object parameter)
{
ViewModelLocator.TitleStorage.TitleStorageFiles = new ObservableCollection<FileMetadata>();
TitleStorageService.QueryFile(ViewModelLocator.TitleStorage
.TitleStorageFileName);
}
}
public class TitleStorageQueryFileListCommand : CommandBase
{
public override bool CanExecute(object parameter)
{
return !string.IsNullOrWhiteSpace(ViewModelLocator.Main.ProductUserId) && !string.IsNullOrWhiteSpace(ViewModelLocator
.TitleStorage.TitleStorageTag);
}
public override void Execute(object parameter)
{
ViewModelLocator.TitleStorage.TitleStorageFiles = new ObservableCollection<FileMetadata>();
TitleStorageService.QueryFileList(ViewModelLocator.TitleStorage
.TitleStorageTag);
}
}
public TitleStorageQueryFileCommand TitleStorageQueryFile { get; set; }
public TitleStorageQueryFileListCommand TitleStorageQueryFileList { get; set; }
public TitleStorageViewModel()
{
TitleStorageQueryFile = new TitleStorageQueryFileCommand();
TitleStorageQueryFileList = new TitleStorageQueryFileListCommand();
}
TitleStorage.TitleStorageQueryFile.RaiseCanExecuteChanged();
TitleStorage.TitleStorageQueryFileList.RaiseCanExecuteChanged();
<TabItem x:Name="TitleStorage" Header="Title Storage">
<views:TitleStorageView />
</TabItem>
public class TitleStorageReadFileCommand : CommandBase
{
public override bool CanExecute(object parameter)
{
return ViewModelLocator.TitleStorage.SelectedTitleStorageFile != null;
}
public override void Execute(object parameter)
{
TitleStorageService.ReadFile(ViewModelLocator.TitleStorage
.SelectedTitleStorageFile);
}
}
public TitleStorageQueryFileCommand TitleStorageQueryFile { get; set; }
public TitleStorageQueryFileListCommand TitleStorageQueryFileList { get; set; }
public TitleStorageReadFileCommand TitleStorageReadFile { get; set; }
public TitleStorageViewModel()
{
TitleStorageQueryFile = new TitleStorageQueryFileCommand();
TitleStorageQueryFileList = new TitleStorageQueryFileListCommand();
TitleStorageReadFile = new TitleStorageReadFileCommand();
}
ViewModel.TitleStorageReadFile.RaiseCanExecuteChanged();