namespace Microsoft.Phone.Tasks
{
public sealed class SaveRingtoneTask : ChooserBase<TaskEventArgs>
{
private const int MAX_PATH = 260;
private const int MAX_FILE_SIZE = 1048576;
private Uri _source;
private string _displayName;
private string _tokenId;
public Uri Source
{
get
{
return this._source;
}
set
{
if (value == (Uri) null)
throw new ArgumentNullException("Source", "Path cannot be null.");
string str = value.LocalPath.Substring(value.LocalPath.LastIndexOf(".") + 1);
if (!str.ToLower().Equals("wma") && !str.ToLower().Equals("mp3"))
throw new ArgumentOutOfRangeException("Source", "Ringtone file is in an invalid format.");
this._source = value;
}
}
public string DisplayName
{
get
{
return this._displayName;
}
set
{
if (value == null || ((object) value).ToString().Length < 1)
{
this._displayName = "";
}
else
{
if (((object) value).ToString().Length > 260)
throw new ArgumentException("DisplayName is too long.");
this._displayName = value;
}
}
}
public bool IsShareable { get; set; }
public override void Show()
{
if (!ChooserHelper.NavigationInProgressGuard((Action) (() => this.Show())))
return;
if (this._source == (Uri) null)
throw new InvalidOperationException("Path cannot be null.");
this.Source = this._source;
this.DisplayName = this._displayName;
HostInfo hostInfo = new HostInfo();
string str = string.Empty;
string fileSystemPath;
try
{
fileSystemPath = hostInfo.GetFileSystemPath(this.Source.ToString());
this._tokenId = DSC.DSCreateSharedFileTokenManaged(fileSystemPath);
}
catch (Exception ex)
{
throw new InvalidOperationException("Path must point to a file in your " +
"Isolated Storage or Application Data directory.");
}
ParameterPropertyBag ppb = new ParameterPropertyBag();
ppb.CreateProperty("TokenId").StringValue = this._tokenId;
ppb.CreateProperty("Source").StringValue = fileSystemPath;
ppb.CreateProperty("DisplayName").StringValue = this.DisplayName;
ppb.CreateProperty("IsShareable").BoolValue = this.IsShareable;
byte[] buffer = ChooserHelper.Serialize(ppb);
Uri appUri = new Uri("app://D8CF8EC7-EC6D-4892-AAB9-1E3A4B5FA24B/SaveRingtone",
UriKind.Absolute);
base.Show();
ChooserHelper.Invoke(appUri, buffer, (IChooser) this._genericChooser);
}
internal override void OnInvokeReturned(byte[] outputBuffer, Delegate fireThisHandlerOnly)
{
bool flag = false;
uint num = 0U;
if (outputBuffer.Length > 0)
{
ParameterProperty property = new ParameterPropertyBag(outputBuffer,
(uint) outputBuffer.Length).GetProperty("Error");
if (property.ValueType == ParameterPropertyValueType.ValueType_Int32)
num = (uint) property.Int32Value;
flag = (int) num == 0;
}
else
num = 4U;
if (flag)
{
this.FireCompleted((object) this,
new TaskEventArgs(TaskResult.OK),
fireThisHandlerOnly);
}
else
{
TaskEventArgs e = new TaskEventArgs(TaskResult.Cancel);
if (num > 0U)
{
switch (num)
{
case 1U:
e.Error = (Exception) new InvalidOperationException
("Ringtone file is in an invalid format.");
break;
case 2U:
e.Error = (Exception) new InvalidOperationException
("Ringtone file is too large.");
break;
case 3U:
e.Error = (Exception) new IOException
("There is not enough space on disk.");
break;
case 4U:
break;
default:
e.Error = (Exception) new IOException
("Failed to save ringtone.");
break;
}
}
this.FireCompleted((object) this, e, fireThisHandlerOnly);
}
}
internal enum SAVE_RINGTONE_RESULT
{
SAVE_RINGTONE_RESULT_SUCCESS,
SAVE_RINGTONE_RESULT_ERRORINVALIDDATA,
SAVE_RINGTONE_RESULT_ERRORFILETOOLARGE,
SAVE_RINGTONE_RESULT_ERRORDISKFULL,
SAVE_RINGTONE_RESULT_ERRORCANCEL,
}
}
}