Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

parity uses winapi 0.3.4 #8366

Merged
merged 2 commits into from
Apr 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ app_dirs = "1.2.1"
futures = "0.1"
futures-cpupool = "0.1"
fdlimit = "0.1"
ws2_32-sys = "0.2"
ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" }
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
ethcore = { path = "ethcore" }
Expand Down Expand Up @@ -85,7 +84,7 @@ tempdir = "0.3"
fake-fetch = { path = "util/fake-fetch" }

[target.'cfg(windows)'.dependencies]
winapi = "0.2"
winapi = { version = "0.3.4", features = ["winsock2", "winuser", "shellapi"] }

[target.'cfg(not(windows))'.dependencies]
daemonize = { git = "https://github.com/paritytech/daemonize" }
Expand Down
7 changes: 3 additions & 4 deletions parity/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ extern crate parity_dapps;
#[macro_use]
extern crate pretty_assertions;

#[cfg(windows)] extern crate ws2_32;
#[cfg(windows)] extern crate winapi;

#[cfg(test)]
Expand Down Expand Up @@ -238,7 +237,7 @@ fn global_cleanup() {
// The loop is required because of internal refernce counter for winsock dll. We don't know how many crates we use do
// initialize it. There's at least 2 now.
for _ in 0.. 10 {
unsafe { ::ws2_32::WSACleanup(); }
unsafe { ::winapi::um::winsock2::WSACleanup(); }
}
}

Expand All @@ -250,8 +249,8 @@ fn global_init() {
// When restarting in the same process this reinits windows sockets.
unsafe {
const WS_VERSION: u16 = 0x202;
let mut wsdata: ::winapi::winsock2::WSADATA = ::std::mem::zeroed();
::ws2_32::WSAStartup(WS_VERSION, &mut wsdata);
let mut wsdata: ::winapi::um::winsock2::WSADATA = ::std::mem::zeroed();
::winapi::um::winsock2::WSAStartup(WS_VERSION, &mut wsdata);
}
}

Expand Down
33 changes: 9 additions & 24 deletions parity/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,19 @@

//! Cross-platform open url in default browser

#[cfg(windows)]
mod shell {
extern crate winapi;

use self::winapi::*;
extern "system" {
pub fn ShellExecuteA(
hwnd: HWND, lpOperation: LPCSTR, lpFile: LPCSTR, lpParameters: LPCSTR, lpDirectory: LPCSTR,
nShowCmd: c_int
) -> HINSTANCE;
}

pub use self::winapi::SW_SHOWNORMAL as Normal;
}

#[cfg(windows)]
pub fn open(url: &str) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR:
Ideally, this function should return an error if the winapi or c_str's fail!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed!

use std::ffi::CString;
use std::ptr;

unsafe {
shell::ShellExecuteA(ptr::null_mut(),
CString::new("open").unwrap().as_ptr(),
CString::new(url.to_owned().replace("\n", "%0A")).unwrap().as_ptr(),
ptr::null(),
ptr::null(),
shell::Normal);
}
use winapi::um::shellapi::ShellExecuteA;
use winapi::um::winuser::SW_SHOWNORMAL as Normal;

ShellExecuteA(ptr::null_mut(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but I will repeat myself again because my comment was removed in the latest change!

But, actually ShellExecuteA can fail. Why doesn't we care about that?

https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cause we're lazy :p created an issue for that :)

CString::new("open").unwrap().as_ptr(),
CString::new(url.to_owned().replace("\n", "%0A")).unwrap().as_ptr(),
ptr::null(),
ptr::null(),
Normal);
}

#[cfg(any(target_os="macos", target_os="freebsd"))]
Expand Down