RamSave
Verfasst: 11.04.2006 09:36
Hi, ich habe ein kleins programm geschrieben mit dem man daten im ram aufbewaren und verwalten kann, und gegenfalls wieder zurück auf die HD speichern, oder z.B. um daten kurzzeitung vor der Harddisk zu verstecken falls jemand anders am pc arbeitet (mit Strg+alt+h versteckt sich das programm, bis es nochmal gedrück wurde). Um daten zu speichern einfach per drag and drop rein, dan mit linker maustaste auf die datei klicken zum verschieben und mit rechter löschen oder speichern!
Code: Alles auswählen
InitSprite()
OpenWindow(0,0,0,300,200,"RamSave",#PB_Window_SizeGadget|#PB_Window_MinimizeGadget)
ExamineDesktops()
OpenWindowedScreen(WindowID(0),0,0,DesktopWidth(0),DesktopHeight(0),0,0,0)
DragAcceptFiles_ (WindowID(0), 1)
Global used = 0
GlobalMemoryStatus_(Memory.MEMORYSTATUS)
Global max = Memory\dwTotalPhys/1024/1024
Global draw_text$
Procedure updatetitle()
SetWindowTitle(0,"RamSave Used: "+Str(used)+"/"+Str(max)+"MB")
draw_text$ = "Used: "+Str(used)+"/"+Str(max)+"MB"
EndProcedure
updatetitle()
Procedure.l DropFiles ()
ProcedureReturn EventwParam ()
EndProcedure
;
Procedure GetNumDropFiles (*dropFiles)
ProcedureReturn DragQueryFile_ (*dropFiles, $FFFFFFFF, temp$, 0)
EndProcedure
;
Procedure.s GetDropFile (*dropFiles, index)
bufferNeeded = DragQueryFile_ (*dropFiles, index, 0, 0)
For a = 1 To bufferNeeded: buffer$ + " ": Next ; Short by one character!
DragQueryFile_ (*dropFiles, index, buffer$, bufferNeeded+1)
ProcedureReturn buffer$
EndProcedure
;
Procedure FreeDropFiles (*dropFiles)
DragFinish_ (*dropFiles)
EndProcedure
Procedure.l RECTSOVERLAP(X1,Y1,Breite1,Hoehe1,X2,Y2,Breite2,Hoehe2)
If x1<=(x2+breite2) And y1<=y2+hoehe2 And (x1+breite1) >=x2 And (y1+hoehe1)>= y2
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
CreatePopupMenu(1)
MenuItem(2,"Save to Harddisk")
MenuItem(3,"Delete")
MenuItem(4,"Set Color")
Structure files
name.s
buffer.l
size.l
menu.l
x.l
y.l
drag.b
rgb.l
EndStructure
NewList file.files()
Repeat
event = WaitWindowEvent()
ClearScreen(RGB(0,0,0))
StartDrawing(ScreenOutput())
DrawText(0,0,draw_text$,RGB(0,200,0),RGB(0,0,0))
ForEach file()
DrawText(file()\x,file()\y,GetFilePart(file()\name),file()\rgb)
If rectsoverlap(file()\x,file()\y,TextWidth(GetFilePart(file()\name)),TextHeight(GetFilePart(file()\name)),WindowMouseX(0),WindowMouseY(0),1,1)
If event = #WM_RBUTTONDOWN
DisplayPopupMenu(1,WindowID(0))
extract_buffer = file()\buffer
EndIf
If event = #WM_LBUTTONDOWN
file()\drag.b = 1-file()\drag.b
EndIf
EndIf
If file()\drag = 1
file()\x = WindowMouseX(0)-(TextWidth(GetFilePart(file()\name))/2)
file()\y = WindowMouseY(0)-(TextHeight(GetFilePart(file()\name))/2)
EndIf
Next
StopDrawing()
FlipBuffers()
If event = #PB_Event_Menu
If EventMenu() = 2
ForEach file()
If file()\buffer = extract_buffer
path$ = SaveFileRequester("Save",file()\name,"",0)
If path$
If CreateFile(0,path$)
WriteData(0,file()\buffer,file()\size)
used = used - file()\size/1024/1024
updatetitle()
DeleteElement(file())
CloseFile(0)
EndIf
EndIf
EndIf
Next
EndIf
If EventMenu() = 3
ForEach file()
If file()\buffer = extract_buffer
FreeMemory(file()\buffer)
used = used - file()\size/1024/1024
updatetitle()
DeleteElement(file())
EndIf
Next
EndIf
If EventMenu() = 4
ForEach file()
If file()\buffer = extract_buffer
file()\rgb = ColorRequester(file()\rgb)
EndIf
Next
EndIf
extract_name$ = ""
EndIf
If GetAsyncKeyState_(#VK_CONTROL) And GetAsyncKeyState_(#VK_MENU) And GetAsyncKeyState_(#VK_H)
Delay(200)
HideWindow(0,1)
Repeat
Delay(100)
Until GetAsyncKeyState_(#VK_CONTROL) And GetAsyncKeyState_(#VK_MENU) And GetAsyncKeyState_(#VK_H)
HideWindow(0,0)
EndIf
If event = #WM_DROPFILES
*dropped = DropFiles ()
num.l = DragQueryFile_ (*dropped , $FFFFFFFF, temp$, 0)
f$ = ""
win_x = WindowMouseX(0)
win_y = WindowMouseY(0)
For files = 0 To num - 1
path$ = GetDropFile (*dropped, files)
If ReadFile(0,path$)
AddElement(file())
file()\name = path$
file()\rgb = RGB(0,0,0)
file()\x = win_x
file()\y = win_y+(files*30)
file()\size = Lof(0)
file()\buffer = AllocateMemory(file()\size)
ReadData(0,file()\buffer,file()\size)
used = used + Lof(0)/1024/1024
CloseFile(0)
Else
MessageRequester("","Error loading file.")
EndIf
updatetitle()
Next
FreeDropFiles (*dropped)
EndIf
Delay(10)
Until event = #PB_Event_CloseWindow