mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-15 22:21:04 +00:00
Update pipe-ipc.js
This commit is contained in:
parent
88482f5ba8
commit
34668ad54e
|
@ -93,6 +93,18 @@ function createADO() {
|
||||||
return CreateObject("ADODB.Stream");
|
return CreateObject("ADODB.Stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openTextFile(filename, iomode) {
|
||||||
|
return createFSO().OpenTextFile(filename, iomode, true, TristateTrue);
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkFileExists(filename) {
|
||||||
|
return createFSO().FileExists(filename);;
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteFile(filename) {
|
||||||
|
if (checkFileExists(filename)) createFSO().DeleteFile(filename);
|
||||||
|
}
|
||||||
|
|
||||||
function AdoConvertToStream(ado, position) {
|
function AdoConvertToStream(ado, position) {
|
||||||
position = (position !== "undefined" ? position : 0);
|
position = (position !== "undefined" ? position : 0);
|
||||||
|
|
||||||
|
@ -109,7 +121,7 @@ function AdoConvertToStream(ado, position) {
|
||||||
|
|
||||||
function PipeIPC() {
|
function PipeIPC() {
|
||||||
this.path = "data\\.pipe_:pipename";
|
this.path = "data\\.pipe_:pipename";
|
||||||
this.delimiter = '\r\n';
|
this.delimiter = "\r\n";
|
||||||
this.reader = null;
|
this.reader = null;
|
||||||
this.writer = null;
|
this.writer = null;
|
||||||
this.recorder = null;
|
this.recorder = null;
|
||||||
|
@ -153,7 +165,7 @@ function PipeIPC() {
|
||||||
this.openWriter = function(iomode) {
|
this.openWriter = function(iomode) {
|
||||||
while (this.writer == null) {
|
while (this.writer == null) {
|
||||||
try {
|
try {
|
||||||
this.writer = createFSO().OpenTextFile(this.path, iomode, true, TristateTrue);
|
this.writer = openTextFile(this.path, iomode);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -168,7 +180,7 @@ function PipeIPC() {
|
||||||
this.openReader = function() {
|
this.openReader = function() {
|
||||||
while (this.reader == null) {
|
while (this.reader == null) {
|
||||||
try {
|
try {
|
||||||
this.reader = createFSO().OpenTextFile(this.path, ForReading, true, TristateTrue);
|
this.reader = openTextFile(this.path, ForReading);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -187,14 +199,14 @@ function PipeIPC() {
|
||||||
this.tmpfile = this.savefile + ".tmp";
|
this.tmpfile = this.savefile + ".tmp";
|
||||||
|
|
||||||
// read a text from save file
|
// read a text from save file
|
||||||
var isExistsSaveFile = createFSO().FileExists(this.savefile);
|
var isExistsSaveFile = checkFileExists(this.savefile);
|
||||||
var isExistsTmpFile = createFSO().FileExists(this.tmpfile);
|
var isExistsTmpFile = checkFileExists(this.tmpfile);
|
||||||
while (isExistsSaveFile && !isExistsTmpFile) {
|
while (isExistsSaveFile && !isExistsTmpFile) {
|
||||||
try {
|
try {
|
||||||
var fso = createFSO().OpenTextFile(this.tmpfile, ForWriting, true, TristateTrue);
|
var fso = openTextFile(this.tmpfile, ForWriting);
|
||||||
fso.Write(this.readTextFromFile(this.savefile));
|
fso.Write(this.readTextFromFile(this.savefile));
|
||||||
fso.Close();
|
fso.Close();
|
||||||
isExistsTmpFile = createFSO().FileExists(this.tmpfile);
|
isExistsTmpFile = checkFileExists(this.tmpfile);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
isExistsTmpFile = false;
|
isExistsTmpFile = false;
|
||||||
}
|
}
|
||||||
|
@ -212,7 +224,7 @@ function PipeIPC() {
|
||||||
this.openRecorder = function(iomode) {
|
this.openRecorder = function(iomode) {
|
||||||
while (this.recorder == null) {
|
while (this.recorder == null) {
|
||||||
try {
|
try {
|
||||||
this.recorder = createFSO().OpenTextFile(this.tmpfile, iomode, true, TristateTrue);
|
this.recorder = openTextFile(this.tmpfile, iomode);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -285,8 +297,9 @@ function PipeIPC() {
|
||||||
while (!isCommited) {
|
while (!isCommited) {
|
||||||
try {
|
try {
|
||||||
// Open a temporary file
|
// Open a temporary file
|
||||||
var fso = createFSO().OpenTextFile(src, ForReading, true, TristateTrue);
|
var fso = openTextFile(src, ForReading);
|
||||||
var text = fso.ReadAll();
|
var text = fso.ReadAll();
|
||||||
|
fso.Close(); // close the file immediately
|
||||||
var sentences = text.split(this.delimiter);
|
var sentences = text.split(this.delimiter);
|
||||||
var newSentences = [], str = '';
|
var newSentences = [], str = '';
|
||||||
|
|
||||||
|
@ -296,6 +309,19 @@ function PipeIPC() {
|
||||||
newSentences.push(sentences.pop());
|
newSentences.push(sentences.pop());
|
||||||
}
|
}
|
||||||
str = newSentences.reverse().join(this.delimiter);
|
str = newSentences.reverse().join(this.delimiter);
|
||||||
|
|
||||||
|
// Write a new temporary file
|
||||||
|
var done = false;
|
||||||
|
while (!done) {
|
||||||
|
try {
|
||||||
|
var _fso = openTextFile(src, ForWriting);
|
||||||
|
_fso.Write(str);
|
||||||
|
_fso.Close();
|
||||||
|
done = true;
|
||||||
|
} catch (e) {
|
||||||
|
done = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
str = text;
|
str = text;
|
||||||
}
|
}
|
||||||
|
@ -310,18 +336,6 @@ function PipeIPC() {
|
||||||
ado.SaveToFile(dst, adSaveCreateOverWrite);
|
ado.SaveToFile(dst, adSaveCreateOverWrite);
|
||||||
ado.Close();
|
ado.Close();
|
||||||
|
|
||||||
// Write a new temporary file
|
|
||||||
/*
|
|
||||||
if (this.maxSentences > 0) {
|
|
||||||
var handler = createFSO().OpenTextFile(src, ForWriting, true, TristateTrue);
|
|
||||||
handler.Write(str);
|
|
||||||
handler.Close();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Close the temporary file
|
|
||||||
fso.Close();
|
|
||||||
|
|
||||||
// Set a result
|
// Set a result
|
||||||
isCommited = true;
|
isCommited = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -380,13 +394,13 @@ function PipeIPC() {
|
||||||
|
|
||||||
this.destroy = function() {
|
this.destroy = function() {
|
||||||
this.close();
|
this.close();
|
||||||
createFSO().DeleteFile(this.path);
|
deleteFile(this.path);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.readTextFromFile = function(filename, charset) {
|
this.readTextFromFile = function(filename, charset) {
|
||||||
var text = '';
|
var text = '';
|
||||||
|
|
||||||
var isFileExists = createFSO().FileExists(filename);
|
var isFileExists = checkFileExists(filename);
|
||||||
if (isFileExists) {
|
if (isFileExists) {
|
||||||
var isRead = false;
|
var isRead = false;
|
||||||
while (!isRead) {
|
while (!isRead) {
|
||||||
|
@ -445,7 +459,7 @@ exports.adSaveCreateNotExist = adSaveCreateNotExist;
|
||||||
exports.adSaveCreateOverWrite = adSaveCreateOverWrite;
|
exports.adSaveCreateOverWrite = adSaveCreateOverWrite;
|
||||||
exports.adModeReadWrite = adModeReadWrite;
|
exports.adModeReadWrite = adModeReadWrite;
|
||||||
|
|
||||||
exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.12";
|
exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.13";
|
||||||
exports.AUTHOR = "abuse@catswords.net";
|
exports.AUTHOR = "abuse@catswords.net";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = require;
|
exports.require = require;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user