-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
samples: Make winapi samples unmount drives when exiting #382
Conversation
samples/winapi_drivelist/main.c
Outdated
Sleep(20000); | ||
|
||
ret = nxUnmountDrive('C'); | ||
if (!ret) { // if there was an error while unmounting (nxUnmountDrive() returns false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't do these sort of inline-comments. Check surrounding code for how it should be done.
(Other instances, too)
samples/winapi_drivelist/main.c
Outdated
if (!ret) { // if there was an error while unmounting (nxUnmountDrive() returns false) | ||
debugPrint("Couldn't unmount C: drive. Exiting in 5 seconds..."); | ||
Sleep (5000); | ||
return 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd consider this bad practice, because we are already trying to exit, and this just skips unmounting E drive, too.
Instead, set error flag instead which can be returned from main
?
(Other instances, too)
b66d362
to
bc0186c
Compare
samples/winapi_drivelist/main.c
Outdated
debugPrint("Failed to retrieve drive strings!\n"); | ||
errorCount++; | ||
error = GetLastError(); | ||
debugPrint("Failed to retrieve drive strings! Reason: %s\n", error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error
is not a char*
; so %s
is wrong.
samples/winapi_drivelist/main.c
Outdated
@@ -7,17 +7,27 @@ int main(void) | |||
{ | |||
XVideoSetMode(640, 480, 32, REFRESH_DEFAULT); | |||
|
|||
// Create a variable for WinAPI error checking | |||
DWORD error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This doesn't have to be at this scope.
samples/winapi_drivelist/main.c
Outdated
// Create a variable for WinAPI error checking | ||
DWORD error; | ||
// Make a variable to keep track of how many errors we have | ||
int errorCount = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This can be unsigned int
.
samples/winapi_drivelist/main.c
Outdated
// Additional error info can be retrieved with GetLastError() | ||
error = GetLastError(); | ||
debugPrint("Failed to mount C: drive! Reason: %s\n", error); | ||
// Give the user some time to read the message | ||
Sleep(5000); | ||
return 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be considered optional now.
samples/winapi_drivelist/main.c
Outdated
errorCount++; | ||
debugPrint("Couldn't unmount C: drive Reason: %s\n. Trying to unmount E: drive...\n", error); | ||
// Leave some time for the user to read the error | ||
Sleep(5000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You already wait 10 seconds if any error happened. Waiting an additional 5 seconds per error is not necessary in my opinion.
(Other instances, too)
samples/winapi_drivelist/main.c
Outdated
@@ -56,10 +67,32 @@ int main(void) | |||
debugPrint("%s\n", drive); | |||
while(*drive++); | |||
} | |||
debugPrint("\ndone"); | |||
debugPrint("\nDone! Exiting in 10 seconds..."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not what's happening.
samples/winapi_drivelist/main.c
Outdated
debugPrint("Failed to mount E: drive!\n"); | ||
errorCount++; | ||
error = GetLastError(); | ||
debugPrint("Failed to mount E: drive! Reason: %s\n", error); | ||
Sleep(5000); | ||
return 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually worse now, because we don't unmount in this case.
samples/winapi_drivelist/main.c
Outdated
ret = nxUnmountDrive('E'); | ||
if (!ret) { | ||
error = GetLastError(); | ||
errorCount++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like you should do this before or after printing the message, but not inbetween getting the message and printing it.
samples/winapi_filefind/main.c
Outdated
if (error == ERROR_NO_MORE_FILES) { | ||
debugPrint("Done!\n"); | ||
debugPrint("Done! Exiting in 10 seconds...\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not what's happening.
} else { | ||
debugPrint("error: %x\n", error); | ||
} | ||
|
||
FindClose(hFind); | ||
|
||
while (1) { | ||
Sleep(2000); | ||
Sleep(10000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wait doesn't make any sense to me.
debugPrint("\ndone"); | ||
debugPrint("\nDone! Re-running in 10 seconds..."); | ||
|
||
// Give some time to the user to read the drives |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user would be reading the output, but not the "drives"
@@ -7,27 +7,30 @@ int main(void) | |||
{ | |||
XVideoSetMode(640, 480, 32, REFRESH_DEFAULT); | |||
|
|||
// Create a variable to check if there was any error in the program | |||
BOOL errored = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This is a poor variable name in my opinion.
Sleep(5000); | ||
return 1; | ||
errored = true; | ||
// Additional error info can be retrieved with GetLastError() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment doesn't add anything
debugPrint("Failed to mount C: drive!\n"); | ||
Sleep(5000); | ||
return 1; | ||
errored = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be done after handling the error, to not disturb the readability of the important bits.
Also if this is later turned into a mark_error();
(for whatever reason) then that function might actually change the GetLastError()
value.
@@ -56,10 +58,30 @@ int main(void) | |||
debugPrint("%s\n", drive); | |||
while(*drive++); | |||
} | |||
debugPrint("\ndone"); | |||
debugPrint("\nDone! Re-running in 10 seconds..."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this "re-running" happen?
Sleep(10000); | ||
|
||
ret = nxUnmountDrive('C'); | ||
// If there was an error while unmounting (nxUnmountDrive() returns false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This claims that it will ~"return false". This isn't actually happening anywhere.
Due to the large amount of issues and backlog, I'm leaning towards closing this PR. |
I understand that there are certain issues in the code, and I will prioritize fixing them. I will do some changes here soon, but first I want to go through them in detail myself to find what might be bad and what might be better to change. I will ping when I believe this will be ready for further review, on a different PR if necessary, since, as stated, this one is starting to become very inefficient. |
@kosmas12 Do you still intend to fix this PR per feedback? If not, I will close this PR within the next couple of days. |
Closed due to lack of activity. If you wish to resume this work, we can re-open. |
Fixes #381