Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1.  
  2. // Program: File_Buffer
  3. // Start: 2/15/03 Release:
  4. // Version 1.1
  5. //
  6. // Program opens files using the filebuf parameters in the fstream.h
  7. // C++ library. Opens all files as "share none" blocking access from other users.
  8. // Manages files with a linked list.
  9.  
  10. #include <fstream.h>
  11. #include <stdlib.h>
  12. //#include <time.h> Associate file locking with current time
  13. //#include <conio.h>
  14. #include <apstring.h>
  15.  
  16. #include <format.h>
  17.  
  18. short int Menu();
  19. apstring DirPrompt(apstring item, apstring Prompt);
  20.  
  21. #include "cLock_File.h"
  22. #include "cLock_Manager.h"
  23.  
  24. int main()
  25. {
  26. short int choice;
  27. apstring temp = "0";
  28.  
  29. cLock_Manager List; // Declares linked list to manage file locks
  30.  
  31. temp[0] = char(8);
  32. List.SET_ADMIN_PASSWORD(temp);
  33.  
  34. Start:
  35. CLS();
  36. choice = Menu();
  37. CLS();
  38.  
  39. if(choice == 1)
  40. {
  41. cin.ignore();
  42. List.Lock(DirPrompt("file", "lock"));
  43. }
  44. else if(choice == 2)
  45. {
  46. List.DisplayAll();
  47. cin >> choice;
  48.  
  49. CLS();
  50. List.UnLock(choice);
  51. choice = 2;
  52. }
  53. else if(choice == 3)
  54. {
  55. cin.ignore();
  56. List.LoadList(DirPrompt("list", "load"));
  57. }
  58. else if(choice == 4)
  59. {
  60. cin.ignore();
  61. if(List.UnLockAll())
  62. {List.Reset();}
  63. else
  64. {
  65. cout << "!!!Invalid password!!!" << endl;
  66. system("pause");
  67. }
  68. }
  69.  
  70. if(choice != 0)
  71. {goto Start;}
  72. else
  73. {
  74. cin.ignore();
  75. cout << "Enter the administrative password: "; getline(cin, temp);
  76.  
  77. if((temp != List.Get_OVERRIDE()) && (temp != List.Get_ADMIN_PASSWORD()))
  78. {
  79. cout << "!!!INVALID PASSWORD!!!" << endl;
  80. system("pause");
  81. goto Start;
  82. }
  83. }
  84.  
  85. List.Reset(); // Deletes all nodes and returns memory to heap
  86.  
  87. return 0;
  88. }
  89.  
  90. short int Menu()
  91. {
  92. short int choice;
  93.  
  94. cout << "What would you like to do?" << endl;
  95. skip(1);
  96. cout << "0 : Exit" << endl;
  97. cout << "1 : Lock a file" << endl;
  98. cout << "2 : Unlock a file" << endl;
  99. // cout << "3 : Change a password(disabled)" << endl; // Administrative Password set a subset of this option
  100. cout << "3 : Load a list" << endl;
  101. cout << "4 : Unlock all files" << endl;
  102. cout << endl;
  103. cin >> choice;
  104.  
  105. if(choice > 0 && choice < 5)
  106. {return choice;}
  107. else
  108. {return 0;}
  109. }
  110.  
  111. apstring DirPrompt(apstring item, apstring Prompt)
  112. {
  113. cout << "Enter the path of the " << item << " that you want to " << Prompt << "." << endl;
  114. cout << endl;
  115. getline(cin, Prompt);
  116.  
  117. return Prompt;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement