home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
MISC
/
VUPLD11.ZIP
/
VUPLOAD.BAS
< prev
next >
Wrap
BASIC Source File
|
2004-12-14
|
11KB
|
419 lines
' ──────────────────────────────────────────────────────────────────────────
' Aspect Technologies 2k 12/14/2004
' VUpload v1.1.0 File 1 of 1
' áetaX Tested [û]
'
' Refer to the program documentation for installation procedures.
' Filename: VUPLOAD.DOC
'
' VUpload v1.1 Copyright (c) 2004
' All Rights Reserved
'
' ── Notice ────────────────────────────────────────────────────────────────
'
' This script is property of Aspect Technologies and may not be changed in a
' manner that eliminates its possession. You may modify the script to
' customize it for the sysop's needs as long as references to Aspect and
' its affiliates are not changed or destroyed. This script may be freely
' distributed WITHOUT charge.
'
' Aspect Technologies expresses no warranties of any kind. In no case will
' Aspect Technologies be held liable for direct, indirect or incidental
' damages resulting from any defect in this software. Use at your own
' risk.
'
' ── History ───────────────────────────────────────────────────────────────
'
' Version 1.0 - First public release.
' 12/04/2004 - A VADV utility to upload local files into a database.
'
' Version 1.1 - Fixed major database issue.
' 12/14/2004
'
' ──────────────────────────────────────────────────────────────────────────
DECLARE SUB ErrorCmdLine ()
DECLARE FUNCTION TRIM$ (text$)
DECLARE FUNCTION CalcDayNumber& (m AS LONG, d AS LONG, y AS LONG)
DECLARE FUNCTION CalcAge& (m AS LONG, d AS LONG, y AS LONG)
DECLARE FUNCTION UnixTime& (tz AS LONG)
DECLARE FUNCTION LongDate$ (tz AS STRING)
DEFINT A-Z
'$INCLUDE: 'vadvcfg.bas'
cr$ = CHR$(13): lf$ = CHR$(10): es$ = CHR$(27)
version$ = "1.1"
DIM cfgMain AS cfgMain
DIM cfgSysPaths AS cfgSysPaths
DIM datDB AS datDB
DIM datStats AS datStats
DIM sysop AS datUserfile
DIM dbInfo AS cfgDatabase
DIM newDB AS datDB
DIM datDBSeq AS datDBSeq
' Print program information.
CLS
PRINT
PRINT "VUpload v" + version$
PRINT "(c) Aspect Technologies"
PRINT "-----------------------"
PRINT
' Examine the command line.
' VUPLOAD.EXE [/M|/C] FILENAME.EXT DATABASE <DESCRIPTION>
cmdline$ = TRIM$(COMMAND$)
fileopt$ = "C"
opt$ = UCASE$(LEFT$(cmdline$, 2))
p = INSTR(opt$, "/M")
IF (p > 0) THEN
fileopt$ = "M"
l$ = TRIM$(LEFT$(cmdline$, p - 1))
r$ = TRIM$(MID$(cmdline$, p + 3))
cmdline$ = l$ + r$
END IF
p = INSTR(opt$, "/C")
IF (p > 0) THEN
fileopt$ = "C"
l$ = TRIM$(LEFT$(cmdline$, p - 1))
r$ = TRIM$(MID$(cmdline$, p + 3))
cmdline$ = l$ + r$
END IF
p = INSTR(cmdline$, " ")
IF (p = 0) THEN ErrorCmdLine
filename$ = TRIM$(LEFT$(cmdline$, p - 1))
cmdline$ = TRIM$(MID$(cmdline$, p + 1))
IF (LEN(cmdline$) = 0) THEN ErrorCmdLine
p = INSTR(cmdline$, " ")
IF (p = 0) THEN
database$ = TRIM$(cmdline$)
filedesc$ = ""
ELSE
database$ = TRIM$(LEFT$(cmdline$, p - 1))
filedesc$ = TRIM$(MID$(cmdline$, p + 1))
END IF
IF (INSTR(filename$, "*") > 0 OR INSTR(filename$, "?") > 0) THEN
PRINT "Filenames cannot contain * or ?"
END
END IF
IF (LEN(filedesc$) > 64) THEN
filedesc$ = LEFT$(filedesc$, 64)
END IF
' Get the main configuration.
OPEN "MAIN.CFG" FOR RANDOM ACCESS READ SHARED AS #1 LEN = LEN(cfgMain)
IF (LOF(1) = 0) THEN
CLOSE #1
KILL "MAIN.CFG"
PRINT "Error - MAIN.CFG is missing."
END
END IF
GET #1, 1, cfgMain
CLOSE #1
' Get the system paths.
OPEN "SYSPATHS.CFG" FOR RANDOM ACCESS READ SHARED AS #1 LEN = LEN(cfgSysPaths)
IF (LOF(1) = 0) THEN
CLOSE #1
KILL "SYSPATHS.CFG"
PRINT "Error - SYSPATHS.CFG is missing."
END
END IF
GET #1, 1, cfgSysPaths
CLOSE #1
' Get the sysop's user account.
f$ = TRIM$(cfgSysPaths.dat) + "\USERFILE.DAT"
OPEN f$ FOR RANDOM ACCESS READ SHARED AS #1 LEN = LEN(sysop)
IF (LOF(1) = 0) THEN
CLOSE #1
KILL f$
PRINT "Error - USERFILE.DAT is missing."
END
END IF
GET #1, 1, sysop
CLOSE #1
' Check the file to see if it exists.
OPEN filename$ FOR RANDOM ACCESS READ SHARED AS #1
IF (LOF(1) = 0) THEN
CLOSE #1
KILL filename$
PRINT "Error - File: " + filename$ + ", not found."
END
END IF
filesize = LOF(1)
CLOSE #1
' Get the database information.
OPEN "DATABASE.CFG" FOR RANDOM ACCESS READ SHARED AS #1 LEN = LEN(dbInfo)
IF (LOF(1) = 0) THEN
CLOSE #1
KILL "DATABASE.CFG"
PRINT "Error - DATABASE.CFG is missing."
END
END IF
db = 0
n = LOF(1) \ LEN(dbInfo)
FOR i = 1 TO n
GET #1, i, dbInfo
IF (TRIM$(dbInfo.filename) = database$) THEN
db = 1
EXIT FOR
END IF
NEXT i
CLOSE #1
IF (db = 0) THEN
PRINT "Error - Specified Database is not configured in VConfig."
END
END IF
' Try to extract file_id.diz for extended description.
longdesc$ = filedesc$ + cr$ + lf$ + cr$ + lf$
longdesc$ = longdesc$ + "Uploaded by VUpload v" + version$
' Copy the file to the directory.
IF (TRIM$(dbInfo.filepath) = "") THEN
PRINT "Error - Database has no path configured."
END
END IF
f$ = filename$
p = INSTR(filename$, "\")
IF (p > 0) THEN
DO WHILE (p > 0)
f$ = TRIM$(MID$(f$, p + 1))
p = INSTR(f$, "\")
LOOP
END IF
file$ = f$
f$ = TRIM$(dbInfo.filepath) + "\" + f$
OPEN f$ FOR RANDOM ACCESS READ SHARED AS #1
IF (LOF(1) > 0) THEN
CLOSE #1
PRINT "Error - Specified filename already exists."
END
END IF
CLOSE #1
s$ = "COPY " + filename$ + " " + TRIM$(dbInfo.filepath) + " > nul."
SHELL s$
OPEN f$ FOR RANDOM ACCESS READ SHARED AS #1
IF LOF(1) = 0 THEN
CLOSE #1
KILL f$
PRINT "Error - Destination directory does not exist."
END
END IF
CLOSE #1
IF (fileopt$ = "M") THEN
KILL filename$
END IF
' Create the DB information.
f$ = TRIM$(cfgSysPaths.db) + "\" + database$ + ".BIN"
OPEN f$ FOR RANDOM ACCESS READ SHARED AS #1
msgpos = LOF(1) + 1
CLOSE #1
f$ = TRIM$(cfgSysPaths.dat) + "\DBSEQ.DAT"
OPEN f$ FOR RANDOM ACCESS READ WRITE SHARED AS #1 LEN = LEN(datDBSeq)
IF LOF(1) = 0 THEN
datDBSeq.msgcnt = 0
ELSE
GET #1, 1, datDBSeq
END IF
datDBSeq.msgcnt = datDBSeq.msgcnt + 1
PUT #1, 1, datDBSeq
CLOSE #1
newDB.fromuserno = 1
newDB.touserno = 0
newDB.fromhandle = sysop.handle
newDB.tohandle = ""
newDB.fromnetnode = "0"
newDB.tonetnode = ""
newDB.fromnetid = 1
newDB.tonetid = 1
newDB.timestamp = UnixTime(0)
newDB.sysmsgno = datDBSeq.msgcnt
newDB.threadbk = 0
newDB.threadbkn = 0
newDB.subject = filedesc$
newDB.deleted = 0
newDB.creation = LongDate(cfgMain.timezone)
newDB.offline = 0
newDB.attfilesize = filesize
newDB.attfilename = file$
newDB.attfilepath = ""
newDB.lib = 0
newDB.downloadno = 0
newDB.dbid = 0
newDB.filename = dbInfo.filename
newDB.msgpos = msgpos
newDB.msglength = LEN(longdesc$) + 2
newDB.originnet = 0
newDB.fidoflags = 0
newDB.originnode = 0
newDB.reserved = ""
newDB.extra = ""
' Add the entry to the DAT file.
f$ = TRIM$(cfgSysPaths.db) + "\" + database$ + ".DAT"
OPEN f$ FOR RANDOM ACCESS WRITE SHARED AS #1 LEN = LEN(newDB)
r = LOF(1) \ LEN(newDB) + 1
PUT #1, r, newDB
CLOSE #1
' Add the entry to the BIN file.
IF (filesize > 0) THEN
f$ = TRIM$(cfgSysPaths.db) + "\" + database$ + ".BIN"
OPEN f$ FOR APPEND ACCESS READ WRITE SHARED AS #1
PRINT #1, longdesc$
CLOSE #1
END IF
' Increase the upload statistics.
f$ = TRIM$(cfgSysPaths.dat) + "\STATVBBS.DAT"
OPEN f$ FOR RANDOM ACCESS READ WRITE AS #1 LEN = LEN(datStats)
GET #1, 1, datStats
datStats.uploadstotal = datStats.uploadstotal + 1
datStats.uploadstoday = datStats.uploadstoday + 1
PUT #1, 1, datStats
CLOSE #1
PRINT "Done!"
END
FUNCTION CalcAge& (m AS LONG, d AS LONG, y AS LONG)
DIM month AS LONG
DIM day AS LONG
DIM year AS LONG
DIM t AS INTEGER
DIM n AS INTEGER
DIM a AS INTEGER
DIM l AS INTEGER
month = VAL(LEFT$(DATE$, 2))
day = VAL(MID$(DATE$, 4, 2))
year = VAL(RIGHT$(DATE$, 4))
t = CalcDayNumber(month, day, year)
n = CalcDayNumber(m, d, y)
a = t - n
l = (a / 365) \ 4
CalcAge = (a - l) \ 365
END FUNCTION
FUNCTION CalcDayNumber& (m AS LONG, d AS LONG, y AS LONG)
DIM v AS LONG
m = (m + 9) MOD 12
y = y - (m \ 10)
v = 365 * y
v = v + (y \ 4)
v = v - (y \ 100)
v = v + (y \ 400)
v = v + (((m * 306) + 5) \ 10)
v = v + d - 1
CalcDayNumber = v
END FUNCTION
SUB ErrorCmdLine
PRINT "You must specify a filename and database name to upload."
PRINT "VUPLOAD.EXE [/C|/M] FILENAME.EXT DATABASE <DESCRIPTION>"
PRINT
PRINT "Options:"
PRINT " /C - Copy filename to database's file directory"
PRINT " /M - Move filename to database's file directory"
END
END SUB
FUNCTION LongDate$ (tz AS STRING)
DIM d AS LONG
DIM m AS LONG
DIM y AS LONG
DIM a AS LONG
a = (14 - m) \ 12
y = y - a
m = m + (12 * a) - 2
d = d + y + (y \ 4) - (y \ 100)
d = d + (y \ 400) + ((31 * m) \ 12)
d = d MOD 7
SELECT CASE d
CASE 1
dow$ = "Mon"
CASE 2
dow$ = "Tue"
CASE 3
dow$ = "Wed"
CASE 4
dow$ = "Thu"
CASE 5
dow$ = "Fri"
CASE 6
dow$ = "Sat"
CASE 7
dow$ = "Sun"
CASE ELSE
dow$ = "Sun"
END SELECT
month$ = LEFT$(DATE$, 2)
day$ = MID$(DATE$, 4, 2)
year$ = RIGHT$(DATE$, 4)
SELECT CASE month$
CASE "01"
mo$ = "Jan"
CASE "02"
mo$ = "Feb"
CASE "03"
mo$ = "Mar"
CASE "04"
mo$ = "Apr"
CASE "05"
mo$ = "May"
CASE "06"
mo$ = "Jun"
CASE "07"
mo$ = "Jul"
CASE "08"
mo$ = "Aug"
CASE "09"
mo$ = "Sep"
CASE "10"
mo$ = "Oct"
CASE "11"
mo$ = "Nov"
CASE "12"
mo$ = "Dec"
END SELECT
LongDate = dow$ + " " + mo$ + " " + day$ + ", " + year$ + " " + TIME$ + " " + tz
END FUNCTION
FUNCTION TRIM$ (text$)
TRIM$ = RTRIM$(LTRIM$(text$))
END FUNCTION
FUNCTION UnixTime& (tz AS LONG)
DIM month AS LONG
DIM day AS LONG
DIM year AS LONG
DIM a AS LONG
DIM t AS LONG
DIM n AS LONG
month = VAL(LEFT$(DATE$, 2))
day = VAL(MID$(DATE$, 4, 2))
year = VAL(RIGHT$(DATE$, 4))
t = CalcDayNumber(month, day, year)
n = CalcDayNumber(1, 1, 1970)
a = t - n
a = a * 1440
a = a * 60
UnixTime = a + TIMER - tz
END FUNCTION