Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions scripts/yyBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2393,7 +2393,7 @@ function buffer_load_async(_buffer, _fname, _offset, _size) {
if (!pBuff) return -1;

// Try and load from local storage first
var pTextFile = LoadTextFile_Block(_fname, true);
var pTextFile = LoadBinaryFile_Block(_fname, true);
if (pTextFile)
{
if (_size >= 0 && pTextFile.length > _size)
Expand Down Expand Up @@ -2447,10 +2447,10 @@ function buffer_load(_fname) {
_fname = yyGetString(_fname);
var shouldDecode = true;

var pTextFile = LoadTextFile_Block(_fname, true);
var pTextFile = LoadBinaryFile_Block(_fname, true);
if (pTextFile == null)
{
pTextFile = LoadTextFile_Block(_fname, false);
pTextFile = LoadBinaryFile_Block(_fname, false);
shouldDecode = false;
}
if (pTextFile == null) return -1;
Expand Down Expand Up @@ -2528,10 +2528,10 @@ function buffer_load_partial(buffer, filename, src_offset, len, dst_offset) {

var shouldDecode = true;

var pTextFile = LoadTextFile_Block(filename, true);
var pTextFile = LoadBinaryFile_Block(filename, true);
if (pTextFile == null)
{
pTextFile = LoadTextFile_Block(filename, false);
pTextFile = LoadBinaryFile_Block(filename, false);
shouldDecode = false;
}
if (pTextFile == null) return -1;
Expand Down
52 changes: 48 additions & 4 deletions scripts/yyIniFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ function RawFileExists(_url) {

// #############################################################################################
/// Function:<summary>
/// Read/Write a file from a server
/// Read/Write a BINARY file from a server
/// </summary>
///
/// In: <param name="U">file or URL to access</param>
Expand All @@ -747,6 +747,30 @@ function RawServerReadWrite(U, V)
}
}

// #############################################################################################
/// Function:<summary>
/// Read/Write a TEXT file from a server
/// </summary>
///
/// In: <param name="U">file or URL to access</param>
/// <param name="V">false for GET, true for POST</param>
/// Out: <returns>
/// the file, or null if an error occured.
/// </returns>
// #############################################################################################
function TextServerReadWrite(U, V)
{
try{
var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
X.open(V ? 'PUT' : 'GET', U, false );
X.send(V ? V : '');
g_LastErrorStatus = X.status;
return X.responseText;
}catch(e){
return null;
}
}


// #############################################################################################
/// Function:<summary>
Expand Down Expand Up @@ -815,7 +839,28 @@ function SaveTextFile_Block(_filename, _pFile)
/// </returns>
// #############################################################################################
function LoadTextFile_Block( _FileName, _fLocal )
{
{
return LoadXXXFile_Block( _FileName, _fLocal, TextServerReadWrite );
}

// #############################################################################################
/// Function:<summary>
/// Load a BINARY file from local, OR remote (blocking)
/// </summary>
///
/// In: <param name="_FileName"></param>
/// <param name="_fLocal"></param>
/// Out: <returns>
///
/// </returns>
// #############################################################################################
function LoadBinaryFile_Block( _FileName, _fLocal )
{
return LoadXXXFile_Block( _FileName, _fLocal, RawServerReadWrite );
}

function LoadXXXFile_Block( _FileName, _fLocal, _ServerReadWriteFunc )
{
var pFile = null;

if (_FileName.substring(0, 5) == "file:") return null;
Expand Down Expand Up @@ -846,14 +891,13 @@ function LoadTextFile_Block( _FileName, _fLocal )
_FileName = CheckWorkingDirectory(_FileName);


pFile = RawServerReadWrite(_FileName, false);
pFile = _ServerReadWriteFunc(_FileName, false);
if( ( pFile ==null ) || (pFile==undefined ) ) return null;
if (g_LastErrorStatus == 404) return null;
}
return pFile;
}


// #############################################################################################
/// Function:<summary>
/// Load a TEXT file from local, OR remote (blocking)
Expand Down