The Labs \ Source Viewer \ SSCLI \ Microsoft.JScript.Vsa \ ResInfo

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. namespace Microsoft.JScript.Vsa
  16. {
  17.    
  18.     using System;
  19.     using System.Globalization;
  20.     using System.IO;
  21.    
  22.     // ResInfo is the argument supplied to the /resource or /linkresource switches
  23.     // on the command line. The argument is required to be in the following format:
  24.     // <filename>[,<name>[,public|private]]
  25.     // Since <filename> can legally contain commas, we require that <name> does not
  26.     // contain commas (should be a valid identifier), and <name> cannot be "public"
  27.     // or "private". That way, we can use commas as delimiters, check the optional
  28.     // parts first, and use the remainder as the filename.
  29.     [Obsolete(VsaObsolete.Description)]
  30.     public class ResInfo
  31.     {
  32.         public string filename;
  33.         public string fullpath;
  34.         public string name;
  35.         public bool isPublic;
  36.         public bool isLinked;
  37.        
  38.         public ResInfo(string filename, string name, bool isPublic, bool isLinked)
  39.         {
  40.             this.filename = filename;
  41.             this.fullpath = Path.GetFullPath(filename);
  42.             this.name = name;
  43.             this.isPublic = isPublic;
  44.             this.isLinked = isLinked;
  45.         }
  46.        
  47.         public ResInfo(string resinfo, bool isLinked)
  48.         {
  49.             // resinfo: <filename>[,<name>[,public|private]]
  50.             string[] info = resinfo.Split(new char[] {','});
  51.             int numParts = info.Length;
  52.            
  53.             // set the defaults
  54.             this.filename = info[0];
  55.             this.name = Path.GetFileName(this.filename);
  56.             this.isPublic = true;
  57.             this.isLinked = isLinked;
  58.            
  59.             if (numParts == 2) {
  60.                 this.name = info[1];
  61.             }
  62.             else if (numParts > 2) {
  63.                 // check the last part for "public" or "private", then the next part is the name, and
  64.                 // the rest should be rejoined as the filename (commas are valid filename characters)
  65.                 bool flagPresent = false;
  66.                 if (String.Compare(info[numParts - 1], "public", StringComparison.OrdinalIgnoreCase) == 0) {
  67.                     flagPresent = true;
  68.                 }
  69.                 else if (String.Compare(info[numParts - 1], "private", StringComparison.OrdinalIgnoreCase) == 0) {
  70.                     this.isPublic = false;
  71.                     flagPresent = true;
  72.                 }
  73.                 this.name = info[numParts - (flagPresent ? 2 : 1)];
  74.                 // this.filename is made up of the rest...
  75.                 this.filename = String.Join(",", info, 0, numParts - (flagPresent ? 2 : 1));
  76.             }
  77.             this.fullpath = Path.GetFullPath(this.filename);
  78.         }
  79.     }
  80. }

Developer Fusion