📄 tarheader.cs
字号:
throw new ArgumentOutOfRangeException();
}
modTime = new DateTime(value.Year, value.Month, value.Day, value.Hour, value.Minute, value.Second);
}
}
int checksum;
/// <summary>
/// Get the entry's checksum. This is only valid/updated after writing or reading an entry.
/// </summary>
public int Checksum
{
get { return checksum; }
}
bool isChecksumValid;
/// <summary>
/// Get value of true if the header checksum is valid, false otherwise.
/// </summary>
public bool IsChecksumValid
{
get { return isChecksumValid; }
}
byte typeFlag;
/// <summary>
/// Get/set the entry's type flag.
/// </summary>
public byte TypeFlag
{
get { return typeFlag; }
set { typeFlag = value; }
}
string linkName;
/// <summary>
/// The entry's link name.
/// </summary>
/// <exception cref="ArgumentNullException">Thrown when attempting to set LinkName to null.</exception>
public string LinkName
{
get { return linkName; }
set {
if ( value == null ) {
throw new ArgumentNullException();
}
linkName = value;
}
}
string magic;
/// <summary>
/// Get/set the entry's magic tag.
/// </summary>
/// <exception cref="ArgumentNullException">Thrown when attempting to set Magic to null.</exception>
public string Magic
{
get { return magic; }
set {
if ( value == null ) {
throw new ArgumentNullException();
}
magic = value;
}
}
string version;
/// <summary>
/// The entry's version.
/// </summary>
/// <exception cref="ArgumentNullException">Thrown when attempting to set Version to null.</exception>
public string Version
{
get { return version; }
set {
if ( value == null ) {
throw new ArgumentNullException();
}
version = value;
}
}
string userName;
/// <summary>
/// The entry's user name.
/// </summary>
/// <remarks>
/// See <see cref="ResetValueDefaults">ResetValueDefaults</see>
/// for detail on how this value is derived.
/// </remarks>
public string UserName
{
get { return userName; }
set {
if (value != null) {
userName = value.Substring(0, Math.Min(UNAMELEN, value.Length));
}
else {
#if COMPACT_FRAMEWORK
string currentUser = "PocketPC";
#else
string currentUser = Environment.UserName;
#endif
if (currentUser.Length > UNAMELEN) {
currentUser = currentUser.Substring(0, UNAMELEN);
}
userName = currentUser;
}
}
}
string groupName;
/// <summary>
/// Get/set the entry's group name.
/// </summary>
/// <remarks>
/// This is only directly relevant to unix systems.
/// </remarks>
public string GroupName
{
get { return groupName; }
set {
if ( value == null ) {
groupName = "None";
}
else {
groupName = value;
}
}
}
int devMajor;
/// <summary>
/// Get/set the entry's major device number.
/// </summary>
public int DevMajor
{
get { return devMajor; }
set { devMajor = value; }
}
int devMinor;
/// <summary>
/// Get/set the entry's minor device number.
/// </summary>
public int DevMinor
{
get { return devMinor; }
set { devMinor = value; }
}
/// <summary>
/// Initialise a default TarHeader instance
/// </summary>
public TarHeader()
{
this.Magic = TarHeader.TMAGIC;
this.Version = " ";
this.Name = "";
this.LinkName = "";
this.UserId = defaultUserId;
this.GroupId = defaultGroupId;
this.UserName = defaultUser;
this.GroupName = defaultGroupName;
this.Size = 0;
}
// Values used during recursive operations.
static internal int userIdAsSet = 0;
static internal int groupIdAsSet = 0;
static internal string userNameAsSet = null;
static internal string groupNameAsSet = "None";
static internal int defaultUserId = 0;
static internal int defaultGroupId = 0;
static internal string defaultGroupName = "None";
static internal string defaultUser = null;
static internal void RestoreSetValues()
{
defaultUserId = userIdAsSet;
defaultUser = userNameAsSet;
defaultGroupId = groupIdAsSet;
defaultGroupName = groupNameAsSet;
}
/// <summary>
/// Set defaults for values used when constructing a TarHeader instance.
/// </summary>
/// <param name="userId">Value to apply as a default for userId.</param>
/// <param name="userName">Value to apply as a default for userName.</param>
/// <param name="groupId">Value to apply as a default for groupId.</param>
/// <param name="groupName">Value to apply as a default for groupName.</param>
static public void SetValueDefaults(int userId, string userName, int groupId, string groupName)
{
defaultUserId = userIdAsSet = userId;
defaultUser = userNameAsSet = userName;
defaultGroupId = groupIdAsSet = groupId;
defaultGroupName = groupNameAsSet = groupName;
}
static internal void SetActiveDefaults(int userId, string userName, int groupId, string groupName)
{
defaultUserId = userId;
defaultUser = userName;
defaultGroupId = groupId;
defaultGroupName = groupName;
}
/// <summary>
/// Reset value defaults to initial values.
/// </summary>
/// <remarks>
/// The default values are user id=0, group id=0, groupname="None", user name=null.
/// When the default user name is null the value from Environment.UserName is used. Or "PocketPC" for the Compact framework.
/// When the default group name is null the value "None" is used.
/// </remarks>
static public void ResetValueDefaults()
{
defaultUserId = 0;
defaultGroupId = 0;
defaultGroupName = "None";
defaultUser = null;
}
/// <summary>
/// Clone a TAR header.
/// </summary>
public object Clone()
{
TarHeader hdr = new TarHeader();
hdr.Name = Name;
hdr.Mode = this.Mode;
hdr.UserId = this.UserId;
hdr.GroupId = this.GroupId;
hdr.Size = this.Size;
hdr.ModTime = this.ModTime;
hdr.TypeFlag = this.TypeFlag;
hdr.LinkName = this.LinkName;
hdr.Magic = this.Magic;
hdr.Version = this.Version;
hdr.UserName = this.UserName;
hdr.GroupName = this.GroupName;
hdr.DevMajor = this.DevMajor;
hdr.DevMinor = this.DevMinor;
return hdr;
}
/// <summary>
/// Get a hash code for the current object.
/// </summary>
/// <returns>A hash code for the current object.</returns>
public override int GetHashCode()
{
return Name.GetHashCode();
}
/// <summary>
/// Determines if this instance is equal to the specified object.
/// </summary>
/// <param name="obj">The object to compare with.</param>
/// <returns>true if the objects are equal, false otherwise.</returns>
public override bool Equals(object obj)
{
if ( obj is TarHeader ) {
TarHeader th = obj as TarHeader;
return name == th.name
&& mode == th.mode
&& UserId == th.UserId
&& GroupId == th.GroupId
&& Size == th.Size
&& ModTime == th.ModTime
&& Checksum == th.Checksum
&& TypeFlag == th.TypeFlag
&& LinkName == th.LinkName
&& Magic == th.Magic
&& Version == th.Version
&& UserName == th.UserName
&& GroupName == th.GroupName
&& DevMajor == th.DevMajor
&& DevMinor == th.DevMinor;
}
else {
return false;
}
}
/// <summary>
/// Get the name of this entry.
/// </summary>
/// <returns>The entry's name.</returns>
/// <remarks>
/// This is obsolete use the Name property instead.
/// </remarks>
[Obsolete]
public string GetName()
{
return this.name.ToString();
}
/// <summary>
/// Parse an octal string from a header buffer.
/// </summary>
/// <param name = "header">The header buffer from which to parse.</param>
/// <param name = "offset">The offset into the buffer from which to parse.</param>
/// <param name = "length">The number of header bytes to parse.</param>
/// <returns>The long equivalent of the octal string.</returns>
public static long ParseOctal(byte[] header, int offset, int length)
{
long result = 0;
bool stillPadding = true;
int end = offset + length;
for (int i = offset; i < end ; ++i) {
if (header[i] == 0) {
break;
}
if (header[i] == (byte)' ' || header[i] == '0') {
if (stillPadding) {
continue;
}
if (header[i] == (byte)' ') {
break;
}
}
stillPadding = false;
result = (result << 3) + (header[i] - '0');
}
return result;
}
/// <summary>
/// Parse a name from a header buffer.
/// </summary>
/// <param name="header">
/// The header buffer from which to parse.
/// </param>
/// <param name="offset">
/// The offset into the buffer from which to parse.
/// </param>
/// <param name="length">
/// The number of header bytes to parse.
/// </param>
/// <returns>
/// The name parsed.
/// </returns>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -