Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

kosmas12
Copy link
Contributor

Fixes #381

Sleep(20000);

ret = nxUnmountDrive('C');
if (!ret) { // if there was an error while unmounting (nxUnmountDrive() returns false)
Copy link
Member

@JayFoxRox JayFoxRox Jul 16, 2020

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)

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;
Copy link
Member

@JayFoxRox JayFoxRox Jul 16, 2020

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)

@kosmas12 kosmas12 force-pushed the unmountsamples branch 3 times, most recently from b66d362 to bc0186c Compare July 16, 2020 20:48
debugPrint("Failed to retrieve drive strings!\n");
errorCount++;
error = GetLastError();
debugPrint("Failed to retrieve drive strings! Reason: %s\n", error);
Copy link
Member

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.

@@ -7,17 +7,27 @@ int main(void)
{
XVideoSetMode(640, 480, 32, REFRESH_DEFAULT);

// Create a variable for WinAPI error checking
DWORD error;
Copy link
Member

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.

// Create a variable for WinAPI error checking
DWORD error;
// Make a variable to keep track of how many errors we have
int errorCount = 0;
Copy link
Member

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.

// 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;
Copy link
Member

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.

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);
Copy link
Member

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)

@@ -56,10 +67,32 @@ int main(void)
debugPrint("%s\n", drive);
while(*drive++);
}
debugPrint("\ndone");
debugPrint("\nDone! Exiting in 10 seconds...");
Copy link
Member

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.

debugPrint("Failed to mount E: drive!\n");
errorCount++;
error = GetLastError();
debugPrint("Failed to mount E: drive! Reason: %s\n", error);
Sleep(5000);
return 1;
Copy link
Member

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.

ret = nxUnmountDrive('E');
if (!ret) {
error = GetLastError();
errorCount++;
Copy link
Member

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.

if (error == ERROR_NO_MORE_FILES) {
debugPrint("Done!\n");
debugPrint("Done! Exiting in 10 seconds...\n");
Copy link
Member

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);
Copy link
Member

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
Copy link
Member

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;
Copy link
Member

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()
Copy link
Member

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;
Copy link
Member

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...");
Copy link
Member

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)
Copy link
Member

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.

@JayFoxRox
Copy link
Member

Due to the large amount of issues and backlog, I'm leaning towards closing this PR.
I feel that some changes during review actually made some of the code worse than the initial proposal.

@kosmas12
Copy link
Contributor Author

kosmas12 commented Aug 8, 2020

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.

@mborgerson
Copy link
Member

@kosmas12 Do you still intend to fix this PR per feedback? If not, I will close this PR within the next couple of days.

@mborgerson
Copy link
Member

Closed due to lack of activity. If you wish to resume this work, we can re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Samples don't demonstrate how to unmount drives
3 participants