📄 processupload.cs
字号:
this._data = new byte[0];
}
this._read = this._data.Length;
this._PreloadWasRead = true;
}
else
{
if (this._data.Length != this._chunksize)
{
this._data = new byte[this._chunksize];
}
if ((this._counter + this._chunksize) > this._ContentLength)
{
this._chunksize = (int) (this._ContentLength - this._counter);
}
if (this._chunksize == 0)
{
return false;
}
if (this.IsSimulateRequest)
{
Array.Copy(this.SimulateRequestArray, this._counter, this._data, (long) 0, (long) this._chunksize);
this._read = this._chunksize;
}
else
{
this._read = this._UploadProgress._WorkerRequest.ReadEntityBody(this._data, this._chunksize);
}
if (this._read == 0)
{
this._UploadProgress._Status = UploadState.Cancelled;
UploadModule.AddDebugInfo("End reading EntityBody from request stream", this._id);
return false;
}
if (this._UploadProgress._bwc.IsLimit)
{
this._UploadProgress._bwc.Limit(this._read);
}
}
this._counter += this._read;
this._ReadSinseLastTime += this._read;
this.SetProgressState(this._counter);
return true;
}
private Encoding GetEncoding(HttpRequest request)
{
string name = "";
string str2 = request.ServerVariables["HTTP_Content_Type"];
if ((str2 == null) || (str2.Length == 0))
{
str2 = request.ServerVariables["CONTENT_TYPE"];
}
if ((str2 != null) && (str2.Length != 0))
{
int index = str2.ToLower().IndexOf("charset=");
if (index == -1)
{
return Encoding.UTF8;
}
name = str2.Substring(index + 8, str2.Length - (index + 8));
index = name.IndexOf(";");
if (index > 0)
{
name = name.Substring(0, index - 1);
}
name = name.Trim().Replace("\"", "");
if (name != "")
{
try
{
return Encoding.GetEncoding(name);
}
catch
{
}
}
}
return Encoding.UTF8;
}
private long GetNextLine(byte[] head, long startpos, long endpos)
{
while (startpos < (endpos - 1))
{
if ((head[(int) ((IntPtr) startpos)] == 13) && (head[(int) ((IntPtr) (startpos + 1))] == 10))
{
return startpos;
}
startpos++;
}
return (long) (-1);
}
private PartHeader GetPartHeader(byte[] head, long startpos, long endpos)
{
PartHeader header = new PartHeader();
header._partName = null;
header._partFilename = null;
header._partContentType = null;
int startIndex = -1;
for (long i = this.GetNextLine(head, startpos, endpos); i != -1; i = this.GetNextLine(head, startpos, endpos))
{
if ((i - startpos) > 0)
{
string headcontent = this._encoding.GetString(head, (int) startpos, (int) (i - startpos));
if (header._partName == null)
{
header._partName = this.ExractValueFromHeader(headcontent, "name");
}
if (header._partFilename == null)
{
header._partFilename = this.ExractValueFromHeader(headcontent, "filename");
}
if ((header._partContentType == null) && ((startIndex = headcontent.ToUpper().IndexOf("CONTENT-TYPE")) != -1))
{
startIndex = headcontent.IndexOf(":", startIndex);
if ((startIndex != -1) && ((startIndex + 1) < headcontent.Length))
{
header._partContentType = headcontent.Substring(startIndex + 1).Trim();
}
}
}
startpos = i + 2;
}
return header;
}
private void InitBoundaries()
{
string boundary;
if (!this.IsSimulateRequest)
{
boundary = this.GetBoundary(this._app.Context.Request);
}
else
{
boundary = this.SimulateBoundary;
}
this._FirstBoundary = this.StrToByteArray("--" + boundary);
this._Boundary = this.StrToByteArray("\r\n--" + boundary);
this._CloseBoundary = this.StrToByteArray("\r\n--" + boundary + "--\r\n");
byte[] buffer = this.StrToByteArray("-");
if (buffer.Length == 1)
{
this._Defis = buffer[0];
this._DeficesInBoundary = this.CountDefisesinBoundary(this.StrToByteArray("--" + boundary));
if (this._DeficesInBoundary >= 4)
{
this._OptimizeBoundarySeach = true;
}
}
}
private void InitConfigVars()
{
this._TempFolderPath = (string) Settings.GetValue(this._id, "tempPath");
try
{
string environmentVariable = Environment.GetEnvironmentVariable(this._TempFolderPath);
if (environmentVariable != null)
{
this._TempFolderPath = environmentVariable;
}
}
catch
{
}
if ((this._TempFolderPath != null) && !this._TempFolderPath.EndsWith(@"\"))
{
this._TempFolderPath = this._TempFolderPath + @"\";
}
if (!Directory.Exists(this._TempFolderPath))
{
try
{
Directory.CreateDirectory(this._TempFolderPath);
}
catch
{
UploadModule.AddDebugInfo("ProcessUpload.InitConfigVars(): Folder " + this._TempFolderPath + " not found and can't be created", this._id);
throw new DirectoryNotFoundException(string.Format("The folder {0} does not exist and cannot be created!", this._TempFolderPath));
}
}
this._chunksize = (int) Settings.GetValue(this._id, "bufferSize");
UploadModule.AddDebugInfo(string.Concat(new object[] { "ProcessUpload.InitConfigVars(): Temp folder ", this._TempFolderPath, ", chunkSize=", this._chunksize }), this._id);
}
private void InitProgressState()
{
this._UploadProgress._UploadedBytes = 0;
this._UploadProgress._ReadSinseLastTime = 0;
this._UploadProgress._StartTime = DateTime.Now;
this._UploadProgress._LastTime = DateTime.Now;
this._UploadProgress._CurrentFileName = "";
this._UploadProgress._Status = UploadState.Uploading;
this._UploadProgress._TimeSinseLastTime = this._UploadProgress._LastTime.Subtract(this._UploadProgress._StartTime);
this._UploadProgress._SecondsDone = 0;
this._UploadProgress._TotalBytes = this._ContentLength;
}
private long InStrB(long startpos, byte[] targetarr, byte[] searcharr, long endpos)
{
long num;
if (endpos != -1)
{
num = endpos - searcharr.Length;
}
else
{
num = targetarr.Length - searcharr.Length;
}
if (startpos <= num)
{
for (long i = startpos; i <= num; i++)
{
int num3 = 0;
for (long j = 0; j < searcharr.Length; j++)
{
if (targetarr[(int) ((IntPtr) (i + j))] != searcharr[(int) ((IntPtr) j)])
{
break;
}
num3++;
}
if (num3 == searcharr.Length)
{
return i;
}
}
}
return (long) (-1);
}
private long InStrB_Boundary(long startpos, byte[] targetarr, ref bool iscloseboundary, long endpos, byte[] inpBoundary)
{
long num2;
iscloseboundary = false;
int length = inpBoundary.Length;
if (endpos != -1)
{
if ((endpos - startpos) < length)
{
return (long) (-1);
}
num2 = endpos - length;
}
else
{
num2 = targetarr.Length - length;
}
if (startpos <= num2)
{
long num3 = startpos;
while (num3 <= num2)
{
if (this._OptimizeBoundarySeach && (targetarr[(int) ((IntPtr) ((num3 + this._DeficesInBoundary) - 1))] != this._Defis))
{
num3 += this._DeficesInBoundary - 2;
continue;
}
int num4 = 0;
long num5 = length - 1;
for (long i = 0; i <= num5; i++)
{
if (targetarr[(int) ((IntPtr) (num3 + i))] != inpBoundary[(int) ((IntPtr) i)])
{
break;
}
num4++;
}
if (num4 == length)
{
if ((((endpos != -1) && (((num3 + num5) + 4) <= endpos)) || ((endpos == -1) && (((num3 + num5) + 4) < targetarr.Length))) && (((targetarr[(int) ((IntPtr) ((num3 + num5) + 1))] == this._CloseBoundary[(int) ((IntPtr) (num5 + 1))]) && (targetarr[(int) ((IntPtr) ((num3 + num5) + 2))] == this._CloseBoundary[(int) ((IntPtr) (num5 + 2))])) && ((targetarr[(int) ((IntPtr) ((num3 + num5) + 3))] == this._CloseBoundary[(int) ((IntPtr) (num5 + 3))]) && (targetarr[(int) ((IntPtr) ((num3 + num5) + 4))] == this._CloseBoundary[(int) ((IntPtr) (num5 + 4))]))))
{
iscloseboundary = true;
}
return num3;
}
num3++;
}
}
return (long) (-1);
}
private bool IsCancelled()
{
if ((this._UploadProgress == null) || ((this._UploadProgress._Status != UploadState.Cancelled) && (this._UploadProgress._Status != UploadState.ConnectionClosed)))
{
return false;
}
return true;
}
private bool IsPartOfBoundaryAtEndofTempBuff()
{
int num2;
long num = this._TempBuffEndPos - this._Boundary.Length;
if (num < 0)
{
num2 = (int) -num;
}
else
{
num2 = 0;
}
while (num2 < this._Boundary.Length)
{
int num4 = this._Boundary.Length - num2;
int index = 0;
while (index < num4)
{
if (this._TempBuff[(int) ((IntPtr) ((num + num2) + index))] != this._Boundary[index])
{
break;
}
index++;
}
if (index == num4)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -