Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Program: File_Buffer
- // Start: 2/15/03 Release:
- // Version 1.1
- //
- // Program opens files using the filebuf parameters in the fstream.h
- // C++ library. Opens all files as "share none" blocking access from other users.
- // Manages files with a linked list.
- #include <fstream.h>
- #include <stdlib.h>
- //#include <time.h> Associate file locking with current time
- //#include <conio.h>
- #include <apstring.h>
- #include <format.h>
- short int Menu();
- apstring DirPrompt(apstring item, apstring Prompt);
- #include "cLock_File.h"
- #include "cLock_Manager.h"
- int main()
- {
- short int choice;
- apstring temp = "0";
- cLock_Manager List; // Declares linked list to manage file locks
- temp[0] = char(8);
- List.SET_ADMIN_PASSWORD(temp);
- Start:
- CLS();
- choice = Menu();
- CLS();
- if(choice == 1)
- {
- cin.ignore();
- List.Lock(DirPrompt("file", "lock"));
- }
- else if(choice == 2)
- {
- List.DisplayAll();
- cin >> choice;
- CLS();
- List.UnLock(choice);
- choice = 2;
- }
- else if(choice == 3)
- {
- cin.ignore();
- List.LoadList(DirPrompt("list", "load"));
- }
- else if(choice == 4)
- {
- cin.ignore();
- if(List.UnLockAll())
- {List.Reset();}
- else
- {
- cout << "!!!Invalid password!!!" << endl;
- system("pause");
- }
- }
- if(choice != 0)
- {goto Start;}
- else
- {
- cin.ignore();
- cout << "Enter the administrative password: "; getline(cin, temp);
- if((temp != List.Get_OVERRIDE()) && (temp != List.Get_ADMIN_PASSWORD()))
- {
- cout << "!!!INVALID PASSWORD!!!" << endl;
- system("pause");
- goto Start;
- }
- }
- List.Reset(); // Deletes all nodes and returns memory to heap
- return 0;
- }
- short int Menu()
- {
- short int choice;
- cout << "What would you like to do?" << endl;
- skip(1);
- cout << "0 : Exit" << endl;
- cout << "1 : Lock a file" << endl;
- cout << "2 : Unlock a file" << endl;
- // cout << "3 : Change a password(disabled)" << endl; // Administrative Password set a subset of this option
- cout << "3 : Load a list" << endl;
- cout << "4 : Unlock all files" << endl;
- cout << endl;
- cin >> choice;
- if(choice > 0 && choice < 5)
- {return choice;}
- else
- {return 0;}
- }
- apstring DirPrompt(apstring item, apstring Prompt)
- {
- cout << "Enter the path of the " << item << " that you want to " << Prompt << "." << endl;
- cout << endl;
- getline(cin, Prompt);
- return Prompt;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement