2021-02-21 21:52:41 -06:00
// Decompiled with JetBrains decompiler
// Type: ZuneUI.UIDevice
// Assembly: ZuneShell, Version=4.7.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: FC8028F3-A47B-4FB4-B35B-11D1752D8264
// Assembly location: C:\Program Files\Zune\ZuneShell.dll
using Microsoft.Iris ;
using Microsoft.Zune.Configuration ;
using Microsoft.Zune.Shell ;
using Microsoft.Zune.Util ;
using MicrosoftZuneLibrary ;
using System ;
using System.Collections ;
using System.Collections.Generic ;
using System.Globalization ;
using System.Security ;
using System.Threading ;
using UIXControls ;
using ZuneXml ;
namespace ZuneUI
{
public class UIDevice : ModelItem
{
private IDeviceIconSet _iconSet ;
2021-02-21 22:59:09 -06:00
private static readonly INewRuleMessageType [] _newRuleMessageLookupTable = new INewRuleMessageType [ 11 ]
2021-02-21 21:52:41 -06:00
{
2021-02-21 22:59:09 -06:00
new NewRuleMessageType ( MediaType . Track , StringId . IDS_ADDED_1_TRACK , StringId . IDS_ADDED_N_TRACKS ),
new NewRuleMessageType ( MediaType . Album , StringId . IDS_ADDED_1_ALBUM , StringId . IDS_ADDED_N_ALBUMS ),
new NewRuleMessageType ( MediaType . Artist , StringId . IDS_ADDED_1_ARTIST , StringId . IDS_ADDED_N_ARTISTS ),
new NewRuleMessageType ( MediaType . Genre , StringId . IDS_ADDED_1_GENRE , StringId . IDS_ADDED_N_GENRES ),
new NewRuleMessageType ( MediaType . Playlist , StringId . IDS_ADDED_1_PLAYLIST , StringId . IDS_ADDED_N_PLAYLISTS ),
new NewRuleMessageType ( MediaType . Video , StringId . IDS_ADDED_1_VIDEO , StringId . IDS_ADDED_N_VIDEOS ),
new NewRuleMessageType ( MediaType . Photo , StringId . IDS_ADDED_1_PHOTO , StringId . IDS_ADDED_N_PHOTOS ),
new NewRuleMessageType ( MediaType . MediaFolder , StringId . IDS_ADDED_1_FOLDER , StringId . IDS_ADDED_N_FOLDERS ),
new NewRuleMessageType ( MediaType . PodcastEpisode , StringId . IDS_ADDED_1_PODCAST_EPISODE , StringId . IDS_ADDED_N_PODCAST_EPISODES ),
new NewRuleMessageType ( MediaType . Podcast , StringId . IDS_ADDED_1_PODCAST , StringId . IDS_ADDED_N_PODCASTS ),
new NewRuleMessageType ( MediaType . UserCard , StringId . IDS_ADDED_1_FRIEND , StringId . IDS_ADDED_N_FRIENDS )
2021-02-21 21:52:41 -06:00
};
2021-02-21 22:59:09 -06:00
private static readonly INewRuleMessageType _channelNewRuleMessage = new NewRuleMessageType ( MediaType . Playlist , StringId . IDS_ADDED_1_CHANNEL , StringId . IDS_ADDED_N_CHANNELS );
private static readonly INewRuleMessageType _genericNewRuleMessage = new NewRuleMessageType ( MediaType . Undefined , StringId . IDS_ADDED_1_ITEM , StringId . IDS_ADDED_N_ITEMS );
2021-02-21 21:52:41 -06:00
private static bool _isOosDialogVisible ;
2021-02-21 22:59:09 -06:00
private static string _syncStatusTitleDivider = Shell . LoadString ( StringId . IDS_SYNCITEM_TITLE_SEPARATOR );
private static string _syncStatusDatumDivider = Shell . LoadString ( StringId . IDS_SYNCITEM_METADATUM_SEPARATOR );
2021-02-21 21:52:41 -06:00
private UIFirmwareUpdater _firmwareUpdater ;
private UIFirmwareRestorer _firmwareRestorer ;
private Device _device ;
private UIGasGauge _actualGasGauge ;
private UIGasGauge _predictedGasGauge ;
private SyncNotification _syncProgress ;
private Command _syncBegun ;
private Command _syncProgressed ;
private Command _syncCompleted ;
private bool _currentlySyncing ;
private bool _currentlyFormatting ;
private bool _isWirelessSyncEnabled ;
private EEndpointStatus _lastDeviceState ;
private bool _isReadyForSync ;
private bool _isLocked ;
private bool _userStoppedLastSync ;
private Microsoft . Iris . Timer _formatSanityTimer ;
private string _lastConnectTimestring ;
private string _lastSyncStartTimestring ;
private HRESULT _lastLoginFailure ;
private HRESULT _lastSyncFailure ;
private MessageBox _pinUnlockMessageBox ;
public IDeviceIconSet IconSet
{
get
{
if ( this . _iconSet == null )
this . _iconSet = ! this . IsValid || this . _device . DeviceAssetSet == null ? DeviceIconSetFactory . DefaultIconSet : DeviceIconSetFactory . BuildDeviceIconSet ( this . _device . DeviceAssetSet , new DeviceIconSetFactory . DeviceIconSetConstructionCompletedCallback ( this . SetDeviceIconSetCallback ));
return this . _iconSet ;
}
private set
{
if ( this . _iconSet == value )
return ;
this . _iconSet = value ;
this . FirePropertyChanged ( nameof ( IconSet ));
}
}
2021-02-21 22:59:09 -06:00
private void ReloadIconSet () => this . IconSet = null ;
2021-02-21 21:52:41 -06:00
private void SetDeviceIconSetCallback ( IDeviceIconSet iconSet ) => this . IconSet = iconSet ;
public event FallibleEventHandler FormatCompletedEvent ;
public event FallibleEventHandler EnumeratedEvent ;
public event FallibleEventHandler WiFiRemovalCompletedEvent ;
public event FallibleEventHandler WiFiProfilesSentEvent ;
public event FallibleEventHandler WiFiProfilesReceivedEvent ;
public event FallibleEventHandler WiFiTestCompletedEvent ;
public event FallibleEventHandler WiFiAssociationCompletedEvent ;
public event FallibleEventHandler ComputerWiFiProfilesLoadedEvent ;
public event FallibleEventHandler WiFiScanCompletedEvent ;
internal UIDevice ( IModelItemOwner owner , Device device )
: base ( owner )
{
this . _device = device ;
this . _lastLoginFailure = HRESULT . _S_OK ;
this . _lastSyncFailure = HRESULT . _S_OK ;
if ( this . _device != null )
{
this . _device . FriendlyNameChangedEvent += new FriendlyNameChangedHandler ( this . OnNameChange );
this . _device . DeviceStatusChangedEvent += new DeviceStatusChangedHandler ( this . OnDeviceStatusChanged );
this . _device . FormatCompleteEvent += new FormatCompleteHandler ( this . OnFormatPhase1Completed );
this . _device . SyncBegan += new SyncBeganHandler ( this . OnSyncBegun );
this . _device . SyncProgressed += new SyncProgressedHandler ( this . OnSyncProgressed );
this . _device . SyncCompleted += new SyncCompletedHandler ( this . OnSyncCompleted );
this . _device . UnassociateWlanDeviceCompleteEvent += new UnassociateWlanDeviceCompleteHandler ( this . OnUnassociateWlanCompleted );
this . _device . SetDeviceWlanProfilesCompleteEvent += new SetDeviceWlanProfilesCompleteHandler ( this . OnSetDeviceWlanProfilesCompleted );
this . _device . GetDeviceWlanProfilesCompleteEvent += new GetDeviceWlanProfilesCompleteHandler ( this . OnGetDeviceWlanProfilesCompleted );
this . _device . TestDeviceWlanCompleteEvent += new TestDeviceWlanCompleteHandler ( this . OnTestWlanCompleted );
this . _device . AssociateWlanDeviceCompleteEvent += new AssociateWlanDeviceCompleteHandler ( this . OnAssociateWlanCompleted );
this . _device . GetWlanProfilesCompleteEvent += new GetWlanProfilesCompleteHandler ( this . OnGetWlanProfilesCompleted );
this . _device . GetDeviceWlanNetworksCompleteEvent += new GetDeviceWlanNetworksCompleteHandler ( this . OnGetDeviceWlanVisibleNetworksCompleted );
2021-02-21 22:59:09 -06:00
this . _actualGasGauge = new UIGasGauge ( this , this . _device . ActualGasGauge );
this . _predictedGasGauge = new UIGasGauge ( this , this . _device . PredictedGasGauge );
2021-02-21 21:52:41 -06:00
if ( this . _device . PredictedGasGauge != null )
this . _device . PredictedGasGauge . DeviceOverflowEvent += new DeviceOverflowHandler ( this . OnDeviceOverfill );
EEndpointStatus currentStatus = this . _device . DeviceStatus ;
if ( currentStatus != EEndpointStatus . eEndpointStatusUndefined )
2021-02-21 22:59:09 -06:00
Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
this . HandleDeviceState ( currentStatus , HRESULT . _S_OK );
2021-02-21 22:59:09 -06:00
}, null );
2021-02-21 21:52:41 -06:00
}
else
{
2021-02-21 22:59:09 -06:00
this . _actualGasGauge = new UIGasGauge ( this , null );
this . _predictedGasGauge = new UIGasGauge ( this , null );
2021-02-21 21:52:41 -06:00
}
2021-02-21 22:59:09 -06:00
this . _syncBegun = new Command ( this );
this . _syncProgressed = new Command ( this );
this . _syncCompleted = new Command ( this );
2021-02-21 21:52:41 -06:00
}
protected override void OnDispose ( bool disposing )
{
if ( this . _device != null )
{
this . _device . FriendlyNameChangedEvent -= new FriendlyNameChangedHandler ( this . OnNameChange );
this . _device . DeviceStatusChangedEvent -= new DeviceStatusChangedHandler ( this . OnDeviceStatusChanged );
this . _device . FormatCompleteEvent -= new FormatCompleteHandler ( this . OnFormatPhase1Completed );
if ( this . _device . PredictedGasGauge != null )
this . _device . PredictedGasGauge . DeviceOverflowEvent -= new DeviceOverflowHandler ( this . OnDeviceOverfill );
this . _device . SyncBegan -= new SyncBeganHandler ( this . OnSyncBegun );
this . _device . SyncProgressed -= new SyncProgressedHandler ( this . OnSyncProgressed );
this . _device . SyncCompleted -= new SyncCompletedHandler ( this . OnSyncCompleted );
this . _device . UnassociateWlanDeviceCompleteEvent -= new UnassociateWlanDeviceCompleteHandler ( this . OnUnassociateWlanCompleted );
this . _device . SetDeviceWlanProfilesCompleteEvent -= new SetDeviceWlanProfilesCompleteHandler ( this . OnSetDeviceWlanProfilesCompleted );
this . _device . GetDeviceWlanProfilesCompleteEvent -= new GetDeviceWlanProfilesCompleteHandler ( this . OnGetDeviceWlanProfilesCompleted );
this . _device . TestDeviceWlanCompleteEvent -= new TestDeviceWlanCompleteHandler ( this . OnTestWlanCompleted );
this . _device . AssociateWlanDeviceCompleteEvent -= new AssociateWlanDeviceCompleteHandler ( this . OnAssociateWlanCompleted );
this . _device . GetWlanProfilesCompleteEvent -= new GetWlanProfilesCompleteHandler ( this . OnGetWlanProfilesCompleted );
this . _device . GetDeviceWlanNetworksCompleteEvent -= new GetDeviceWlanNetworksCompleteHandler ( this . OnGetDeviceWlanVisibleNetworksCompleted );
}
base . OnDispose ( disposing );
}
public bool IsValid => this . _device != null && ! this . IsDisposed && this . _lastDeviceState > EEndpointStatus . eEndpointStatusUndefined ;
public int ID => ! this . IsValid ? 0 : this . _device . DeviceID ;
public string MyPhoneDeviceID
{
get
{
string str = string . Empty ;
if ( this . IsValid && this . SupportsMyPhoneLinks && this . _device . MyPhoneDeviceID != null )
str = this . _device . MyPhoneDeviceID ;
return str ;
}
}
public string EndpointId => ! this . IsValid ? string . Empty : this . _device . EndpointId ;
public string CanonicalName => ! this . IsConnectedToClient ? string . Empty : this . _device . CanonicalName ;
public DeviceClass Class => ! this . IsValid ? DeviceClass . Invalid : ( DeviceClass ) this . _device . ClassID ;
public int AdvertisedCapacity => ! this . IsValid ? 0 : ( int ) this . _device . StatedCapacity ;
public bool AllowChainedUpdates { get ; set ; }
public bool NavigateToDeviceSummaryAfterUpdate { get ; set ; }
public int SequentialUpdatesInstalled { get ; set ; }
public bool SkipFutureBackupRequests { get ; set ; }
public bool SupportsTVOutput
{
get
{
bool fIsTvOutSupported = false ;
if ( this . IsValid )
this . _device . GetIsTvOutSupported ( ref fIsTvOutSupported );
return fIsTvOutSupported ;
}
}
public bool SupportsClassicGames
{
get
{
bool fHasCapability = false ;
HRESULT hresult = HRESULT . _S_OK ;
if ( this . IsValid )
2021-02-21 22:59:09 -06:00
hresult = this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilityInstallFirmwareGames , ref fHasCapability );
2021-02-21 21:52:41 -06:00
return hresult . IsSuccess && fHasCapability ;
}
}
public bool SupportsLiveId
{
get
{
bool fHasCapability = false ;
HRESULT hresult = HRESULT . _S_OK ;
if ( this . IsValid )
2021-02-21 22:59:09 -06:00
hresult = this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilityLiveId , ref fHasCapability );
2021-02-21 21:52:41 -06:00
return hresult . IsSuccess && fHasCapability ;
}
}
public bool SupportsOOBECompleted
{
get
{
bool fHasCapability = false ;
HRESULT hresult = HRESULT . _S_OK ;
if ( this . IsValid )
2021-02-21 22:59:09 -06:00
hresult = this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilityOOBECompleted , ref fHasCapability );
2021-02-21 21:52:41 -06:00
return hresult . IsSuccess && fHasCapability ;
}
}
public bool SupportsRestorePoint
{
get
{
bool fHasCapability = false ;
return (! this . IsValid || (( HRESULT ) this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilityRestorePoint , ref fHasCapability )). IsSuccess ) && fHasCapability ;
}
}
public bool RequiresAutoRestore => this . SupportsRestorePoint && ! this . _device . InStandardMode ;
public bool InStandardMode => this . IsValid && this . _device . InStandardMode ;
public bool SupportsSyncApplications
{
get
{
bool fHasCapability = false ;
HRESULT hresult = HRESULT . _S_OK ;
if ( this . IsValid )
2021-02-21 22:59:09 -06:00
hresult = this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilitySyncApps , ref fHasCapability );
2021-02-21 21:52:41 -06:00
return hresult . IsSuccess && fHasCapability ;
}
}
public bool SupportsPaidApplications
{
get
{
bool fHasCapability = false ;
HRESULT hresult = HRESULT . _S_OK ;
if ( this . IsValid )
2021-02-21 22:59:09 -06:00
hresult = this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilityPaidApps , ref fHasCapability );
2021-02-21 21:52:41 -06:00
return hresult . IsSuccess && fHasCapability ;
}
}
public bool SupportsStoreApplications => this . SupportsSyncApplications || this . SupportsPaidApplications ;
public bool SupportsHD
{
get
{
bool fHasCapability = false ;
HRESULT hresult = HRESULT . _S_OK ;
if ( this . IsValid )
2021-02-21 22:59:09 -06:00
hresult = this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilityHdVideo , ref fHasCapability );
2021-02-21 21:52:41 -06:00
return hresult . IsSuccess && fHasCapability ;
}
}
public bool SupportsWiFi
{
get
{
bool fHasCapability = false ;
HRESULT hresult = HRESULT . _S_OK ;
if ( this . IsValid )
2021-02-21 22:59:09 -06:00
hresult = this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilityWireless , ref fHasCapability );
2021-02-21 21:52:41 -06:00
return hresult . IsSuccess && fHasCapability ;
}
}
public bool SupportsWirelessSetupMethod1
{
get
{
bool fHasCapability = true ;
HRESULT hresult = HRESULT . _S_OK ;
if ( this . IsValid )
2021-02-21 22:59:09 -06:00
hresult = this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilityWirelessSetupMethod1 , ref fHasCapability );
2021-02-21 21:52:41 -06:00
return hresult . IsSuccess && fHasCapability ;
}
}
public bool SupportsWirelessSetupMethod2
{
get
{
bool fHasCapability = true ;
HRESULT hresult = HRESULT . _S_OK ;
if ( this . IsValid )
2021-02-21 22:59:09 -06:00
hresult = this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilityWirelessSetupMethod2 , ref fHasCapability );
2021-02-21 21:52:41 -06:00
return hresult . IsSuccess && fHasCapability ;
}
}
public bool SupportsFirmwareUpdate
{
get
{
bool fHasCapability = false ;
HRESULT hresult = HRESULT . _S_OK ;
if ( this . IsValid )
2021-02-21 22:59:09 -06:00
hresult = this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilityFirmwareUpdate , ref fHasCapability );
2021-02-21 21:52:41 -06:00
return hresult . IsSuccess && fHasCapability ;
}
}
public bool SupportsMyPhoneLinks
{
get
{
bool fHasCapability = false ;
HRESULT hresult = HRESULT . _S_OK ;
if ( this . IsValid )
2021-02-21 22:59:09 -06:00
hresult = this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilityMyPhoneLinks , ref fHasCapability );
2021-02-21 21:52:41 -06:00
return hresult . IsSuccess && fHasCapability ;
}
}
public bool SupportsRental
{
get
{
bool fHasCapability = false ;
HRESULT hresult = HRESULT . _S_OK ;
if ( this . IsValid )
2021-02-21 22:59:09 -06:00
hresult = this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilityRental , ref fHasCapability );
2021-02-21 21:52:41 -06:00
return hresult . IsSuccess && fHasCapability ;
}
}
public bool SupportsUserCards
{
get
{
bool fHasCapability = false ;
HRESULT hresult = HRESULT . _S_OK ;
if ( this . IsValid )
2021-02-21 22:59:09 -06:00
hresult = this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilityCloudSync , ref fHasCapability );
2021-02-21 21:52:41 -06:00
return hresult . IsSuccess && fHasCapability ;
}
}
public bool SupportsChannels
{
get
{
bool fHasCapability = false ;
HRESULT hresult = HRESULT . _S_OK ;
if ( this . IsValid )
2021-02-21 22:59:09 -06:00
hresult = this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilityCloudSync , ref fHasCapability );
2021-02-21 21:52:41 -06:00
return hresult . IsSuccess && fHasCapability ;
}
}
public bool SupportsFormat
{
get
{
bool fHasCapability = true ;
HRESULT hresult = HRESULT . _S_OK ;
if ( this . IsValid )
2021-02-21 22:59:09 -06:00
hresult = this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilityFormat , ref fHasCapability );
2021-02-21 21:52:41 -06:00
return hresult . IsSuccess && fHasCapability ;
}
}
public bool SupportsZuneTagLinking
{
get
{
bool fHasCapability = false ;
HRESULT hresult = HRESULT . _S_OK ;
if ( this . IsValid )
2021-02-21 22:59:09 -06:00
hresult = this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilityZuneTagLinking , ref fHasCapability );
2021-02-21 21:52:41 -06:00
return hresult . IsSuccess && fHasCapability ;
}
}
public bool SupportsUsageData
{
get
{
bool fHasCapability = false ;
HRESULT hresult = HRESULT . _S_OK ;
if ( this . IsValid )
2021-02-21 22:59:09 -06:00
hresult = this . _device . GetCapability ( EEndpointCapability . eEndpointCapabilityUsageData , ref fHasCapability );
2021-02-21 21:52:41 -06:00
return hresult . IsSuccess && fHasCapability ;
}
}
public bool HasOffloadedContent => this . IsValid && ! string . IsNullOrEmpty ( this . OffloadedContentMessage ) && ! string . IsNullOrEmpty ( this . OffloadedContentUrl );
public string OffloadedContentMessage
{
get
{
2021-02-21 22:59:09 -06:00
string str = null ;
2021-02-21 21:52:41 -06:00
if ( this . IsValid )
str = this . _device . PicturesVideosViewText ;
return str ?? string . Empty ;
}
}
public string OffloadedContentUrl
{
get
{
2021-02-21 22:59:09 -06:00
string str = null ;
2021-02-21 21:52:41 -06:00
if ( this . IsValid )
str = this . _device . PicturesVideosViewUrl ;
return str ?? string . Empty ;
}
}
public bool HasRestorePoint => this . SupportsRestorePoint && this . UIFirmwareRestorer != null && this . UIFirmwareRestorer . RestorePoint != null ;
public string RestorePointDate => ! this . HasRestorePoint ? string . Empty : StringFormatHelper . Format ( this . UIFirmwareRestorer . RestorePoint . CreationDate . ToLocalTime (), StringFormatHelper . FriendlyMonthYearPattern );
public string Manufacturer
{
get
{
2021-02-21 22:59:09 -06:00
string strManufacturer = null ;
2021-02-21 21:52:41 -06:00
if ( this . IsValid )
this . _device . GetManufacturer ( ref strManufacturer );
return strManufacturer ?? string . Empty ;
}
}
public string ModelName
{
get
{
2021-02-21 22:59:09 -06:00
string strModelName = null ;
2021-02-21 21:52:41 -06:00
if ( this . IsValid )
this . _device . GetModelName ( ref strModelName );
return strModelName ?? string . Empty ;
}
}
public bool IsConnectedToPC => this . IsValid && this . _lastDeviceState >= EEndpointStatus . eEndpointStatusConnected ;
public bool IsConnectedToClient => this . IsValid && this . _lastDeviceState >= EEndpointStatus . eEndpointStatusAvailable ;
public bool IsConnectedToClientWirelessly => this . IsValid && this . IsConnectedToClient && this . _device . IsConnectedWirelessly ;
public bool IsConnectedToClientPhysically => this . IsConnectedToClient && ! this . IsConnectedToClientWirelessly ;
public bool IsConnectedToSideloader => this . IsValid && this . _lastDeviceState == EEndpointStatus . eEndpointStatusInUse ;
public string OwnerApplicationName => ! this . IsConnectedToSideloader ? string . Empty : this . _device . OwnerApplicationName ;
public bool IsReadyForSync
{
get => this . IsConnectedToClient && this . _isReadyForSync ;
private set
{
if (! this . IsValid || this . _isReadyForSync == value )
return ;
this . _isReadyForSync = value ;
this . FirePropertyChanged ( nameof ( IsReadyForSync ));
}
}
public bool IsFormatting
{
get => this . _currentlyFormatting ;
private set
{
if (! this . IsValid || this . _currentlyFormatting == value )
return ;
this . _currentlyFormatting = value ;
this . FirePropertyChanged ( nameof ( IsFormatting ));
}
}
public bool IsLockedAgainstSyncing
{
get => this . _isLocked ;
set
{
if (! this . IsValid || this . _isLocked == value )
return ;
this . _isLocked = value ;
if (! this . _isLocked )
return ;
this . EndSync ();
}
}
public bool UserStoppedLastSync
{
get => this . _userStoppedLastSync ;
private set
{
if ( this . _userStoppedLastSync == value )
return ;
this . _userStoppedLastSync = value ;
this . FirePropertyChanged ( nameof ( UserStoppedLastSync ));
}
}
public HRESULT LastFailedLoginError
{
get => this . _lastLoginFailure ;
set
{
if (!( this . _lastLoginFailure != value ))
return ;
this . _lastLoginFailure = value ;
this . FirePropertyChanged ( nameof ( LastFailedLoginError ));
this . FirePropertyChanged ( "HasFailedLogin" );
}
}
public bool HasFailedLogin => this . LastFailedLoginError . IsError ;
public HRESULT LastSyncError
{
get => this . _lastSyncFailure ;
private set
{
if (!( this . _lastSyncFailure != value ))
return ;
this . _lastSyncFailure = value ;
this . FirePropertyChanged ( nameof ( LastSyncError ));
this . FirePropertyChanged ( "HasFailedSync" );
}
}
public bool HasFailedSync => this . LastSyncError . IsError ;
2021-02-21 22:59:09 -06:00
public string PivotDescription => Shell . LoadString ( StringId . IDS_DEVICE_PIVOT );
2021-02-21 21:52:41 -06:00
public bool IsWirelessSyncEnabled
{
get => this . IsValid && this . _isWirelessSyncEnabled ;
private set
{
if ( this . _isWirelessSyncEnabled == value )
return ;
this . _isWirelessSyncEnabled = value ;
this . FirePropertyChanged ( nameof ( IsWirelessSyncEnabled ));
}
}
public DeviceRelationship Relationship
{
get
{
DeviceRelationship deviceRelationship = DeviceRelationship . None ;
if ( this . IsValid )
{
ESyncRelationship relationship = ESyncRelationship . srNone ;
if ((( HRESULT ) this . _device . GetSyncRelationship ( ref relationship )). IsSuccess )
deviceRelationship = ( DeviceRelationship ) relationship ;
}
return deviceRelationship ;
}
set
{
if (! this . IsValid || this . Relationship == value )
return ;
this . _device . SetSyncRelationship (( ESyncRelationship ) value );
if ( value == DeviceRelationship . Permanent )
this . SetGeoId ();
this . _device . SetTimeZoneBias ( Convert . ToInt32 ( TimeZone . CurrentTimeZone . GetUtcOffset ( DateTime . Now ). TotalMinutes ));
int num = this . HasFailedLogin ? 1 : 0 ;
this . FirePropertyChanged ( nameof ( Relationship ));
}
}
public bool IsGuest
{
get
{
if (! this . IsValid )
return false ;
return this . Relationship == DeviceRelationship . Guest || this . Relationship == DeviceRelationship . None ;
}
}
public string GetLocalizedDevicePath ( string devicePath )
{
if (! this . IsValid )
return devicePath ;
string strPath = devicePath ;
return !(( HRESULT ) this . _device . GetLocalizedDevicePath ( ref strPath )). IsSuccess ? devicePath : strPath ;
}
public string Name
{
get
{
if (! this . IsValid )
2021-02-21 22:59:09 -06:00
return Shell . LoadString ( StringId . IDS_NO_DEVICE );
string strName = null ;
return !(( HRESULT ) this . _device . GetFriendlyName ( ref strName )). IsSuccess ? Shell . LoadString ( StringId . IDS_SYNC_DEFAULT_DEVICE_WORD ) : strName ;
2021-02-21 21:52:41 -06:00
}
set
{
if (! this . IsConnectedToClient )
return ;
this . _device . SetFriendlyName ( value );
}
}
public string NameXMLEscaped => SecurityElement . Escape ( this . Name );
public bool IsPermanentGuest
{
get
{
bool bPromptGuest = true ;
if ( this . IsValid )
this . _device . GetPromptGuest ( ref bPromptGuest );
return ! bPromptGuest ;
}
set
{
if (! this . IsValid || this . IsPermanentGuest == value )
return ;
this . _device . SetPromptGuest (! value );
this . FirePropertyChanged ( nameof ( IsPermanentGuest ));
}
}
public Guid UserGuid
{
get
{
Guid empty = Guid . Empty ;
if ( this . IsValid )
this . _device . GetUserGuid ( ref empty );
return empty ;
}
}
public int UserId
{
get
{
int userId = 0 ;
if ( this . IsValid )
this . _device . GetUserId ( ref userId );
return userId ;
}
}
public string ZuneTag
{
get
{
string empty = string . Empty ;
if ( this . IsConnectedToClient )
this . _device . GetZuneTag ( ref empty );
return empty ;
}
}
public string LiveId
{
get
{
string empty = string . Empty ;
if ( this . SupportsLiveId )
this . _device . GetLiveId ( ref empty );
return empty ;
}
}
public bool OOBECompleted
{
get
{
bool oobeCompleted = false ;
if ( this . SupportsOOBECompleted && this . IsConnectedToClient )
{
if (! this . _device . InStandardMode )
return true ;
this . _device . GetOOBECompleted ( ref oobeCompleted );
}
return oobeCompleted ;
}
}
public bool ExcludeDislikedContent
{
get
{
bool fDontSyncHatedContent = false ;
if ( this . IsValid )
this . _device . Rules . GetDontSyncHatedContent ( ref fDontSyncHatedContent );
return fDontSyncHatedContent ;
}
set
{
if (! this . IsValid || this . ExcludeDislikedContent == value )
return ;
this . _device . Rules . SetDontSyncHatedContent ( value );
this . FirePropertyChanged ( nameof ( ExcludeDislikedContent ));
}
}
private bool ReverseSyncPicsFromPhone
{
get
{
bool bReverseSync = false ;
if ( this . IsValid )
this . _device . GetPhotoVideoReverseSync ( ref bReverseSync );
return bReverseSync ;
}
set
{
if (! this . IsValid || this . ReverseSyncPicsFromPhone == value )
return ;
this . _device . SetPhotoVideoReverseSync ( value );
this . FirePropertyChanged ( nameof ( ReverseSyncPicsFromPhone ));
}
}
public bool DeletePicsFromPhoneAfterReverseSync
{
get
{
bool bDeleteAfterSync = false ;
if ( this . IsValid )
this . _device . GetDeletePhotoVideoAfterReverseSync ( ref bDeleteAfterSync );
return bDeleteAfterSync ;
}
set
{
if (! this . IsValid || this . DeletePicsFromPhoneAfterReverseSync == value )
return ;
this . _device . SetDeletePhotoVideoAfterReverseSync ( value );
this . FirePropertyChanged ( nameof ( DeletePicsFromPhoneAfterReverseSync ));
}
}
public ETranscodePhotoSetting ImageTranscodeQuality
{
get
{
ETranscodePhotoSetting ePhotoSetting = ETranscodePhotoSetting . tsPhotoSettingInvalid ;
if ( this . IsValid )
this . _device . GetPhotoTranscodeSetting ( ref ePhotoSetting );
return ePhotoSetting ;
}
set
{
if (! this . IsValid || this . ImageTranscodeQuality == value )
return ;
this . _device . SetPhotoTranscodeSetting ( value );
this . FirePropertyChanged ( nameof ( ImageTranscodeQuality ));
}
}
public string CameraRollDestinationPath
{
get
{
string empty = string . Empty ;
if ( this . IsValid )
this . _device . GetCameraRollDestinationFolder ( ref empty );
return empty ;
}
set
{
if (! this . IsValid )
return ;
this . _device . SetCameraRollDestinationFolder ( value );
this . FirePropertyChanged ( nameof ( CameraRollDestinationPath ));
}
}
public string SavedFolderDestinationPath
{
get
{
string empty = string . Empty ;
if ( this . IsValid )
this . _device . GetSavedDestinationFolder ( ref empty );
return empty ;
}
set
{
if (! this . IsValid )
return ;
this . _device . SetSavedDestinationFolder ( value );
this . FirePropertyChanged ( nameof ( SavedFolderDestinationPath ));
}
}
public int AudioTranscodeLimit
{
get
{
int audioThresholdBitRate = 0 ;
int audioTargetBitRate = 0 ;
if ( this . IsValid )
this . _device . GetAudioTranscodeParams ( ref audioThresholdBitRate , ref audioTargetBitRate );
return audioThresholdBitRate ;
}
set
{
if (! this . IsValid )
return ;
this . _device . SetAudioTranscodeParams ( value , this . AudioTranscodeTarget );
this . FirePropertyChanged ( nameof ( AudioTranscodeLimit ));
}
}
public int AudioTranscodeTarget
{
get
{
int audioThresholdBitRate = 0 ;
int audioTargetBitRate = 0 ;
if ( this . IsValid )
this . _device . GetAudioTranscodeParams ( ref audioThresholdBitRate , ref audioTargetBitRate );
return audioTargetBitRate ;
}
set
{
if (! this . IsValid )
return ;
this . _device . SetAudioTranscodeParams ( this . AudioTranscodeLimit , value );
this . FirePropertyChanged ( nameof ( AudioTranscodeTarget ));
}
}
public bool OptimizeVideoForTV
{
get
{
ETranscodeOptimization transcodeOptimization = ETranscodeOptimization . toOptimizeForSize ;
if ( this . IsValid )
this . _device . GetVideoTranscodeOptimization ( ref transcodeOptimization );
return transcodeOptimization == ETranscodeOptimization . toOptimizeForQuality ;
}
set
{
if (! this . IsValid || this . OptimizeVideoForTV == value )
return ;
if ( value )
this . _device . SetVideoTranscodeOptimization ( ETranscodeOptimization . toOptimizeForQuality );
else
this . _device . SetVideoTranscodeOptimization ( ETranscodeOptimization . toOptimizeForSize );
this . FirePropertyChanged ( nameof ( OptimizeVideoForTV ));
}
}
public bool PurchaseEnabled
{
get
{
bool purchaseEnabled = false ;
if ( this . IsConnectedToClient )
this . _device . GetPurchaseEnabled ( ref purchaseEnabled );
return purchaseEnabled ;
}
set
{
if (! this . IsConnectedToClient || this . PurchaseEnabled == value )
return ;
this . _device . SetPurchaseEnabled ( value );
this . FirePropertyChanged ( nameof ( PurchaseEnabled ));
}
}
public int PercentReserved
{
get
{
uint ulPercentage = 0 ;
if ( this . IsValid )
this . _device . GetPercentSpaceReserved ( ref ulPercentage );
return ( int ) ulPercentage ;
}
set
{
if (! this . IsValid )
return ;
this . _device . SetPercentSpaceReserved (( uint ) value );
this . FirePropertyChanged ( nameof ( PercentReserved ));
}
}
public bool PromptForAccountLinkage
{
get
{
bool bPromptLink = false ;
if ( this . IsValid )
this . _device . GetPromptLink ( ref bPromptLink );
return bPromptLink ;
}
set
{
if (! this . IsValid )
return ;
this . _device . SetPromptLink ( value );
this . FirePropertyChanged ( nameof ( PromptForAccountLinkage ));
}
}
public bool RequiresClientUpdate => this . IsConnectedToClient && this . _device . ClientUpdateRequired ;
public bool RequiresFirmwareUpdate => this . IsConnectedToClient && this . _device . FirmwareUpdateRequired ;
public UIFirmwareUpdater UIFirmwareUpdater
{
get
{
if ( this . _firmwareUpdater == null && this . IsValid && ( this . _device . FirmwareUpdater != null && this . IsConnectedToClientPhysically ))
this . UIFirmwareUpdater = new UIFirmwareUpdater ( this , this . _device . FirmwareUpdater );
return this . _firmwareUpdater ;
}
private set
{
if ( this . _firmwareUpdater == value )
return ;
this . _firmwareUpdater = value ;
this . FirePropertyChanged ( nameof ( UIFirmwareUpdater ));
}
}
public UIFirmwareRestorer UIFirmwareRestorer
{
get
{
if ( this . _firmwareRestorer == null && this . IsValid && ( this . _device . FirmwareUpdater != null && this . IsConnectedToClientPhysically ))
this . UIFirmwareRestorer = new UIFirmwareRestorer ( this . _device . FirmwareUpdater . Restorer , this . RequiresAutoRestore );
return this . _firmwareRestorer ;
}
private set
{
this . _firmwareRestorer = value ;
this . FirePropertyChanged ( nameof ( UIFirmwareRestorer ));
}
}
public string FirmwareVersion
{
get
{
string empty = string . Empty ;
if ( this . IsConnectedToClient )
this . _device . GetFirmwareVersion ( ref empty );
return empty ;
}
}
public bool IsSyncing
{
get => this . _currentlySyncing ;
private set
{
if (! this . IsValid || this . _currentlySyncing == value )
return ;
this . _currentlySyncing = value ;
this . FirePropertyChanged ( nameof ( IsSyncing ));
}
}
public SyncNotification SyncProgress
{
get => this . _syncProgress ;
private set
{
if (! this . IsValid || this . _syncProgress == value )
return ;
this . _syncProgress = value ;
this . FirePropertyChanged ( nameof ( SyncProgress ));
}
}
public Command SyncBegun => this . _syncBegun ;
public Command SyncProgressed => this . _syncProgressed ;
public Command SyncCompleted => this . _syncCompleted ;
private Microsoft . Iris . Timer FormatSanityTimer
{
get
{
if ( this . _formatSanityTimer == null )
{
2021-02-21 22:59:09 -06:00
this . _formatSanityTimer = new Microsoft . Iris . Timer ( this );
2021-02-21 21:52:41 -06:00
this . _formatSanityTimer . Interval = 60000 ;
this . _formatSanityTimer . AutoRepeat = false ;
this . _formatSanityTimer . Tick += new EventHandler ( this . FormatSanityFailed );
}
return this . _formatSanityTimer ;
}
}
public DateTime LastConnectTime
{
get
{
DateTime dateTime = DateTime . MinValue ;
if ( this . IsValid )
dateTime = this . _device . LastConnectTime ;
return dateTime ;
}
}
public string LastSyncTime
{
get
{
string str = string . Empty ;
if ( this . IsValid )
{
DateTime lastSyncTime = this . _device . LastSyncTime ;
if ( lastSyncTime . Year >= 2006 )
str = !( lastSyncTime . Date == DateTime . Now . Date ) ? lastSyncTime . ToString ( "d" ) : lastSyncTime . ToString ( "t" );
}
return str ;
}
}
public string LastConnectTimestring
{
get => this . _lastConnectTimestring ?? string . Empty ;
private set
{
if (!( this . _lastConnectTimestring != value ))
return ;
this . _lastConnectTimestring = value ;
this . FirePropertyChanged ( nameof ( LastConnectTimestring ));
}
}
public string LastSyncStartTimestring
{
get => this . _lastSyncStartTimestring ?? this . LastConnectTimestring ;
private set
{
if (!( this . _lastSyncStartTimestring != value ))
return ;
this . _lastSyncStartTimestring = value ;
this . FirePropertyChanged ( nameof ( LastSyncStartTimestring ));
}
}
public UIGasGauge ActualGasGauge
{
get => this . _actualGasGauge ;
private set
{
if ( this . _actualGasGauge == value )
return ;
this . _actualGasGauge = value ;
this . FirePropertyChanged ( nameof ( ActualGasGauge ));
}
}
public UIGasGauge PredictedGasGauge
{
get => this . _predictedGasGauge ;
private set
{
if ( this . _predictedGasGauge == value )
return ;
this . _predictedGasGauge = value ;
this . FirePropertyChanged ( nameof ( PredictedGasGauge ));
}
}
public bool EnableWatson
{
get
{
uint dwWatsonSetting = 0 ;
if ( this . IsConnectedToClient )
this . _device . GetWatsonSetting ( ref dwWatsonSetting );
return dwWatsonSetting > 0 U ;
}
set
{
if (! this . IsConnectedToClient || this . EnableWatson == value )
return ;
this . _device . SetWatsonSetting ( value ? 1 U : 0 U );
this . FirePropertyChanged ( nameof ( EnableWatson ));
}
}
public SyncMode GetSyncMode ( SyncCategory schema ) => this . GetSyncMode ( schema , false );
internal SyncMode GetSyncMode ( SyncCategory schema , bool fEstablishingPartnership )
{
ESyncMode mode = ESyncMode . eSyncModeInvalid ;
if ( this . IsValid && this . SupportsSyncCategory ( schema ))
this . _device . Rules . GetCategorySyncMode (( ESyncCategory ) schema , ref mode , fEstablishingPartnership );
return ( SyncMode ) mode ;
}
public void SetSyncMode ( SyncCategory schema , SyncMode mode )
{
if (! this . IsValid )
return ;
this . _device . Rules . SetCategorySyncMode (( ESyncCategory ) schema , ( ESyncMode ) mode );
}
public bool IsManualFor ( MediaType type ) => this . IsManualFor ( UIDeviceList . MapMediaTypeToSyncCategory ( type ));
public bool IsManualFor ( SyncCategory type ) => this . IsManualFor ( type , false );
internal bool IsManualFor ( SyncCategory type , bool fEstablishingPartnership ) => this . GetSyncMode ( type , fEstablishingPartnership ) == SyncMode . Manual ;
public bool IsSyncAllFor ( MediaType schema ) => this . IsSyncAllFor ( UIDeviceList . MapMediaTypeToSyncCategory ( schema ));
public bool IsSyncAllFor ( SyncCategory schema ) => this . IsSyncAllFor ( schema , false );
internal bool IsSyncAllFor ( SyncCategory schema , bool fEstablishingPartnership ) => this . GetSyncMode ( schema , fEstablishingPartnership ) == SyncMode . SyncAll ;
public void AddSyncRule ( IList items )
{
throw new NotImplementedException ();
/*// ISSUE: object of a compiler-generated type is created
// ISSUE: variable of a compiler-generated type
UIDevice.c__DisplayClass6 cDisplayClass6_1 = new UIDevice.c__DisplayClass6();
// ISSUE: reference to a compiler-generated field
cDisplayClass6_1.items = items;
// ISSUE: reference to a compiler-generated field
cDisplayClass6_1.<>4__this = this;
// ISSUE: reference to a compiler-generated field
// ISSUE: reference to a compiler-generated field
if (cDisplayClass6_1.items == null || cDisplayClass6_1.items.Count <= 0 || !this.IsValid)
return;
TypeDiscoveringSyncEventArgs args = new TypeDiscoveringSyncEventArgs();
args.Device = this._device;
long startingSize = this.ActualGasGauge.UsedSpace;
// ISSUE: reference to a compiler-generated field
this.MaterializeMarketplaceMedia(cDisplayClass6_1.items);
// ISSUE: reference to a compiler-generated field
MediaIdAndType[] threadSafeItems = this.GenerateThreadSafeDatabaseItems(cDisplayClass6_1.items);
ThreadPool.QueueUserWorkItem((WaitCallback) delegate
{
// ISSUE: variable of a compiler-generated type
UIDevice.c__DisplayClass6 cDisplayClass6 = cDisplayClass6_1;
bool actionSucceeded = LibraryDataProvider.ActOnItems((IList) threadSafeItems, BulkItemAction.AddSyncRules, (EventArgs) args);
Application.DeferredInvoke((DeferredInvokeHandler) delegate
{
if (actionSucceeded)
{
string message = (string) null;
MediaType mediaType = args.ContainedTypes == null || args.ContainedTypes.Count != 1 ? MediaType.Undefined : (MediaType) args.ContainedTypes[0];
// ISSUE: reference to a compiler-generated field
if (mediaType == MediaType.Playlist && cDisplayClass6.items[0] is IDatabaseMedia databaseMedia)
{
int mediaId;
databaseMedia.GetMediaIdAndType(out mediaId, out EMediaTypes _);
if (PlaylistManager.IsChannel(mediaId))
{
// ISSUE: reference to a compiler-generated field
message = UIDevice._channelNewRuleMessage.GetMessageForCount(cDisplayClass6.items.Count);
}
}
if (message == null)
{
foreach (UIDevice.INewRuleMessageType newRuleMessageType in UIDevice._newRuleMessageLookupTable)
{
if (newRuleMessageType.Type == mediaType)
{
// ISSUE: reference to a compiler-generated field
message = newRuleMessageType.GetMessageForCount(cDisplayClass6.items.Count);
break;
}
}
}
if (message == null)
{
// ISSUE: reference to a compiler-generated field
message = UIDevice._genericNewRuleMessage.GetMessageForCount(cDisplayClass6.items.Count);
}
// ISSUE: reference to a compiler-generated field
NotificationArea.Instance.Override((Notification) new SyncNewRuleAddedNotification(message, startingSize, cDisplayClass6.<>4__this.PredictedGasGauge));
}
// ISSUE: reference to a compiler-generated field
cDisplayClass6.<>4__this.BeginSync(true, false);
}, (object) null);
}, (object) null);*/
}
2021-02-21 22:59:09 -06:00
public void AddPlaylistSyncRule ( int dbPlaylistId ) => this . AddSyncRule ( new MediaIdAndType [ 1 ]
2021-02-21 21:52:41 -06:00
{
new MediaIdAndType ( dbPlaylistId , MediaType . Playlist )
});
public void RemoveSyncRule ( IList items )
{
if ( items == null || items . Count <= 0 || ! this . IsValid )
return ;
SyncEventArgs args = new SyncEventArgs ();
args . Device = this . _device ;
MediaIdAndType [] threadSafeItems = this . GenerateThreadSafeDatabaseItems ( items );
2021-02-21 22:59:09 -06:00
ThreadPool . QueueUserWorkItem ( delegate
2021-02-21 21:52:41 -06:00
{
2021-02-21 22:59:09 -06:00
LibraryDataProvider . ActOnItems ( threadSafeItems , BulkItemAction . RemoveSyncRules , args );
Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
2021-02-21 22:59:09 -06:00
this . BeginSync ( true , false );
}, null );
}, null );
2021-02-21 21:52:41 -06:00
}
public void Exclude ( IList items )
{
if ( items == null || items . Count <= 0 || ! this . IsValid )
return ;
SyncEventArgs args = new SyncEventArgs ();
args . Device = this . _device ;
MediaIdAndType [] threadSafeItems = this . GenerateThreadSafeDatabaseItems ( items );
bool shouldBeginSyncAfter = false ;
2021-02-21 22:59:09 -06:00
foreach ( object obj in items )
2021-02-21 21:52:41 -06:00
{
if ( obj is LibraryDataProviderItemBase providerItemBase )
{
object property = providerItemBase . GetProperty ( "SyncState" );
if ( property != null )
{
switch (( ESyncState ) property )
{
case ESyncState . eSyncStateCurrentlySyncing :
case ESyncState . eSyncStateOnDevice :
break ;
default :
continue ;
}
}
}
shouldBeginSyncAfter = true ;
break ;
}
2021-02-21 22:59:09 -06:00
ThreadPool . QueueUserWorkItem ( delegate
2021-02-21 21:52:41 -06:00
{
2021-02-21 22:59:09 -06:00
LibraryDataProvider . ActOnItems ( threadSafeItems , BulkItemAction . ExcludeFromSync , args );
2021-02-21 21:52:41 -06:00
if (! shouldBeginSyncAfter )
return ;
2021-02-21 22:59:09 -06:00
Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
2021-02-21 22:59:09 -06:00
this . BeginSync ( true , false );
}, null );
}, null );
2021-02-21 21:52:41 -06:00
}
public void Unexclude ( IList items )
{
if ( items == null || items . Count <= 0 || ! this . IsValid )
return ;
SyncEventArgs args = new SyncEventArgs ();
args . Device = this . _device ;
MediaIdAndType [] threadSafeItems = this . GenerateThreadSafeDatabaseItems ( items );
2021-02-21 22:59:09 -06:00
ThreadPool . QueueUserWorkItem ( delegate
2021-02-21 21:52:41 -06:00
{
2021-02-21 22:59:09 -06:00
LibraryDataProvider . ActOnItems ( threadSafeItems , BulkItemAction . UnexcludeFromSync , args );
Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
2021-02-21 22:59:09 -06:00
this . BeginSync ( true , false );
}, null );
}, null );
2021-02-21 21:52:41 -06:00
}
public void DeleteAndExclude ( IList items )
{
if ( items == null || items . Count <= 0 || ! this . IsReadyForSync )
return ;
DeferrableSyncEventArgs args = new DeferrableSyncEventArgs ();
args . Device = this . _device ;
MediaIdAndType [] threadSafeItems = this . GenerateThreadSafeDatabaseItems ( items );
2021-02-21 22:59:09 -06:00
ThreadPool . QueueUserWorkItem ( delegate
2021-02-21 21:52:41 -06:00
{
2021-02-21 22:59:09 -06:00
LibraryDataProvider . ActOnItems ( threadSafeItems , BulkItemAction . DeleteFromDevice , args );
}, null );
2021-02-21 21:52:41 -06:00
}
public SyncGroupList GenerateSyncGroupList (
IModelItemOwner owner ,
bool expandSyncAllEntries )
{
2021-02-21 22:59:09 -06:00
SyncRulesView syncRulesView = null ;
2021-02-21 21:52:41 -06:00
if ( this . IsValid )
{
2021-02-21 22:59:09 -06:00
HRESULT snapshot = this . _device . Rules . GenerateSnapshot ( expandSyncAllEntries , ref syncRulesView );
2021-02-21 21:52:41 -06:00
}
return new SyncGroupList ( owner , this , syncRulesView , expandSyncAllEntries );
}
public PodcastSyncLimit GetPodcastSyncLimit ( int podcastID )
{
EDeviceSyncRuleType ruleType = EDeviceSyncRuleType . eDeviceSyncRuleTypeInvalid ;
if ( this . IsValid )
this . _device . Rules . GetSyncRuleForMedia ( EMediaTypes . eMediaTypePodcastSeries , podcastID , ref ruleType );
return ( PodcastSyncLimit ) ruleType ;
}
public void SetPodcastSyncLimit ( int podcastID , PodcastSyncLimit limit )
{
if (! this . IsValid )
return ;
this . _device . Rules . Add ( new int [ 1 ] { podcastID }, EMediaTypes . eMediaTypePodcastSeries , ( EDeviceSyncRuleType ) limit );
}
public int GetPodcastSyncLimitWithValue ( int podcastID )
{
int iValue = - 1 ;
if ( this . IsValid && this . _device != null && this . _device . Rules != null )
this . _device . Rules . GetSyncRuleValueForMedia ( podcastID , ref iValue );
return iValue ;
}
public void SetPodcastSyncLimitWithValue ( int podcastID , int value )
{
if (! this . IsValid )
return ;
int [] rgIds = new int [ 1 ] { podcastID };
if ( this . _device == null || this . _device . Rules == null )
return ;
this . _device . Rules . AddDeviceSyncRuleWithValue ( rgIds , value );
}
public void BeginSync () => this . BeginSync ( false , false );
public void BeginSync ( bool userInitiated , bool syncOnNextNotify )
{
if (! this . IsReadyForSync || this . IsLockedAgainstSyncing || ! userInitiated && this . UserStoppedLastSync )
return ;
if ( syncOnNextNotify )
this . _device . StartSyncNextNotify ();
else
this . _device . StartSync ();
}
public void EndSync () => this . EndSync ( false );
public void EndSync ( bool userInitiated )
{
if ( this . SyncProgress != null )
this . SyncProgress . SyncCanceled = true ;
if ( this . IsConnectedToClient )
this . _device . StopSync ();
if (! userInitiated )
return ;
if ( this . IsGuest )
this . _device . ClearRules ();
else
this . _device . ClearManualModeRules ();
this . UserStoppedLastSync = true ;
}
public bool ReverseSync ( IList items )
{
if ( items != null && items . Count > 0 && ( this . IsConnectedToClient && this . IsReadyForSync ))
{
DeferrableSyncEventArgs deferrableSyncEventArgs = new DeferrableSyncEventArgs ();
deferrableSyncEventArgs . Device = this . _device ;
2021-02-21 22:59:09 -06:00
LibraryDataProvider . ActOnItems ( items , BulkItemAction . ReverseSync , deferrableSyncEventArgs );
2021-02-21 21:52:41 -06:00
if ( deferrableSyncEventArgs . Status == ESyncOperationStatus . osDeferred )
return false ;
}
return true ;
}
2021-02-21 22:59:09 -06:00
public HRESULT Enumerate () => ! this . IsConnectedToClient ? HRESULT . _E_UNEXPECTED : this . _device . StartEnumeration ();
2021-02-21 21:52:41 -06:00
public HRESULT Format ()
{
if (! this . IsConnectedToClient )
return HRESULT . _E_UNEXPECTED ;
this . IsFormatting = true ;
2021-02-21 22:59:09 -06:00
return this . _device . Format ();
2021-02-21 21:52:41 -06:00
}
public HRESULT DeleteAllGuestContent ()
{
if (! this . IsConnectedToClient )
return HRESULT . _E_UNEXPECTED ;
ESyncOperationStatus operationStatus = ESyncOperationStatus . osInvalid ;
2021-02-21 22:59:09 -06:00
return this . _device . DeleteAllGuestContent ( ref operationStatus );
2021-02-21 21:52:41 -06:00
}
2021-02-21 22:59:09 -06:00
public HRESULT ForceAppUpdate () => ! this . IsConnectedToClient ? HRESULT . _E_UNEXPECTED : this . _device . ForceAppUpdate ();
2021-02-21 21:52:41 -06:00
public HRESULT ClearAccountAssociation ()
{
HRESULT hresult = HRESULT . _E_UNEXPECTED ;
if ( this . IsConnectedToClient )
{
2021-02-21 22:59:09 -06:00
hresult = this . _device . ClearUserGuidandZuneTag ();
2021-02-21 21:52:41 -06:00
int num = this . HasFailedLogin ? 1 : 0 ;
this . FirePropertyChanged ( "UserId" );
this . FirePropertyChanged ( "ZuneTag" );
this . PurchaseEnabled = false ;
}
return hresult ;
}
public HRESULT AssociateWithAccount ( Guid guid , string tag )
{
HRESULT hresult = HRESULT . _E_UNEXPECTED ;
if ( this . IsConnectedToClient )
{
2021-02-21 22:59:09 -06:00
hresult = this . _device . SetUserGuidandZuneTag ( guid , tag );
2021-02-21 21:52:41 -06:00
if ( hresult . IsSuccess )
hresult = this . SetGeoId ();
int num = this . HasFailedLogin ? 1 : 0 ;
this . FirePropertyChanged ( "UserId" );
this . FirePropertyChanged ( "ZuneTag" );
}
return hresult ;
}
public void SendMarketplaceCredentials ( string username , string password )
{
if (! this . IsConnectedToClient )
return ;
2021-02-21 22:59:09 -06:00
SecureString secureUsername = Shell . MakeSecureString ( username , true );
SecureString securePassword = Shell . MakeSecureString ( password , true );
ThreadPool . QueueUserWorkItem ( delegate
2021-02-21 21:52:41 -06:00
{
this . _device . SetMarketplaceCredentials ( secureUsername , securePassword );
});
}
public HRESULT SetGeoId ()
{
HRESULT hresult = HRESULT . _E_UNEXPECTED ;
if ( this . IsValid )
{
uint num = CultureHelper . GeoId ();
if (! CultureHelper . IsValidGeoId ( num ))
num = 0 U ;
2021-02-21 22:59:09 -06:00
hresult = this . _device . SetGeoId ( num );
2021-02-21 21:52:41 -06:00
}
return hresult ;
}
2021-02-21 22:59:09 -06:00
public HRESULT RemoveWiFiAssociation () => ! this . IsConnectedToClient ? HRESULT . _E_UNEXPECTED : this . _device . UnassociateWlanDevice ();
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
public HRESULT SetWiFiProfileList ( WlanProfileList list ) => ! this . IsConnectedToClient ? HRESULT . _E_UNEXPECTED : this . _device . SetWlanProfileList ( list );
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
public HRESULT GetWiFiProfileList ( ref WlanProfileList list ) => ! this . IsConnectedToClient ? HRESULT . _E_UNEXPECTED : this . _device . GetWlanProfileList ( ref list );
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
public HRESULT SendWiFiProfiles () => ! this . IsConnectedToClient ? HRESULT . _E_UNEXPECTED : this . _device . SetDeviceWlanProfiles ();
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
public HRESULT ReceiveWiFiProfiles () => ! this . IsConnectedToClient ? HRESULT . _E_UNEXPECTED : this . _device . GetDeviceWlanProfiles ();
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
public HRESULT TestWiFi () => ! this . IsConnectedToClient ? HRESULT . _E_UNEXPECTED : this . _device . TestDeviceWlan ();
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
public HRESULT CancelWiFiTest () => ! this . IsConnectedToClient ? HRESULT . _E_UNEXPECTED : this . _device . CancelTestDeviceWlan ();
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
public HRESULT AssociateWiFi () => ! this . IsConnectedToClient ? HRESULT . _E_UNEXPECTED : this . _device . AssociateWlanDevice ();
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
public HRESULT LoadComputerWiFiProfiles () => ! this . IsConnectedToClient ? HRESULT . _E_UNEXPECTED : this . _device . GetWlanProfiles ();
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
public HRESULT ScanForWiFiNetworks () => ! this . IsConnectedToClient ? HRESULT . _E_UNEXPECTED : this . _device . GetDeviceWlanNetworks ();
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
public HRESULT GetDisconnectedWiFiUUID ( ref string uuid ) => ! this . IsValid ? HRESULT . _E_UNEXPECTED : this . _device . GetDisconnectedWlanDeviceUuid ( ref uuid );
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
public HRESULT UnassociateWiFiUUID ( string uuid ) => ! this . IsValid ? HRESULT . _E_UNEXPECTED : this . _device . UnassociateWlanDeviceUuid ( uuid );
2021-02-21 21:52:41 -06:00
public bool WirelessEnableRequiresElevation ()
{
bool bEnabled = true ;
if ( this . IsValid )
this . _device . IsWlanFirewallEnabled ( ref bEnabled );
return Environment . OSVersion . Version . Major >= 6 && ! bEnabled ;
}
2021-02-21 22:59:09 -06:00
public HRESULT GetWiFiAuthorizationCipherList ( ref WlanAuthCipherPairList list ) => ! this . IsConnectedToClient ? HRESULT . _E_UNEXPECTED : this . _device . GetWlanDeviceAuthCipherPairList ( ref list );
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
public HRESULT GetWifiConnectedSSID ( ref string connectedSSID ) => ! this . IsConnectedToClient ? HRESULT . _E_UNEXPECTED : this . _device . GetDeviceWlanConnectedSSID ( ref connectedSSID );
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
public HRESULT IsWlanDeviceDisabled ( ref bool disabled ) => ! this . IsConnectedToClient ? HRESULT . _E_UNEXPECTED : this . _device . IsWlanDeviceDisabled ( ref disabled );
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
public HRESULT GetWifiMediaSyncSSID ( ref string mediaSyncSSID ) => ! this . IsConnectedToClient ? HRESULT . _E_UNEXPECTED : this . _device . GetDeviceWlanMediaSyncSSID ( ref mediaSyncSSID );
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
public HRESULT SetWifiMediaSyncSSID ( string mediaSyncSSID ) => ! this . IsConnectedToClient ? HRESULT . _E_UNEXPECTED : this . _device . SetDeviceWlanMediaSyncSSID ( mediaSyncSSID );
2021-02-21 21:52:41 -06:00
public override bool Equals ( object obj ) => obj is UIDevice uiDevice ? this . _device == uiDevice . _device : base . Equals ( obj );
public override int GetHashCode () => this . _device == null ? 0 : this . _device . GetHashCode ();
public bool SupportsRentalOfVideo ( bool isHD )
{
if (! this . SupportsRental )
return false ;
return ! isHD || this . SupportsHD ;
}
public bool SupportsBrandingType ( DeviceBranding brand )
{
bool flag = false ;
switch ( this . Class )
{
case DeviceClass . Invalid :
case DeviceClass . Reserved :
return flag ;
case DeviceClass . WindowsPhone :
flag = brand == DeviceBranding . WindowsPhone ;
goto case DeviceClass . Invalid ;
case DeviceClass . Kin :
flag = brand == DeviceBranding . Kin ;
goto case DeviceClass . Invalid ;
default :
flag = brand == DeviceBranding . Zune ;
goto case DeviceClass . Invalid ;
}
}
2021-02-21 22:59:09 -06:00
private void OnNameChange ( Device device , string newName ) => Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
if ( this . IsDisposed )
return ;
this . FirePropertyChanged ( "Name" );
this . FirePropertyChanged ( "NameXMLEscaped" );
2021-02-21 22:59:09 -06:00
}, null );
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
private void OnDeviceOverfill ( GasGauge gasGauge ) => Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
if ( this . IsDisposed )
return ;
this . EndSync ();
if ( this . IsGuest )
this . _device . ClearRules ();
ZuneShell shell = ZuneShell . DefaultInstance ;
if ( shell . CurrentPage is PlaybackPage )
shell . NavigateBack ();
2021-02-21 22:59:09 -06:00
if ( shell . CurrentPage is DialogPage || _isOosDialogVisible )
2021-02-21 21:52:41 -06:00
return ;
2021-02-21 22:59:09 -06:00
_isOosDialogVisible = true ;
2021-02-21 21:52:41 -06:00
if ( this . IsGuest )
{
2021-02-21 22:59:09 -06:00
MessageBox . Show ( Shell . LoadString ( StringId . IDS_DEVICE_OUT_OF_SPACE_TITLE ), string . Format ( Shell . LoadString ( StringId . IDS_GUEST_OUT_OF_SPACE_MESSAGE ), Name ), null , null , null , delegate
2021-02-21 21:52:41 -06:00
{
2021-02-21 22:59:09 -06:00
_isOosDialogVisible = false ;
});
2021-02-21 21:52:41 -06:00
}
else
{
2021-02-21 22:59:09 -06:00
Command okCommand = new Command ( this , Shell . LoadString ( StringId . IDS_HANDLE_DEVICE_OUT_OF_SPACE_BUTTON ), delegate
2021-02-21 21:52:41 -06:00
{
2021-02-21 22:59:09 -06:00
shell . NavigateToPage ( new DeviceOverfillLand ( this ));
_isOosDialogVisible = false ;
});
MessageBox . Show ( Shell . LoadString ( StringId . IDS_DEVICE_OUT_OF_SPACE_TITLE ), string . Format ( Shell . LoadString ( StringId . IDS_DEVICE_OUT_OF_SPACE_MESSAGE ), Name ), okCommand , null , delegate
2021-02-21 21:52:41 -06:00
{
2021-02-21 22:59:09 -06:00
_isOosDialogVisible = false ;
}, false );
2021-02-21 21:52:41 -06:00
}
2021-02-21 22:59:09 -06:00
}, null );
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
private void OnDeviceStatusChanged ( Device device , int rawHR , EEndpointStatus endpointStatus ) => Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
if ( this . IsDisposed )
return ;
2021-02-21 22:59:09 -06:00
this . HandleDeviceState ( endpointStatus , rawHR );
}, null );
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
private void OnFormatPhase1Completed ( Device device , int rawHR ) => Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
if ( this . IsDisposed )
return ;
2021-02-21 22:59:09 -06:00
HRESULT hr = rawHR ;
2021-02-21 21:52:41 -06:00
if ( hr . IsError )
this . OnFormatCompleted ( hr );
else
this . FormatSanityTimer . Start ();
2021-02-21 22:59:09 -06:00
}, null );
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
private void OnSyncBegun ( Device device ) => Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
if ( this . IsDisposed )
return ;
this . SyncProgress = new SyncNotification ( this );
this . IsSyncing = true ;
this . SyncBegun . Invoke ();
this . SyncProgressed . Invoke ();
if ( this . IsLockedAgainstSyncing )
this . EndSync ();
else
this . UserStoppedLastSync = false ;
this . LastSyncStartTimestring = this . GenerateSyncTimestring ();
this . FirePropertyChanged ( "LastSyncTime" );
2021-02-21 22:59:09 -06:00
}, null );
2021-02-21 21:52:41 -06:00
private void OnSyncProgressed (
Device device ,
uint percent ,
uint percentItem ,
uint percentTitle ,
string group ,
string title ,
ESyncEngineState engineState )
{
2021-02-21 22:59:09 -06:00
Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
if ( this . IsDisposed )
return ;
if ( this . SyncProgress != null )
this . SyncProgress . UpdateProgress (( int ) percent , ( int ) percentItem , ( int ) percentTitle , group , title , engineState );
this . SyncProgressed . Invoke ();
2021-02-21 22:59:09 -06:00
}, null );
2021-02-21 21:52:41 -06:00
}
2021-02-21 22:59:09 -06:00
private void OnSyncCompleted ( Device device , ESyncEventReason reason ) => Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
if ( this . IsDisposed )
return ;
if ( this . SyncProgress != null )
{
this . SyncProgress . Complete ( reason );
2021-02-21 22:59:09 -06:00
this . SyncProgress = null ;
2021-02-21 21:52:41 -06:00
this . LastSyncError = reason != ESyncEventReason . eSyncEventSucceeded ? HRESULT . _E_FAIL : HRESULT . _S_OK ;
}
this . IsSyncing = false ;
this . SyncProgressed . Invoke ();
this . SyncCompleted . Invoke ();
this . FirePropertyChanged ( "LastSyncTime" );
2021-02-21 22:59:09 -06:00
}, null );
2021-02-21 21:52:41 -06:00
private void FormatSanityFailed ( object sender , EventArgs e )
{
if (! this . IsFormatting )
return ;
this . OnFormatCompleted ( HRESULT . _E_FAIL );
SingletonModelItem < UIDeviceList >. Instance . HideDevice ( this );
}
2021-02-21 22:59:09 -06:00
private void OnUnassociateWlanCompleted ( Device device , int hr ) => Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
if ( this . IsDisposed )
return ;
this . UpdateWirelessSyncEnabled ();
if ( this . WiFiRemovalCompletedEvent == null )
return ;
2021-02-21 22:59:09 -06:00
this . WiFiRemovalCompletedEvent ( this , new FallibleEventArgs ( hr ));
}, null );
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
private void OnSetDeviceWlanProfilesCompleted ( Device device , int hr ) => Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
if ( this . IsDisposed )
return ;
this . UpdateWirelessSyncEnabled ();
if ( this . WiFiProfilesSentEvent == null )
return ;
2021-02-21 22:59:09 -06:00
this . WiFiProfilesSentEvent ( this , new FallibleEventArgs ( hr ));
}, null );
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
private void OnGetDeviceWlanProfilesCompleted ( Device device , int hr ) => Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
if ( this . IsDisposed || this . WiFiProfilesReceivedEvent == null )
return ;
2021-02-21 22:59:09 -06:00
this . WiFiProfilesReceivedEvent ( this , new FallibleEventArgs ( hr ));
}, null );
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
private void OnTestWlanCompleted ( Device device , WlanTestResultCode result , int hr ) => Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
this . UpdateWirelessSyncEnabled ();
if ( this . IsDisposed || this . WiFiTestCompletedEvent == null )
return ;
2021-02-21 22:59:09 -06:00
this . WiFiTestCompletedEvent ( this , new FallibleEventArgs ( hr ));
}, null );
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
private void OnAssociateWlanCompleted ( Device device , int hr ) => Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
this . UpdateWirelessSyncEnabled ();
if ( this . IsDisposed || this . WiFiAssociationCompletedEvent == null )
return ;
2021-02-21 22:59:09 -06:00
this . WiFiAssociationCompletedEvent ( this , new FallibleEventArgs ( hr ));
}, null );
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
private void OnGetWlanProfilesCompleted ( Device device , int hr ) => Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
if ( this . IsDisposed || this . ComputerWiFiProfilesLoadedEvent == null )
return ;
2021-02-21 22:59:09 -06:00
this . ComputerWiFiProfilesLoadedEvent ( this , new FallibleEventArgs ( hr ));
}, null );
2021-02-21 21:52:41 -06:00
2021-02-21 22:59:09 -06:00
private void OnGetDeviceWlanVisibleNetworksCompleted ( Device device , int hr ) => Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
if ( this . IsDisposed || this . WiFiScanCompletedEvent == null )
return ;
2021-02-21 22:59:09 -06:00
this . WiFiScanCompletedEvent ( this , new FallibleEventArgs ( hr ));
}, null );
2021-02-21 21:52:41 -06:00
private void ReleaseFirmwareObjects ()
{
2021-02-21 22:59:09 -06:00
this . UIFirmwareUpdater = null ;
this . UIFirmwareRestorer = null ;
2021-02-21 21:52:41 -06:00
}
private void MaterializeMarketplaceMedia ( IList items )
{
List < int > intList = new List < int >( items . Count );
for ( int index = 0 ; index < items . Count ; ++ index )
{
if ( items [ index ] is DataProviderObject dataProviderObject )
{
switch ( dataProviderObject )
{
case Track _ :
Track track = ( Track ) dataProviderObject ;
int dbMediaId1 = - 1 ;
2022-06-06 15:08:07 -05:00
if (! ZuneApplication . Service2 . InCompleteCollection ( track . Id , Microsoft . Zune . Service . EContentType . MusicTrack , out dbMediaId1 , out bool _ ) && ( track . IsDownloading || track . CanDownload || track . CanPurchase ))
2021-02-21 21:52:41 -06:00
dbMediaId1 = ZuneApplication . ZuneLibrary . AddTrack ( track . Id , track . AlbumId , track . TrackNumber , track . Title , track . Duration , track . AlbumTitle , track . Artist , track . PrimaryGenre . Title );
if ( dbMediaId1 >= 0 )
{
track . LibraryId = dbMediaId1 ;
continue ;
}
continue ;
case Album _ :
Album album = ( Album ) dataProviderObject ;
int num = ZuneApplication . ZuneLibrary . AddAlbum ( album . Id , album . Title , album . Artist );
if ( num >= 0 )
{
album . LibraryId = num ;
continue ;
}
continue ;
case PodcastSeries _ :
PodcastSeries podcastSeries = ( PodcastSeries ) dataProviderObject ;
string sourceUrl = podcastSeries . SourceUrl ;
if (! string . IsNullOrEmpty ( sourceUrl ))
{
SubscriptionState subscriptionState = ZuneShell . DefaultInstance . Management . GetSubscriptionState ( sourceUrl , EMediaTypes . eMediaTypePodcastSeries );
if ( subscriptionState != null && ! subscriptionState . IsSubscribed )
{
ZuneShell . DefaultInstance . Management . SubscribeToPodcastFeed ( sourceUrl , podcastSeries . Title , podcastSeries . Id , ESubscriptionSource . eSubscriptionSourceZMP );
continue ;
}
continue ;
}
continue ;
case MusicVideo _ :
MusicVideo musicVideo = ( MusicVideo ) dataProviderObject ;
int dbMediaId2 = - 1 ;
2022-06-06 15:08:07 -05:00
if (! ZuneApplication . Service2 . InCompleteCollection ( musicVideo . Id , Microsoft . Zune . Service . EContentType . Video , out dbMediaId2 , out bool _ ) && ( musicVideo . IsDownloading || musicVideo . CanPurchase ))
2021-02-21 21:52:41 -06:00
dbMediaId2 = ZuneApplication . ZuneLibrary . AddVideo ( musicVideo . Id , musicVideo . Title , musicVideo . Duration );
if ( dbMediaId2 >= 0 )
{
musicVideo . LibraryId = dbMediaId2 ;
continue ;
}
continue ;
default :
continue ;
}
}
}
}
private void HandleDeviceState ( EEndpointStatus state , HRESULT hr )
{
bool isValid = this . IsValid ;
bool isConnectedToPc = this . IsConnectedToPC ;
bool connectedToClient = this . IsConnectedToClient ;
bool connectedToSideloader = this . IsConnectedToSideloader ;
bool isReadyForSync = this . IsReadyForSync ;
this . _lastDeviceState = state ;
if ( isValid != this . IsValid )
{
this . ReverseSyncPicsFromPhone = true ;
this . FirePropertyChanged ( "IsValid" );
}
if ( isConnectedToPc != this . IsConnectedToPC )
{
this . FirePropertyChanged ( "IsConnectedToPC" );
if (! FeatureEnablement . IsFeatureEnabled ( Features . eDevice ))
{
ClientConfiguration . FeaturesOverride . Device = 1 ;
FeatureEnablement . ForceFeatureOn ( Features . eDevice );
}
2021-02-21 22:59:09 -06:00
Application . DeferredInvoke ( delegate
2021-02-21 21:52:41 -06:00
{
2021-02-21 22:59:09 -06:00
Shell . MainFrame . Device . UpdateShowDevice ();
Shell . SettingsFrame . Settings . ShowDevice ( true );
}, null );
2021-02-21 21:52:41 -06:00
}
if ( connectedToClient != this . IsConnectedToClient )
{
if ( this . IsConnectedToClient )
{
this . ReloadIconSet ();
if ( this . IsFormatting )
this . OnFormatCompleted ( HRESULT . _S_OK );
}
if (! this . ShouldSuppressConnectionNotifications ())
{
this . OnConnectivityChanged ();
this . FirePropertyChanged ( "IsConnectedToClient" );
this . FirePropertyChanged ( "IsConnectedToClientWirelessly" );
this . FirePropertyChanged ( "IsConnectedToClientPhysically" );
if ( isReadyForSync != this . IsReadyForSync )
this . FirePropertyChanged ( "IsReadyForSync" );
}
}
if ( connectedToSideloader != this . IsConnectedToSideloader )
{
this . FirePropertyChanged ( "IsConnectedToSideloader" );
this . FirePropertyChanged ( "OwnerApplicationName" );
}
if (! this . IsConnectedToPC )
this . IsReadyForSync = false ;
else if ( state >= EEndpointStatus . eEndpointStatusReadyForSync )
this . IsReadyForSync = true ;
switch ( state - 6 )
{
case EEndpointStatus . eEndpointStatusUndefined :
this . HidePinUnlockDialog ( false );
2021-02-21 22:59:09 -06:00
MessageBox . Show ( Shell . LoadString ( StringId . IDS_PHONE_TLS_ERROR_TITLE ), Shell . LoadString ( StringId . IDS_PHONE_TLS_ERROR_TEXT ), null );
2021-02-21 21:52:41 -06:00
break ;
case EEndpointStatus . eEndpointStatusNotPresent :
this . ShowPinUnlockDialog ();
break ;
case EEndpointStatus . eEndpointStatusHidden :
this . HidePinUnlockDialog ( true );
break ;
case EEndpointStatus . eEndpointStatusAuthenticationRequired :
if (! hr . IsSuccess )
{
2021-02-21 22:59:09 -06:00
MessageBox . Show ( Shell . LoadString ( StringId . IDS_DEVICE_ENUMERATION_FAILED_TITLE ), Shell . LoadString ( StringId . IDS_DEVICE_ENUMERATION_FAILED_BODY ), null );
2021-02-21 21:52:41 -06:00
SingletonModelItem < UIDeviceList >. Instance . HideDevice ( this );
}
if ( this . EnumeratedEvent == null )
break ;
2021-02-21 22:59:09 -06:00
this . EnumeratedEvent ( this , new FallibleEventArgs ( hr ));
2021-02-21 21:52:41 -06:00
break ;
case EEndpointStatus . eEndpointStatusAuthenticationCompleted :
if ( this . IsFormatting )
{
this . OnFormatCompleted ( HRESULT . _S_OK );
break ;
}
this . BeginSync ();
if (! this . SupportsPaidApplications )
break ;
this . ForceAppUpdate ();
break ;
case EEndpointStatus . eEndpointStatusDetectingProxy :
2021-02-21 22:59:09 -06:00
MessageBox . Show ( Shell . LoadString ( StringId . IDS_PHONE_NO_IP_TITLE ), Shell . LoadString ( StringId . IDS_PHONE_NO_IP_TEXT ), null );
2021-02-21 21:52:41 -06:00
break ;
}
}
private void OnConnectivityChanged ()
{
if ( this . IsConnectedToClient )
{
HRESULT hresult = HRESULT . _S_OK ;
if ( this . UserGuid != Guid . Empty )
{
int hrLogin = 0 ;
if ((( HRESULT ) this . _device . GetAndResetLastLoginError ( ref hrLogin )). IsSuccess )
2021-02-21 22:59:09 -06:00
hresult = hrLogin ;
2021-02-21 21:52:41 -06:00
}
this . LastFailedLoginError = hresult ;
}
else
{
if ( this . SyncProgress != null )
{
this . SyncProgress . SyncCanceled = true ;
this . SyncProgress . Complete ( ESyncEventReason . eSyncEventSucceeded );
2021-02-21 22:59:09 -06:00
this . SyncProgress = null ;
2021-02-21 21:52:41 -06:00
}
this . ReleaseFirmwareObjects ();
}
if ( this . ActualGasGauge != null )
this . ActualGasGauge . Dispose ();
if ( this . PredictedGasGauge != null )
this . PredictedGasGauge . Dispose ();
2021-02-21 22:59:09 -06:00
this . ActualGasGauge = new UIGasGauge ( this , this . _device . ActualGasGauge );
this . PredictedGasGauge = new UIGasGauge ( this , this . _device . PredictedGasGauge );
2021-02-21 21:52:41 -06:00
if ( this . _device . PredictedGasGauge != null )
{
this . _device . PredictedGasGauge . DeviceOverflowEvent -= new DeviceOverflowHandler ( this . OnDeviceOverfill );
this . _device . PredictedGasGauge . DeviceOverflowEvent += new DeviceOverflowHandler ( this . OnDeviceOverfill );
}
this . UpdateWirelessSyncEnabled ();
this . FirePropertyChanged ( "CanonicalName" );
this . FirePropertyChanged ( "ZuneTag" );
this . FirePropertyChanged ( "RequiresClientUpdate" );
this . FirePropertyChanged ( "RequiresFirmwareUpdate" );
this . FirePropertyChanged ( "FirmwareVersion" );
this . UserStoppedLastSync = false ;
this . LastConnectTimestring = this . GenerateSyncTimestring ();
}
private void OnFormatCompleted ( HRESULT hr )
{
this . FormatSanityTimer . Stop ();
this . IsFormatting = false ;
if ( this . FormatCompletedEvent == null )
return ;
2021-02-21 22:59:09 -06:00
this . FormatCompletedEvent ( this , new FallibleEventArgs ( hr ));
2021-02-21 21:52:41 -06:00
}
private bool ShouldSuppressConnectionNotifications ()
{
if ( this . IsFormatting || this . UIFirmwareUpdater != null && this . UIFirmwareUpdater . UpdateInProgress )
return true ;
return this . UIFirmwareRestorer != null && this . UIFirmwareRestorer . RestoreInProgress ;
}
private void UpdateWirelessSyncEnabled ()
{
bool flag = false ;
if ( this . IsConnectedToClient )
{
2021-02-21 22:59:09 -06:00
string mediaSyncSSID = null ;
2021-02-21 21:52:41 -06:00
bool disabled = false ;
HRESULT hresult = this . IsWlanDeviceDisabled ( ref disabled );
if ( hresult . IsSuccess )
hresult = this . GetWifiMediaSyncSSID ( ref mediaSyncSSID );
if ( hresult . IsSuccess )
flag = ! disabled && ! string . IsNullOrEmpty ( mediaSyncSSID );
}
this . IsWirelessSyncEnabled = flag ;
}
private void ShowPinUnlockDialog ()
{
if ( this . _pinUnlockMessageBox == null )
{
2021-02-21 22:59:09 -06:00
this . _pinUnlockMessageBox = MessageBox . Show ( Shell . LoadString ( StringId . IDS_PHONE_PIN_UNLOCK_TITLE ), Shell . LoadString ( StringId . IDS_PHONE_PIN_UNLOCK_TEXT ), null , Shell . LoadString ( StringId . IDS_CANCEL_BUTTON ), new EventHandler ( this . PinUnlockCancelled ), false );
2021-02-21 21:52:41 -06:00
}
else
{
if ( Application . RenderingType == RenderingType . GDI && SingletonModelItem < TransportControls >. Instance . PlayingVideo )
SingletonModelItem < TransportControls >. Instance . Stop . Invoke ();
this . _pinUnlockMessageBox . Show ();
}
}
private void HidePinUnlockDialog ( bool unlockSucceeded )
{
if ( this . _pinUnlockMessageBox == null )
return ;
if ( unlockSucceeded )
this . _pinUnlockMessageBox . Hide ();
else
this . _pinUnlockMessageBox . Cancel . Invoke ();
2021-02-21 22:59:09 -06:00
this . _pinUnlockMessageBox = null ;
2021-02-21 21:52:41 -06:00
}
private void PinUnlockCancelled ( object sender , EventArgs args ) => SingletonModelItem < UIDeviceList >. Instance . HideDevice ( this );
2021-02-21 22:59:09 -06:00
private string GenerateSyncTimestring () => DateTime . UtcNow . ToString ( "yyyy-MM-dd HH\\:mm\\:ss.fff" , CultureInfo . CreateSpecificCulture ( "en-US" ));
2021-02-21 21:52:41 -06:00
private bool SupportsSyncCategory ( SyncCategory category )
{
bool flag ;
switch ( category )
{
case SyncCategory . Friend :
flag = this . SupportsUserCards ;
break ;
case SyncCategory . Channel :
flag = this . SupportsChannels ;
break ;
case SyncCategory . Application :
flag = this . SupportsSyncApplications ;
break ;
default :
flag = true ;
break ;
}
return flag ;
}
private MediaIdAndType [] GenerateThreadSafeDatabaseItems ( IList source )
{
MediaIdAndType [] mediaIdAndTypeArray = new MediaIdAndType [ source . Count ];
for ( int index = 0 ; index < source . Count ; ++ index )
{
if ( source [ index ] is IDatabaseMedia databaseMedia )
{
int mediaId ;
EMediaTypes mediaType ;
databaseMedia . GetMediaIdAndType ( out mediaId , out mediaType );
mediaIdAndTypeArray [ index ] = new MediaIdAndType ( mediaId , mediaType );
}
}
return mediaIdAndTypeArray ;
}
public static void WarnUserAboutFriendSyncSize ()
{
if (! ClientConfiguration . MediaStore . AlertSyncAllFriendsBehavior )
return ;
2021-02-21 22:59:09 -06:00
BooleanChoice neverAlertSyncAllFriendsBehavior = new BooleanChoice ( ZuneShell . DefaultInstance , Shell . LoadString ( StringId . IDS_DONT_SHOW_THIS_MESSAGE_AGAIN ));
2021-02-21 21:52:41 -06:00
neverAlertSyncAllFriendsBehavior . Value = false ;
2021-02-21 22:59:09 -06:00
neverAlertSyncAllFriendsBehavior . ChosenChanged += delegate
2021-02-21 21:52:41 -06:00
{
ClientConfiguration . MediaStore . AlertSyncAllFriendsBehavior = ! neverAlertSyncAllFriendsBehavior . Value ;
};
2021-02-21 22:59:09 -06:00
MessageBox . Show ( Shell . LoadString ( StringId . IDS_SYNC_FRIENDS_NOTICE_TITLE ), Shell . LoadString ( StringId . IDS_SYNC_FRIENDS_NOTICE ), null , neverAlertSyncAllFriendsBehavior );
2021-02-21 21:52:41 -06:00
}
public static string FormatSyncStatus ( object title , IList metadata )
{
2021-02-21 22:59:09 -06:00
string str1 = ( title ?? string . Empty ). ToString ();
2021-02-21 21:52:41 -06:00
bool flag = false ;
2021-02-21 22:59:09 -06:00
foreach ( object obj in metadata )
2021-02-21 21:52:41 -06:00
{
2021-02-21 22:59:09 -06:00
string str2 = ( obj ?? string . Empty ). ToString ();
2021-02-21 21:52:41 -06:00
if (! string . IsNullOrEmpty ( str2 ))
{
if ( flag )
{
2021-02-21 22:59:09 -06:00
str1 += _syncStatusDatumDivider ;
2021-02-21 21:52:41 -06:00
}
else
{
2021-02-21 22:59:09 -06:00
str1 += _syncStatusTitleDivider ;
2021-02-21 21:52:41 -06:00
flag = true ;
}
str1 += str2 ;
}
}
return str1 ;
}
public static string FormatDeviceClass ( DeviceClass deviceClass )
{
if ( deviceClass == DeviceClass . ZuneHD )
2021-02-21 22:59:09 -06:00
return Shell . LoadString ( StringId . IDS_AppsZuneHDDeviceName );
return deviceClass == DeviceClass . WindowsPhone ? Shell . LoadString ( StringId . IDS_AppsWindowsPhoneDeviceName ) : Shell . LoadString ( StringId . IDS_GENERIC_ERROR );
2021-02-21 21:52:41 -06:00
}
public static DeviceClass ToDeviceClass ( int deviceClass ) => ( DeviceClass ) deviceClass ;
public static DeviceClass ToDeviceClass ( object deviceClass )
{
DeviceClass ? nullable = ( DeviceClass ?) deviceClass ;
return ! nullable . HasValue ? DeviceClass . Invalid : nullable . Value ;
}
public static int ToInt32 ( DeviceClass deviceClass ) => ( int ) deviceClass ;
protected interface INewRuleMessageType
{
MediaType Type { get ; }
string SingularMessage { get ; }
string PluralMessage { get ; }
string GetMessageForCount ( int count );
}
2021-02-21 22:59:09 -06:00
protected class NewRuleMessageType : INewRuleMessageType
2021-02-21 21:52:41 -06:00
{
private MediaType _type ;
private string _singular ;
private string _plural ;
public NewRuleMessageType ( MediaType type , StringId singular , StringId plural )
{
this . _type = type ;
2021-02-21 22:59:09 -06:00
this . _singular = Shell . LoadString ( singular );
this . _plural = Shell . LoadString ( plural );
2021-02-21 21:52:41 -06:00
}
public MediaType Type => this . _type ;
public string SingularMessage => this . _singular ;
public string PluralMessage => this . _plural ;
2021-02-21 22:59:09 -06:00
public string GetMessageForCount ( int count ) => count == 1 ? this . SingularMessage : string . Format ( this . PluralMessage , count );
2021-02-21 21:52:41 -06:00
}
}
}