@@ -438,7 +438,7 @@ public static string MakePath(params string[] directories)
438438 return Path . Combine ( directories ) ;
439439 }
440440
441-
441+
442442 public static string PrintByteLength ( long bytes )
443443 {
444444 if ( bytes < 1024 ) return bytes . ToString ( ) ;
@@ -517,7 +517,7 @@ public static U Get<T, U>(this IDictionary<T, U> dict, T key)
517517 return val ;
518518 }
519519
520-
520+
521521 public static List < T > Shuffle < T > ( this IEnumerable < T > source )
522522 {
523523 var list = source . ToList ( ) ;
@@ -576,7 +576,7 @@ public static void StartAsync(Action action)
576576 } ) ;
577577 }
578578
579-
579+
580580
581581 public static byte [ ] ToBytes ( this Image image , int size )
582582 {
@@ -595,7 +595,7 @@ public static byte[] ToBytes(this Image image, int size)
595595 return stream . ToArray ( ) ;
596596 }
597597
598-
598+
599599
600600 /// <summary>
601601 /// Hash password with default hash used by remote server
@@ -628,7 +628,7 @@ public static void SafeDelete(string path)
628628 }
629629 catch { }
630630 }
631-
631+
632632
633633 public static string ToHex ( this byte [ ] array )
634634 {
@@ -700,22 +700,26 @@ public static async Task<FileResponse<byte[]>> DownloadFileAsync(string url, Dat
700700 var ms = new MemoryStream ( ) ;
701701 var wc = ( HttpWebRequest ) HttpWebRequest . Create ( new Uri ( url ) ) ;
702702 var ret = new FileResponse < byte [ ] > ( ) ;
703-
703+
704704 if ( ifModifiedSince != null ) wc . IfModifiedSince = ifModifiedSince . Value ;
705705
706- try {
707- using ( var response = ( HttpWebResponse ) await wc . GetResponseAsync ( ) . ConfigureAwait ( false ) ) {
706+ try
707+ {
708+ using ( var response = ( HttpWebResponse ) await wc . GetResponseAsync ( ) . ConfigureAwait ( false ) )
709+ {
708710 ret . WasModified = true ;
709711 ret . DateModified = response . LastModified ;
710712
711- using ( var stream = response . GetResponseStream ( ) ) {
713+ using ( var stream = response . GetResponseStream ( ) )
714+ {
712715 await stream . CopyToAsync ( ms ) . ConfigureAwait ( false ) ;
713716 ret . Content = ms . ToArray ( ) ;
714717 return ret ;
715718 }
716719 }
717720 }
718- catch ( WebException e ) {
721+ catch ( WebException e )
722+ {
719723 if ( e . Response != null && ( ( HttpWebResponse ) e . Response ) . StatusCode == HttpStatusCode . NotModified ) return ret ;
720724 throw ;
721725 }
@@ -724,7 +728,8 @@ public static async Task<FileResponse<byte[]>> DownloadFileAsync(string url, Dat
724728 public static async Task < FileResponse < string > > DownloadStringAsync ( string url , DateTime ? ifModifiedSince = null )
725729 {
726730 var file = await DownloadFileAsync ( url , ifModifiedSince ) . ConfigureAwait ( false ) ;
727- return new FileResponse < string > ( ) {
731+ return new FileResponse < string > ( )
732+ {
728733 WasModified = file . WasModified ,
729734 DateModified = file . DateModified ,
730735 Content = file . Content != null ? Encoding . UTF8 . GetString ( file . Content ) : null
@@ -754,10 +759,10 @@ public static IEnumerable<Type> GetLoadableTypes(this Assembly assembly)
754759 public static IEnumerable < Type > GetAllTypesWithAttribute < T > ( )
755760 {
756761 return from a in AppDomain . CurrentDomain . GetAssemblies ( ) . AsParallel ( )
757- from t in a . GetLoadableTypes ( )
758- let attributes = t . GetCustomAttributes ( typeof ( T ) , true )
759- where attributes != null && attributes . Length > 0
760- select t ;
762+ from t in a . GetLoadableTypes ( )
763+ let attributes = t . GetCustomAttributes ( typeof ( T ) , true )
764+ where attributes != null && attributes . Length > 0
765+ select t ;
761766 }
762767
763768 /// <summary>
@@ -821,7 +826,8 @@ public static string Truncate(this string input, int length)
821826 return input . Substring ( 0 , length ) ;
822827 }
823828
824- public static bool ValidLobbyNameCharacter ( char c ) {
829+ public static bool ValidLobbyNameCharacter ( char c )
830+ {
825831 if ( c >= 'a' && c <= 'z' ) return true ;
826832 if ( c >= 'A' && c <= 'Z' ) return true ;
827833 if ( c >= '0' && c <= '9' ) return true ;
@@ -830,13 +836,26 @@ public static bool ValidLobbyNameCharacter(char c) {
830836 return false ;
831837 }
832838
833- public static string StripInvalidLobbyNameChars ( string name ) {
839+ public static string StripInvalidLobbyNameChars ( string name )
840+ {
834841 if ( String . IsNullOrEmpty ( name ) ) return name ;
835842 var sb = new StringBuilder ( ) ;
836843 foreach ( var c in name . Where ( Utils . ValidLobbyNameCharacter ) ) sb . Append ( c ) ;
837844 return sb . ToString ( ) ;
838845 }
839846
847+ public static string GetMyInstallID ( )
848+ {
849+
850+ var path = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . CommonApplicationData ) , "chobbyla" , "id.txt" ) ;
851+ if ( ! File . Exists ( path ) )
852+ {
853+ string guid = Guid . NewGuid ( ) . ToString ( ) ;
854+ File . WriteAllText ( path , guid ) ;
855+ }
856+ return File . ReadAllText ( path ) ;
857+ }
858+
840859 public static long GetMyUserID ( )
841860 {
842861 try
@@ -854,7 +873,7 @@ public static long GetMyUserID()
854873 }
855874 catch ( Exception ex )
856875 {
857- Trace . TraceWarning ( "Failed to get the userID: {0}" , ex ) ;
876+ Trace . TraceWarning ( "Failed to get the userID: {0}" , ex ) ;
858877 }
859878 return 0 ;
860879 }
@@ -899,7 +918,7 @@ public static T ReadStruct<T>(this BinaryReader reader)
899918 return reader . ReadBytes ( Marshal . SizeOf ( typeof ( T ) ) ) . ToStruct < T > ( ) ;
900919 }
901920
902- public static DateTime UnixToDateTime ( this UInt64 secondsFrom1970 )
921+ public static DateTime UnixToDateTime ( this UInt64 secondsFrom1970 )
903922 {
904923 var dtDateTime = new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , 0 , DateTimeKind . Utc ) ;
905924 dtDateTime = dtDateTime . AddSeconds ( secondsFrom1970 ) . ToLocalTime ( ) ;
0 commit comments